You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2010/07/13 22:52:02 UTC

svn commit: r963858 - in /incubator/clerezza/trunk/org.apache.clerezza.parent: org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/ org.apache.clerezza.utils/ org.apache.clerezza.utils/src/main/java/org/apache/cler...

Author: reto
Date: Tue Jul 13 20:52:01 2010
New Revision: 963858

URL: http://svn.apache.org/viewvc?rev=963858&view=rev
Log:
CLEREZZA-259: introduced PermissionParser utility class

Added:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/src/main/java/org/apache/clerezza/utils/security/
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/src/main/java/org/apache/clerezza/utils/security/PermissionParser.java
Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/UserAwarePolicy.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/pom.xml

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/UserAwarePolicy.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/UserAwarePolicy.java?rev=963858&r1=963857&r2=963858&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/UserAwarePolicy.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.platform.security/src/main/java/org/apache/clerezza/platform/security/UserAwarePolicy.java Tue Jul 13 20:52:01 2010
@@ -53,6 +53,7 @@ import org.apache.clerezza.rdf.ontologie
 import org.apache.clerezza.rdf.ontologies.PLATFORM;
 import org.apache.clerezza.rdf.ontologies.RDF;
 import org.apache.clerezza.rdf.ontologies.SIOC;
+import org.apache.clerezza.utils.security.PermissionParser;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
@@ -146,46 +147,20 @@ public class UserAwarePolicy extends Pol
 				for (String permissionStr : permissions) {
 					logger.debug("Add permission {}", permissionStr);
 					Permission perm = permissionMap.get(permissionStr);
-
 					// make new permission, if the required
 					// <code>Permission</code> object is not in the map.
 					if (perm == null) {
-						PermissionInfo permissionInfo;
 						try {
-							permissionInfo = new PermissionInfo(
-									permissionStr);
+							perm = PermissionParser.getPermission(permissionStr,
+									getClass().getClassLoader());
 						} catch (IllegalArgumentException e) {
 							logger.error("parsing "+permissionStr,e);
 							continue;
-						}
-
-						try {
-							Class clazz = Class.forName(permissionInfo
-									.getType());
-							Constructor<?> constructor = clazz.getConstructor(
-									String.class, String.class);
-							perm = (Permission) constructor.newInstance(
-									permissionInfo.getName(), permissionInfo
-											.getActions());
-							permissionMap.put(permissionStr, perm);
-						} catch (InstantiationException ie) {
-							logger.warn("{}", ie);
-							continue;
-						} catch (ClassNotFoundException cnfe) {
-							logger.warn("{}", cnfe);
-							continue;
-						} catch (NoSuchMethodException nsme) {
-							logger.warn("{}", nsme);
-							continue;
-						} catch (InvocationTargetException ite) {
-							logger.warn("{}", ite);
-							continue;
-						} catch (IllegalAccessException iae) {
-							logger.warn("{}", iae);
+						} catch (RuntimeException e) {
+							logger.error("instantiating "+permissionStr,e);
 							continue;
 						}
 					}
-
 					result.add(perm);
 				}
 				return null;

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/pom.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/pom.xml?rev=963858&r1=963857&r2=963858&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/pom.xml (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/pom.xml Tue Jul 13 20:52:01 2010
@@ -26,6 +26,10 @@
 			<artifactId>junit</artifactId>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.core</artifactId>
+		</dependency>
 	</dependencies>
 	<build>
 		<plugins>

Added: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/src/main/java/org/apache/clerezza/utils/security/PermissionParser.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/src/main/java/org/apache/clerezza/utils/security/PermissionParser.java?rev=963858&view=auto
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/src/main/java/org/apache/clerezza/utils/security/PermissionParser.java (added)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.utils/src/main/java/org/apache/clerezza/utils/security/PermissionParser.java Tue Jul 13 20:52:01 2010
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.utils.security;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.security.Permission;
+
+
+import org.osgi.service.permissionadmin.PermissionInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author reto
+ */
+public class PermissionParser {
+
+	final static Logger logger = LoggerFactory.getLogger(PermissionParser.class);
+
+	public static Permission getPermission(String permissionDescription, ClassLoader classLoader) {
+		PermissionInfo permissionInfo = new PermissionInfo(
+					permissionDescription);
+
+		try {
+			Class clazz = classLoader.loadClass(permissionInfo.getType());
+			Constructor<?> constructor = clazz.getConstructor(
+					String.class, String.class);
+			return (Permission) constructor.newInstance(
+					permissionInfo.getName(), permissionInfo.getActions());
+		} catch (InstantiationException ie) {
+			logger.warn("{}", ie);
+			throw new RuntimeException(ie);
+		} catch (ClassNotFoundException cnfe) {
+			logger.warn("{}", cnfe);
+			throw new RuntimeException(cnfe);
+		} catch (NoSuchMethodException nsme) {
+			logger.warn("{}", nsme);
+			throw new RuntimeException(nsme);
+		} catch (InvocationTargetException ite) {
+			logger.warn("{}", ite);
+			throw new RuntimeException(ite);
+		} catch (IllegalAccessException iae) {
+			logger.warn("{}", iae);
+			throw new RuntimeException(iae);
+		}
+	}
+}