SecureClassLoaderpublic class SecureClassLoader extends ClassLoader {@code SecureClassLoader} represents a {@code ClassLoader} which associates
the classes it loads with a code source and provide mechanisms to allow the
relevant permissions to be retrieved. |
Fields Summary |
---|
private HashMap | pds |
Constructors Summary |
---|
protected SecureClassLoader()Constructs a new instance of {@code SecureClassLoader}. The default
parent {@code ClassLoader} is used.
If a {@code SecurityManager} is installed, code calling this constructor
needs the {@code SecurityPermission} {@code checkCreateClassLoader} to be
granted, otherwise a {@code SecurityException} will be thrown.
super();
| protected SecureClassLoader(ClassLoader parent)Constructs a new instance of {@code SecureClassLoader} with the specified
parent {@code ClassLoader}.
If a {@code SecurityManager} is installed, code calling this constructor
needs the {@code SecurityPermission} {@code checkCreateClassLoader} to be
granted, otherwise a {@code SecurityException} will be thrown.
super(parent);
|
Methods Summary |
---|
protected final java.lang.Class | defineClass(java.lang.String name, byte[] b, int off, int len, java.security.CodeSource cs)Constructs a new class from an array of bytes containing a class
definition in class file format with an optional {@code CodeSource}.
return cs == null ? defineClass(name, b, off, len) : defineClass(name,
b, off, len, getPD(cs));
| protected final java.lang.Class | defineClass(java.lang.String name, java.nio.ByteBuffer b, java.security.CodeSource cs)Constructs a new class from an array of bytes containing a class
definition in class file format with an optional {@code CodeSource}.
//FIXME 1.5 - remove b.array(), call super.defineClass(,ByteBuffer,)
// directly
byte[] data = b.array();
return cs == null ? defineClass(name, data, 0, data.length)
: defineClass(name, data, 0, data.length, getPD(cs));
| private java.security.ProtectionDomain | getPD(java.security.CodeSource cs)
if (cs == null) {
return null;
}
// need to cache PDs, otherwise every class from a given CodeSource
// will have it's own ProtectionDomain, which does not look right.
ProtectionDomain pd;
synchronized (pds) {
if ((pd = (ProtectionDomain) pds.get(cs)) != null) {
return pd;
}
PermissionCollection perms = getPermissions(cs);
pd = new ProtectionDomain(cs, perms, this, null);
pds.put(cs, pd);
}
return pd;
| protected java.security.PermissionCollection | getPermissions(java.security.CodeSource codesource)Returns the {@code PermissionCollection} for the specified {@code
CodeSource}.
// Do nothing by default, ProtectionDomain will take care about
// permissions in dynamic
return new Permissions();
|
|