1 7 8 package java.security; 9 10 import java.util.HashMap ; 11 import java.util.ArrayList ; 12 import java.net.URL ; 13 14 import sun.security.util.Debug; 15 16 25 public class SecureClassLoader extends ClassLoader { 26 31 private boolean initialized = false; 32 33 private HashMap pdcache = new HashMap (11); 35 36 private static final Debug debug = Debug.getInstance("scl"); 37 38 52 protected SecureClassLoader(ClassLoader parent) { 53 super(parent); 54 SecurityManager security = System.getSecurityManager(); 56 if (security != null) { 57 security.checkCreateClassLoader(); 58 } 59 initialized = true; 60 } 61 62 75 protected SecureClassLoader() { 76 super(); 77 SecurityManager security = System.getSecurityManager(); 79 if (security != null) { 80 security.checkCreateClassLoader(); 81 } 82 initialized = true; 83 } 84 85 117 protected final Class <?> defineClass(String name, 118 byte[] b, int off, int len, 119 CodeSource cs) 120 { 121 if (cs == null) 122 return defineClass(name, b, off, len); 123 else 124 return defineClass(name, b, off, len, getProtectionDomain(cs)); 125 } 126 127 154 protected final Class <?> defineClass(String name, java.nio.ByteBuffer b, 155 CodeSource cs) 156 { 157 if (cs == null) 158 return defineClass(name, b, (ProtectionDomain )null); 159 else 160 return defineClass(name, b, getProtectionDomain(cs)); 161 } 162 163 175 protected PermissionCollection getPermissions(CodeSource codesource) 176 { 177 check(); 178 return new Permissions (); } 180 181 184 private ProtectionDomain getProtectionDomain(CodeSource cs) { 185 if (cs == null) 186 return null; 187 188 ProtectionDomain pd = null; 189 synchronized (pdcache) { 190 pd = (ProtectionDomain )pdcache.get(cs); 191 if (pd == null) { 192 PermissionCollection perms = getPermissions(cs); 193 pd = new ProtectionDomain (cs, perms, this, null); 194 if (pd != null) { 195 pdcache.put(cs, pd); 196 if (debug != null) { 197 debug.println(" getPermissions "+ pd); 198 debug.println(""); 199 } 200 } 201 } 202 } 203 return pd; 204 } 205 206 209 private void check() { 210 if (!initialized) { 211 throw new SecurityException ("ClassLoader object not initialized"); 212 } 213 } 214 215 } 216 | Popular Tags |