SecureClassLoaderpublic class SecureClassLoader extends ClassLoader This class extends ClassLoader with additional support for defining
classes with an associated code source and permissions which are
retrieved by the system policy by default. |
Fields Summary |
---|
private boolean | initialized | private HashMap | pdcache | private static final Debug | debug |
Constructors Summary |
---|
protected SecureClassLoader(ClassLoader parent)Creates a new SecureClassLoader using the specified parent
class loader for delegation.
If there is a security manager, this method first
calls the security manager's checkCreateClassLoader
method to ensure creation of a class loader is allowed.
super(parent);
// this is to make the stack depth consistent with 1.1
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkCreateClassLoader();
}
initialized = true;
| protected SecureClassLoader()Creates a new SecureClassLoader using the default parent class
loader for delegation.
If there is a security manager, this method first
calls the security manager's checkCreateClassLoader
method to ensure creation of a class loader is allowed.
super();
// this is to make the stack depth consistent with 1.1
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkCreateClassLoader();
}
initialized = true;
|
Methods Summary |
---|
private void | check()
if (!initialized) {
throw new SecurityException("ClassLoader object not initialized");
}
| protected final java.lang.Class | defineClass(java.lang.String name, byte[] b, int off, int len, java.security.CodeSource cs)Converts an array of bytes into an instance of class Class,
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.
if (cs == null)
return defineClass(name, b, off, len);
else
return defineClass(name, b, off, len, getProtectionDomain(cs));
| protected final java.lang.Class | defineClass(java.lang.String name, java.nio.ByteBuffer b, java.security.CodeSource cs)Converts a {@link java.nio.ByteBuffer ByteBuffer}
into an instance of class Class, 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.
if (cs == null)
return defineClass(name, b, (ProtectionDomain)null);
else
return defineClass(name, b, getProtectionDomain(cs));
| protected java.security.PermissionCollection | getPermissions(java.security.CodeSource codesource)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.
check();
return new Permissions(); // ProtectionDomain defers the binding
| private java.security.ProtectionDomain | getProtectionDomain(java.security.CodeSource cs)
if (cs == null)
return null;
ProtectionDomain pd = null;
synchronized (pdcache) {
pd = (ProtectionDomain)pdcache.get(cs);
if (pd == null) {
PermissionCollection perms = getPermissions(cs);
pd = new ProtectionDomain(cs, perms, this, null);
if (pd != null) {
pdcache.put(cs, pd);
if (debug != null) {
debug.println(" getPermissions "+ pd);
debug.println("");
}
}
}
}
return pd;
|
|