mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-1716: Merge remove usage of deprecated AccessController class
This commit is contained in:
@@ -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<DirectoryClassLoader>() {
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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<File> temporaryFiles, final ClassLoader parent)
|
||||
throws GuacamoleException {
|
||||
|
||||
try {
|
||||
// Attempt to create classloader which loads classes from the given
|
||||
// .jar file
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<ExtensionClassLoader>() {
|
||||
|
||||
@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<File> temporaryFiles,
|
||||
public ExtensionClassLoader(File extension, List<File> temporaryFiles,
|
||||
ClassLoader parent) throws GuacamoleException {
|
||||
super(getExtensionURLs(extension, temporaryFiles), null);
|
||||
this.parent = parent;
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user