You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ma...@apache.org on 2010/06/14 14:32:08 UTC
svn commit: r954428 - in /incubator/aries/trunk:
blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/
blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/
jpa/jpa-container/src/main/java/org/apache/aries/jpa/...
Author: mahrwald
Date: Mon Jun 14 12:32:07 2010
New Revision: 954428
URL: http://svn.apache.org/viewvc?rev=954428&view=rev
Log:
ARIES-336: Add do-priv around appropriate Bundle.loadClass
Modified:
incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/GenericType.java
incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/BundleDelegatingClassLoader.java
incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/GenericType.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/GenericType.java?rev=954428&r1=954427&r2=954428&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/GenericType.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/GenericType.java Mon Jun 14 12:32:07 2010
@@ -23,6 +23,9 @@ import java.lang.reflect.ParameterizedTy
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
@@ -64,8 +67,8 @@ public class GenericType extends Reified
this.parameters = parameters;
}
- public static GenericType parse(String type, Object loader) throws ClassNotFoundException, IllegalArgumentException {
- type = type.trim();
+ public static GenericType parse(String rawType, final Object loader) throws ClassNotFoundException, IllegalArgumentException {
+ final String type = rawType.trim();
// Check if this is an array
if (type.endsWith("[]")) {
GenericType t = parse(type.substring(0, type.length() - 2), loader);
@@ -93,7 +96,19 @@ public class GenericType extends Reified
if (loader instanceof ClassLoader) {
return new GenericType(((ClassLoader) loader).loadClass(type));
} else if (loader instanceof Bundle) {
- return new GenericType(((Bundle) loader).loadClass(type));
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<GenericType>() {
+ public GenericType run() throws ClassNotFoundException {
+ return new GenericType(((Bundle) loader).loadClass(type));
+ }
+ });
+ } catch (PrivilegedActionException pae) {
+ Exception e = pae.getException();
+ if (e instanceof ClassNotFoundException)
+ throw (ClassNotFoundException) e;
+ else
+ throw (RuntimeException) e;
+ }
} else if (loader instanceof ExecutionContext) {
return new GenericType(((ExecutionContext) loader).loadClass(type));
} else if (loader instanceof ExtendedBlueprintContainer) {
Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/BundleDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/BundleDelegatingClassLoader.java?rev=954428&r1=954427&r2=954428&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/BundleDelegatingClassLoader.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/BundleDelegatingClassLoader.java Mon Jun 14 12:32:07 2010
@@ -20,6 +20,12 @@ package org.apache.aries.blueprint.utils
import java.io.IOException;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import org.osgi.framework.Bundle;
@@ -43,20 +49,59 @@ public class BundleDelegatingClassLoader
this.classLoader = classLoader;
}
- protected Class findClass(String name) throws ClassNotFoundException {
- return bundle.loadClass(name);
+ protected Class findClass(final String name) throws ClassNotFoundException {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws ClassNotFoundException
+ {
+ return bundle.loadClass(name);
+ }
+
+ });
+ } catch (PrivilegedActionException e) {
+ Exception cause = e.getException();
+
+ if (cause instanceof ClassNotFoundException) throw (ClassNotFoundException)cause;
+ else throw (RuntimeException)cause;
+ }
}
- protected URL findResource(String name) {
- URL resource = bundle.getResource(name);
+ protected URL findResource(final String name) {
+ URL resource = AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run()
+ {
+ return bundle.getResource(name);
+ }
+ });
if (classLoader != null && resource == null) {
resource = classLoader.getResource(name);
}
return resource;
}
- protected Enumeration findResources(String name) throws IOException {
- return bundle.getResources(name);
+ protected Enumeration findResources(final String name) throws IOException {
+ Enumeration<URL> urls;
+ try {
+ urls = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
+ @SuppressWarnings("unchecked")
+ public Enumeration<URL> run() throws IOException
+ {
+ return (Enumeration<URL>)bundle.getResources(name);
+ }
+
+ });
+ } catch (PrivilegedActionException e) {
+ Exception cause = e.getException();
+
+ if (cause instanceof IOException) throw (IOException)cause;
+ else throw (RuntimeException)cause;
+ }
+
+ if (urls == null) {
+ urls = Collections.enumeration(new ArrayList<URL>());
+ }
+
+ return urls;
}
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
Modified: incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java?rev=954428&r1=954427&r2=954428&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java (original)
+++ incubator/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/BundleDelegatingClassLoader.java Mon Jun 14 12:32:07 2010
@@ -20,6 +20,12 @@ package org.apache.aries.jpa.container.u
import java.io.IOException;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import org.osgi.framework.Bundle;
@@ -36,19 +42,57 @@ public class BundleDelegatingClassLoader
}
@Override
- protected Class<?> findClass(String className) throws ClassNotFoundException {
- return bundle.loadClass(className);
+ protected Class<?> findClass(final String name) throws ClassNotFoundException {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws ClassNotFoundException
+ {
+ return bundle.loadClass(name);
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ Exception cause = e.getException();
+
+ if (cause instanceof ClassNotFoundException) throw (ClassNotFoundException)cause;
+ else throw (RuntimeException)cause;
+ }
}
@Override
- protected URL findResource(String resName) {
- return bundle.getResource(resName);
+ protected URL findResource(final String name) {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run()
+ {
+ return bundle.getResource(name);
+ }
+ });
}
@SuppressWarnings("unchecked")
@Override
- protected Enumeration<URL> findResources(String resName) throws IOException {
- return bundle.getResources(resName);
+ protected Enumeration<URL> findResources(final String name) throws IOException {
+ Enumeration<URL> urls;
+ try {
+ urls = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
+ @SuppressWarnings("unchecked")
+ public Enumeration<URL> run() throws IOException
+ {
+ return (Enumeration<URL>)bundle.getResources(name);
+ }
+
+ });
+ } catch (PrivilegedActionException e) {
+ Exception cause = e.getException();
+
+ if (cause instanceof IOException) throw (IOException)cause;
+ else throw (RuntimeException)cause;
+ }
+
+ if (urls == null) {
+ urls = Collections.enumeration(new ArrayList<URL>());
+ }
+
+ return urls;
}
}