diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/java/security/SecureClassLoader.java | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/classpath/java/security/SecureClassLoader.java')
-rw-r--r-- | libjava/classpath/java/security/SecureClassLoader.java | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/libjava/classpath/java/security/SecureClassLoader.java b/libjava/classpath/java/security/SecureClassLoader.java index 9d1fac79..dfc1758 100644 --- a/libjava/classpath/java/security/SecureClassLoader.java +++ b/libjava/classpath/java/security/SecureClassLoader.java @@ -1,5 +1,5 @@ /* SecureClassLoader.java --- A Secure Class Loader - Copyright (C) 1999, 2004 Free Software Foundation, Inc. + Copyright (C) 1999, 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,6 +37,11 @@ exception statement from your version. */ package java.security; +import java.util.WeakHashMap; + +import java.nio.ByteBuffer; +import java.util.HashMap; + /** * A Secure Class Loader for loading classes with additional * support for specifying code source and permissions when @@ -48,21 +53,16 @@ package java.security; */ public class SecureClassLoader extends ClassLoader { - java.util.WeakHashMap protectionDomainCache = new java.util.WeakHashMap(); + private final HashMap<CodeSource,ProtectionDomain> protectionDomainCache + = new HashMap<CodeSource, ProtectionDomain>(); protected SecureClassLoader(ClassLoader parent) { super(parent); - SecurityManager sm = System.getSecurityManager(); - if(sm != null) - sm.checkCreateClassLoader(); } protected SecureClassLoader() { - SecurityManager sm = System.getSecurityManager(); - if(sm != null) - sm.checkCreateClassLoader(); } /** @@ -79,13 +79,38 @@ public class SecureClassLoader extends ClassLoader * * @exception ClassFormatError if the byte array is not in proper classfile format. */ - protected final Class defineClass(String name, byte[] b, int off, int len, + protected final Class<?> defineClass(String name, byte[] b, int off, int len, CodeSource cs) { + return super.defineClass(name, b, off, len, getProtectionDomain(cs)); + } + + /** + * Creates a class using an ByteBuffer and a + * CodeSource. + * + * @param name the name to give the class. null if unknown. + * @param b the data representing the classfile, in classfile format. + * @param cs the CodeSource for the class or null when unknown. + * + * @return the class that was defined and optional CodeSource. + * + * @exception ClassFormatError if the byte array is not in proper classfile format. + * + * @since 1.5 + */ + protected final Class defineClass(String name, ByteBuffer b, CodeSource cs) + { + return super.defineClass(name, b, getProtectionDomain(cs)); + } + + /* Lookup or create a protection domain for the CodeSource, + * if CodeSource is null it will return null. */ + private ProtectionDomain getProtectionDomain(CodeSource cs) + { + ProtectionDomain protectionDomain = null; if (cs != null) { - ProtectionDomain protectionDomain; - synchronized (protectionDomainCache) { protectionDomain = (ProtectionDomain)protectionDomainCache.get(cs); @@ -105,10 +130,8 @@ public class SecureClassLoader extends ClassLoader protectionDomain = domain; } } - return super.defineClass(name, b, off, len, protectionDomain); - } - else - return super.defineClass(name, b, off, len); + } + return protectionDomain; } /** @@ -117,7 +140,7 @@ public class SecureClassLoader extends ClassLoader * java.security.Policy.getPermissions. * * This method is called by defineClass that takes a CodeSource - * arguement to build a proper ProtectionDomain for the class + * argument to build a proper ProtectionDomain for the class * being defined. */ protected PermissionCollection getPermissions(CodeSource cs) |