diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/DirectoryClassLoader.java b/guacamole/src/main/java/org/apache/guacamole/extension/DirectoryClassLoader.java index 215c3c00c..83ad9be73 100644 --- a/guacamole/src/main/java/org/apache/guacamole/extension/DirectoryClassLoader.java +++ b/guacamole/src/main/java/org/apache/guacamole/extension/DirectoryClassLoader.java @@ -24,9 +24,6 @@ import java.io.FilenameFilter; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collection; import org.apache.guacamole.GuacamoleException; @@ -37,44 +34,6 @@ import org.apache.guacamole.GuacamoleException; */ public class DirectoryClassLoader extends URLClassLoader { - /** - * Returns an instance of DirectoryClassLoader configured to load .jar - * files from the given directory. Calling this function multiple times - * will not affect previously-returned instances of DirectoryClassLoader. - * - * @param dir - * The directory from which .jar files should be read. - * - * @return - * A DirectoryClassLoader instance which loads classes from the .jar - * files in the given directory. - * - * @throws GuacamoleException - * If the given file is not a directory, or the contents of the given - * directory cannot be read. - */ - public static DirectoryClassLoader getInstance(final File dir) - throws GuacamoleException { - - try { - // Attempt to create singleton classloader which loads classes from - // all .jar's in the lib directory defined in guacamole.properties - return AccessController.doPrivileged(new PrivilegedExceptionAction() { - - @Override - public DirectoryClassLoader run() throws GuacamoleException { - return new DirectoryClassLoader(dir); - } - - }); - } - - catch (PrivilegedActionException e) { - throw (GuacamoleException) e.getException(); - } - - } - /** * Returns all .jar files within the given directory as an array of URLs. * @@ -142,7 +101,7 @@ public class DirectoryClassLoader extends URLClassLoader { * directory cannot be read. */ - private DirectoryClassLoader(File dir) throws GuacamoleException { + public DirectoryClassLoader(File dir) throws GuacamoleException { super(getJarURLs(dir), DirectoryClassLoader.class.getClassLoader()); } diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/Extension.java b/guacamole/src/main/java/org/apache/guacamole/extension/Extension.java index f6cf80df2..be67a384b 100644 --- a/guacamole/src/main/java/org/apache/guacamole/extension/Extension.java +++ b/guacamole/src/main/java/org/apache/guacamole/extension/Extension.java @@ -397,7 +397,7 @@ public class Extension { } // Create isolated classloader for this extension - classLoader = ExtensionClassLoader.getInstance(file, temporaryFiles, parent); + classLoader = new ExtensionClassLoader(file, temporaryFiles, parent); } diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionClassLoader.java b/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionClassLoader.java index 03faf53cb..6473aa230 100644 --- a/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionClassLoader.java +++ b/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionClassLoader.java @@ -29,9 +29,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Files; import java.nio.file.Path; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; @@ -74,56 +71,6 @@ public class ExtensionClassLoader extends URLClassLoader { */ private final ClassLoader parent; - /** - * Returns an instance of ExtensionClassLoader configured to load classes - * from the given extension .jar. If a necessary class cannot be found - * within the .jar, the given parent ClassLoader is used. Calling this - * function multiple times will not affect previously-returned instances of - * ExtensionClassLoader. - * - * @param extension - * The extension .jar file from which classes should be loaded. - * - * @param temporaryFiles - * A modifiable List that should be populated with all temporary files - * created for the given extension. These files should be deleted on - * application shutdown in reverse order. - * - * @param parent - * The ClassLoader to use if class resolution through the extension - * .jar fails. - * - * @return - * A ExtensionClassLoader instance which loads classes from the - * given extension .jar file. - * - * @throws GuacamoleException - * If the given file is not actually a file, or the contents of the - * file cannot be read. - */ - public static ExtensionClassLoader getInstance(final File extension, - final List temporaryFiles, final ClassLoader parent) - throws GuacamoleException { - - try { - // Attempt to create classloader which loads classes from the given - // .jar file - return AccessController.doPrivileged(new PrivilegedExceptionAction() { - - @Override - public ExtensionClassLoader run() throws GuacamoleException { - return new ExtensionClassLoader(extension, temporaryFiles, parent); - } - - }); - } - - catch (PrivilegedActionException e) { - throw (GuacamoleException) e.getException(); - } - - } - /** * Returns the URL that refers to the given file. If the given file refers * to a directory, an exception is thrown. @@ -320,7 +267,7 @@ public class ExtensionClassLoader extends URLClassLoader { * If the given file is not actually a file, or the contents of the * file cannot be read. */ - private ExtensionClassLoader(File extension, List temporaryFiles, + public ExtensionClassLoader(File extension, List temporaryFiles, ClassLoader parent) throws GuacamoleException { super(getExtensionURLs(extension, temporaryFiles), null); this.parent = parent; diff --git a/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionModule.java b/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionModule.java index e5fbe2e57..d13b9d0ad 100644 --- a/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionModule.java +++ b/guacamole/src/main/java/org/apache/guacamole/extension/ExtensionModule.java @@ -182,7 +182,7 @@ public class ExtensionModule extends ServletModule { return ExtensionModule.class.getClassLoader(); // Return classloader which loads classes from all .jars within the lib directory - return DirectoryClassLoader.getInstance(libDir); + return new DirectoryClassLoader(libDir); }