You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-scm@geronimo.apache.org by ga...@apache.org on 2013/11/05 17:43:36 UTC
svn commit: r1539053 -
/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
Author: gawor
Date: Tue Nov 5 16:43:36 2013
New Revision: 1539053
URL: http://svn.apache.org/r1539053
Log:
XBEAN-255: Remove doPrivileged() calls
Modified:
geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
Modified: geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java?rev=1539053&r1=1539052&r2=1539053&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java (original)
+++ geronimo/xbean/trunk/xbean-classloader/src/main/java/org/apache/xbean/classloader/JarFileClassLoader.java Tue Nov 5 16:43:36 2013
@@ -20,12 +20,7 @@ import java.io.IOException;
import java.io.File;
import java.net.URL;
import java.net.URI;
-import java.security.AccessControlContext;
-import java.security.AccessController;
import java.security.CodeSource;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedExceptionAction;
-import java.security.PrivilegedActionException;
import java.security.cert.Certificate;
import java.util.Collection;
import java.util.Enumeration;
@@ -49,7 +44,6 @@ public class JarFileClassLoader extends
private static final URL[] EMPTY_URLS = new URL[0];
private final UrlResourceFinder resourceFinder = new UrlResourceFinder();
- private final AccessControlContext acc;
/**
* Creates a JarFileClassLoader that is a child of the system class loader.
@@ -58,7 +52,6 @@ public class JarFileClassLoader extends
*/
public JarFileClassLoader(String name, URL[] urls) {
super(name, EMPTY_URLS);
- this.acc = AccessController.getContext();
addURLs(urls);
}
@@ -70,13 +63,11 @@ public class JarFileClassLoader extends
*/
public JarFileClassLoader(String name, URL[] urls, ClassLoader parent) {
super(name, EMPTY_URLS, parent);
- this.acc = AccessController.getContext();
addURLs(urls);
}
public JarFileClassLoader(String name, URL[] urls, ClassLoader parent, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
super(name, EMPTY_URLS, parent, inverseClassLoading, hiddenClasses, nonOverridableClasses);
- this.acc = AccessController.getContext();
addURLs(urls);
}
@@ -88,19 +79,16 @@ public class JarFileClassLoader extends
*/
public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents) {
super(name, EMPTY_URLS, parents);
- this.acc = AccessController.getContext();
addURLs(urls);
}
public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, Collection hiddenClasses, Collection nonOverridableClasses) {
super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
- this.acc = AccessController.getContext();
addURLs(urls);
}
public JarFileClassLoader(String name, URL[] urls, ClassLoader[] parents, boolean inverseClassLoading, String[] hiddenClasses, String[] nonOverridableClasses) {
super(name, EMPTY_URLS, parents, inverseClassLoading, hiddenClasses, nonOverridableClasses);
- this.acc = AccessController.getContext();
addURLs(urls);
}
@@ -115,12 +103,7 @@ public class JarFileClassLoader extends
* {@inheritDoc}
*/
public void addURL(final URL url) {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- resourceFinder.addUrl(url);
- return null;
- }
- }, acc);
+ resourceFinder.addUrl(url);
}
/**
@@ -128,12 +111,7 @@ public class JarFileClassLoader extends
* @param urls the URLs to add
*/
protected void addURLs(final URL[] urls) {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- resourceFinder.addUrls(urls);
- return null;
- }
- }, acc);
+ resourceFinder.addUrls(urls);
}
/**
@@ -148,11 +126,7 @@ public class JarFileClassLoader extends
* {@inheritDoc}
*/
public URL findResource(final String resourceName) {
- return (URL) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return resourceFinder.findResource(resourceName);
- }
- }, acc);
+ return resourceFinder.findResource(resourceName);
}
/**
@@ -164,11 +138,7 @@ public class JarFileClassLoader extends
Enumeration parentResources = super.findResources(resourceName);
// get the classes from my urls
- Enumeration myResources = (Enumeration) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return resourceFinder.findResources(resourceName);
- }
- }, acc);
+ Enumeration myResources = resourceFinder.findResources(resourceName);
// join the two together
Enumeration resources = new UnionEnumeration(parentResources, myResources);
@@ -196,11 +166,7 @@ public class JarFileClassLoader extends
}
// get a resource handle to the library
- ResourceHandle resourceHandle = (ResourceHandle) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return resourceFinder.getResource(resourceName);
- }
- }, acc);
+ ResourceHandle resourceHandle = resourceFinder.getResource(resourceName);
if (resourceHandle == null) {
return null;
@@ -220,62 +186,53 @@ public class JarFileClassLoader extends
* {@inheritDoc}
*/
protected Class findClass(final String className) throws ClassNotFoundException {
- try {
- return (Class) AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws ClassNotFoundException {
- // first think check if we are allowed to define the package
- SecurityManager securityManager = System.getSecurityManager();
- if (securityManager != null) {
- String packageName;
- int packageEnd = className.lastIndexOf('.');
- if (packageEnd >= 0) {
- packageName = className.substring(0, packageEnd);
- securityManager.checkPackageDefinition(packageName);
- }
- }
-
-
- // convert the class name to a file name
- String resourceName = className.replace('.', '/') + ".class";
-
- // find the class file resource
- ResourceHandle resourceHandle = resourceFinder.getResource(resourceName);
- if (resourceHandle == null) {
- throw new ClassNotFoundException(className);
- }
-
- byte[] bytes;
- Manifest manifest;
- try {
- // get the bytes from the class file
- bytes = resourceHandle.getBytes();
-
- // get the manifest for defining the packages
- manifest = resourceHandle.getManifest();
- } catch (IOException e) {
- throw new ClassNotFoundException(className, e);
- }
-
- // get the certificates for the code source
- Certificate[] certificates = resourceHandle.getCertificates();
-
- // the code source url is used to define the package and as the security context for the class
- URL codeSourceUrl = resourceHandle.getCodeSourceUrl();
-
- // define the package (required for security)
- definePackage(className, codeSourceUrl, manifest);
-
- // this is the security context of the class
- CodeSource codeSource = new CodeSource(codeSourceUrl, certificates);
-
- // load the class into the vm
- Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource);
- return clazz;
- }
- }, acc);
- } catch (PrivilegedActionException e) {
- throw (ClassNotFoundException) e.getException();
+ // first think check if we are allowed to define the package
+ SecurityManager securityManager = System.getSecurityManager();
+ if (securityManager != null) {
+ String packageName;
+ int packageEnd = className.lastIndexOf('.');
+ if (packageEnd >= 0) {
+ packageName = className.substring(0, packageEnd);
+ securityManager.checkPackageDefinition(packageName);
+ }
}
+
+ // convert the class name to a file name
+ String resourceName = className.replace('.', '/') + ".class";
+
+ // find the class file resource
+ ResourceHandle resourceHandle = resourceFinder.getResource(resourceName);
+ if (resourceHandle == null) {
+ throw new ClassNotFoundException(className);
+ }
+
+ byte[] bytes;
+ Manifest manifest;
+ try {
+ // get the bytes from the class file
+ bytes = resourceHandle.getBytes();
+
+ // get the manifest for defining the packages
+ manifest = resourceHandle.getManifest();
+ } catch (IOException e) {
+ throw new ClassNotFoundException(className, e);
+ }
+
+ // get the certificates for the code source
+ Certificate[] certificates = resourceHandle.getCertificates();
+
+ // the code source url is used to define the package and as the security context for the class
+ URL codeSourceUrl = resourceHandle.getCodeSourceUrl();
+
+ // define the package (required for security)
+ definePackage(className, codeSourceUrl, manifest);
+
+ // this is the security context of the class
+ CodeSource codeSource = new CodeSource(codeSourceUrl, certificates);
+
+ // load the class into the vm
+ Class clazz = defineClass(className, bytes, 0, bytes.length, codeSource);
+ return clazz;
}
private void definePackage(String className, URL jarUrl, Manifest manifest) {