Class SecureClassLoader
java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
- Direct Known Subclasses:
URLClassLoader
This class extends
ClassLoader with additional support for defining
classes with an associated code source and permissions.- API Note:
- Permissions cannot be used for controlling access to resources as the Security Manager is no longer supported.
- Since:
- 1.2
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a newSecureClassLoaderusing the system class loader as the parent.protectedSecureClassLoader(ClassLoader parent) Creates a newSecureClassLoaderusing the specified parent class loader for delegation.protectedSecureClassLoader(String name, ClassLoader parent) Creates a newSecureClassLoaderof the specified name and using the specified parent class loader for delegation. -
Method Summary
Modifier and TypeMethodDescriptionprotected final Class<?> defineClass(String name, byte[] b, int off, int len, CodeSource cs) Converts an array of bytes into an instance of classClass, with an optional CodeSource.protected final Class<?> defineClass(String name, ByteBuffer b, CodeSource cs) Converts aByteBufferinto an instance of classClass, with an optional CodeSource.protected PermissionCollectiongetPermissions(CodeSource codesource) Returns the permissions for the given CodeSource object.Methods declared in class ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignersModifier and TypeMethodDescriptionvoidClears the default, package and class assertion status of a classloaderprotected final Class<?> defineClass(byte[] classRep, int offset, int length) Deprecated.Use defineClass(String, byte[], int, int)protected final Class<?> defineClass(String className, byte[] classRep, int offset, int length) Constructs a new class from an array of bytes containing a class definition in class file format.protected final Class<?> defineClass(String className, byte[] classRep, int offset, int length, ProtectionDomain protectionDomain) Constructs a new class from an array of bytes containing a class definition in class file format and assigns the new class to the specified protection domain.protected final Class<?> defineClass(String name, ByteBuffer buffer, ProtectionDomain domain) Constructs a new class from an array of bytes containing a class definition in class file format and assigns the new class to the specified protection domain.protected PackagedefinePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) Define a new Package using the specified information.protected Class<?> Overridden by subclasses, by default throws ClassNotFoundException.protected Class<?> Overridden by subclasses that support the loading from modules.protected StringfindLibrary(String libName) Answers the absolute path of the file containing the library associated with the given name, or null.protected final Class<?> findLoadedClass(String className) Attempts to find and return a class which has already been loaded by the virtual machine.protected URLfindResource(String resName) Answers an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.protected URLfindResource(String moduleName, String resName) Answers an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.protected Enumeration<URL> findResources(String resName) Answers an Enumeration of URL which can be used to access the resources described by resName, using the class loader's resource lookup algorithm.protected final Class<?> findSystemClass(String className) Attempts to load a class using the system class loader.protected ObjectgetClassLoadingLock(String className) Answers the lock object for class loading in parallel.final PackagegetDefinedPackage(String name) Answers a package of given name defined by this ClassLoader.final Package[]Answers all the packages defined by this classloader.getName()Get the name given when creating the ClassLoader instance, or null if none was provided.protected PackagegetPackage(String name) Deprecated.Use getDefinedPackage(String)protected Package[]Answers all the packages known to this class loader.final ClassLoaderReturns the specified ClassLoader's parent.static ClassLoaderReturn the Platform classloader.getResource(String resName) Answers an URL which can be used to access the resource described by resName, using the class loader's resource lookup algorithm.getResourceAsStream(String resName) Answers a stream on a resource found by looking up resName using the class loader's resource lookup algorithm.getResources(String resName) Answers an Enumeration of URL which can be used to access the resources described by resName, using the class loader's resource lookup algorithm.static ClassLoaderConvenience operation to obtain a reference to the system class loader.static URLgetSystemResource(String resName) Answers an URL specifying a resource which can be found by looking up resName using the system class loader's resource lookup algorithm.static InputStreamgetSystemResourceAsStream(String resName) Answers a stream on a resource found by looking up resName using the system class loader's resource lookup algorithm.static Enumeration<URL> getSystemResources(String resName) Answers an Enumeration of URL containing all resources which can be found by looking up resName using the system class loader's resource lookup algorithm.final ModuleAnswers the unnamed Module of this class loader.final booleanIndicating if this class loader is registered as parallel capable or notClass<?> Invoked by the Virtual Machine when resolving class references.protected Class<?> Attempts to load the typeclassNamein the running VM, optionally linking the type after a successful load.protected static booleanAttempts to register the ClassLoader as being capable of parallel class loading.protected final voidresolveClass(Class<?> clazz) Forces a class to be linked (initialized).Answers a stream of URL which can be used to access the resources described by name, using the class loader's resource lookup algorithm.voidsetClassAssertionStatus(String cname, boolean enable) Sets the assertion status of a class.voidsetDefaultAssertionStatus(boolean enable) Sets the default assertion status of a classloadervoidsetPackageAssertionStatus(String pname, boolean enable) Sets the assertion status of a package.protected final voidsetSigners(Class<?> c, Object[] signers) Sets the signers of a class.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
SecureClassLoader
Creates a newSecureClassLoaderusing the specified parent class loader for delegation.- API Note:
- If
parentis specified asnull(for the bootstrap class loader) then there is no guarantee that all platform classes are visible. See Run-time Built-in Class Loaders for information on the bootstrap class loader and other built-in class loaders. - Parameters:
parent- the parent ClassLoader, can benullfor the bootstrap class loader
-
SecureClassLoader
protected SecureClassLoader()Creates a newSecureClassLoaderusing the system class loader as the parent. -
SecureClassLoader
Creates a newSecureClassLoaderof the specified name and using the specified parent class loader for delegation.- API Note:
- If
parentis specified asnull(for the bootstrap class loader) then there is no guarantee that all platform classes are visible. See Run-time Built-in Class Loaders for information on the bootstrap class loader and other built-in class loaders. - Parameters:
name- class loader name; ornullif not namedparent- the parent class loader, can benullfor the bootstrap class loader- Throws:
IllegalArgumentException- if the given name is empty.- Since:
- 9
-
-
Method Details
-
defineClass
Converts an array of bytes into an instance of classClass, with an optional CodeSource. Before the class can be used it must be resolved.If a non-null CodeSource is supplied a ProtectionDomain is constructed and associated with the class being defined.
- Parameters:
name- the expected name of the class, ornullif not known, using '.' and not '/' as the separator and without a trailing ".class" suffix.b- the bytes that make up the class data. The bytes in positionsoffthroughoff+len-1should have the format of a valid class file as defined by The Java Virtual Machine Specification.off- the start offset inbof the class datalen- the length of the class datacs- the associated CodeSource, ornullif none- Returns:
- the
Classobject created from the data, and optional CodeSource. - Throws:
ClassFormatError- if the data did not contain a valid classIndexOutOfBoundsException- if eitherofforlenis negative, or ifoff+lenis greater thanb.length.SecurityException- if an attempt is made to add this class to a package that contains classes that were signed by a different set of certificates than this class, or if the class name begins with "java.".
-
defineClass
Converts aByteBufferinto an instance of classClass, with an optional CodeSource. Before the class can be used it must be resolved.If a non-null CodeSource is supplied a ProtectionDomain is constructed and associated with the class being defined.
- Parameters:
name- the expected name of the class, ornullif not known, using '.' and not '/' as the separator and without a trailing ".class" suffix.b- the bytes that make up the class data. The bytes from positionsb.position()throughb.position() + b.limit() -1should have the format of a valid class file as defined by The Java Virtual Machine Specification.cs- the associated CodeSource, ornullif none- Returns:
- the
Classobject created from the data, and optional CodeSource. - Throws:
ClassFormatError- if the data did not contain a valid classSecurityException- if an attempt is made to add this class to a package that contains classes that were signed by a different set of certificates than this class, or if the class name begins with "java.".- Since:
- 1.5
-
getPermissions
Returns the permissions for the given CodeSource object.This method is invoked by the defineClass method which takes a CodeSource as an argument when it is constructing the ProtectionDomain for the class being defined.
- Parameters:
codesource- the codesource.- Returns:
- the permissions for the codesource.
-