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 TypeMethodDescriptionvoidSets the default assertion status for this class loader tofalseand discards any package defaults or class assertion status settings associated with the class loader.protected final Class<?> defineClass(byte[] b, int off, int len) Deprecated.protected final Class<?> defineClass(String name, byte[] b, int off, int len) Converts an array of bytes into an instance of classClass.protected final Class<?> defineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain) Converts an array of bytes into an instance of classClass, with a givenProtectionDomain.protected final Class<?> defineClass(String name, ByteBuffer b, ProtectionDomain protectionDomain) protected PackagedefinePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase) Defines a package by name in thisClassLoader.protected Class<?> Finds the class with the specified binary name.protected Class<?> Finds the class with the given binary name in a module defined to this class loader.protected StringfindLibrary(String libname) Returns the absolute path name of a native library.protected final Class<?> findLoadedClass(String name) Returns the class with the given binary name if this loader has been recorded by the Java virtual machine as an initiating loader of a class with that binary name.protected URLfindResource(String name) Finds the resource with the given name.protected URLfindResource(String moduleName, String name) Returns a URL to a resource in a module defined to this class loader.protected Enumeration<URL> findResources(String name) Returns an enumeration ofURLobjects representing all the resources with the given name.protected final Class<?> findSystemClass(String name) Finds a class with the specified binary name, loading it if necessary.protected ObjectgetClassLoadingLock(String className) Returns the lock object for class loading operations.final PackagegetDefinedPackage(String name) Returns aPackageof the given name that has been defined by this class loader.final Package[]Returns all of thePackages that have been defined by this class loader.getName()Returns the name of this class loader ornullif this class loader is not named.protected PackagegetPackage(String name) Deprecated.If multiple class loaders delegate to each other and define classes with the same package name, and one such loader relies on the lookup behavior ofgetPackageto return aPackagefrom a parent loader, then the properties exposed by thePackagemay not be as expected in the rest of the program.protected Package[]Returns all of thePackages that have been defined by this class loader and its ancestors.final ClassLoaderReturns the parent class loader for delegation.static ClassLoaderReturns the platform class loader.getResource(String name) Finds the resource with the given name.getResourceAsStream(String name) Returns an input stream for reading the specified resource.getResources(String name) Finds all the resources with the given name.static ClassLoaderReturns the system class loader.static URLgetSystemResource(String name) Find a resource of the specified name from the search path used to load classes.static InputStreamOpen for reading, a resource of the specified name from the search path used to load classes.static Enumeration<URL> getSystemResources(String name) Finds all resources of the specified name from the search path used to load classes.final ModuleReturns the unnamedModulefor this class loader.final booleanClass<?> Loads the class with the specified binary name.protected Class<?> Loads the class with the specified binary name.protected static booleanRegisters the caller as parallel capable.protected final voidresolveClass(Class<?> c) Links the specified class.Returns a stream whose elements are the URLs of all the resources with the given name.voidsetClassAssertionStatus(String className, boolean enabled) Sets the desired assertion status for the named top-level class in this class loader and any nested classes contained therein.voidsetDefaultAssertionStatus(boolean enabled) Sets the default assertion status for this class loader.voidsetPackageAssertionStatus(String packageName, boolean enabled) Sets the package default assertion status for the named 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()Creates and returns a copy of this object.booleanIndicates whether some other object is "equal to" this one.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.inthashCode()Returns a hash code value for this object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
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.
-
defineClass(String, byte[], int, int)