When a custom class loader needs to override the getPermissions()
method, the implementation must consult the default system policy by explicitly invoking the superclass's getPermissions()
method before assigning arbitrary permissions to the code source. The getPermissions()
method is actually defined by SecureClassLoader
, which extends ClassLoader
. ClassLoader
is abstract and must not be extended directly.
Noncompliant Code Example
...
Code Block | ||
---|---|---|
| ||
protected PermissionCollection getPermissions(CodeSource cs) { PermissionCollection pc = super.getPermissions(cs); pc.add(new RuntimePermission("exitVM")); // allow exit from the VM anytime return pc; } |
Exceptions
...
Risk Assessment
Failure to consult the default system policy while defining a custom classloader violates the tenets of defensive programming and can result in classes defined with unintended permissions.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="eec0345fee7e5fe0-e94d16ac-4f904d72-b387aef2-a74cfb3f62f748fb48fc4204"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | [Class ClassLoader | http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b1fe3744fed952e9-85da872a-4a344830-ad1ca557-2b8df7d13c71a4b7f68ce177"><ac:plain-text-body><![CDATA[ | [[Oaks 2001 | AA. Bibliography#Oaks 01]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7c23cd3e342dd835-0b7e5d0a-4c4e42a4-9ee394d7-2f56c34a1b951cb0024a9b97"><ac:plain-text-body><![CDATA[ | [[Security 2006 | AA. Bibliography#Security 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
...