1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
38 *
39 * @author Li Gong
40 * @author Roland Schemers
41 */
42 public class SecureClassLoader extends ClassLoader {
43 /*
44 * If initialization succeed this is set to true and security checks will
45 * succeed. Otherwise the object is not initialized and the object is
46 * useless.
47 */
48 private final boolean initialized;
49
50 // HashMap that maps CodeSource to ProtectionDomain
51 // @GuardedBy("pdcache")
52 private final HashMap<CodeSource, ProtectionDomain> pdcache =
53 new HashMap<>(11);
54
55 private static final Debug debug = Debug.getInstance("scl");
56
57 static {
58 ClassLoader.registerAsParallelCapable();
59 }
60
61 /**
62 * Creates a new SecureClassLoader using the specified parent
63 * class loader for delegation.
64 *
65 * <p>If there is a security manager, this method first
66 * calls the security manager's <code>checkCreateClassLoader</code>
67 * method to ensure creation of a class loader is allowed.
68 * <p>
69 * @param parent the parent ClassLoader
70 * @exception SecurityException if a security manager exists and its
71 * <code>checkCreateClassLoader</code> method doesn't allow
72 * creation of a class loader.
73 * @see SecurityManager#checkCreateClassLoader
74 */
75 protected SecureClassLoader(ClassLoader parent) {
76 super(parent);
77 // this is to make the stack depth consistent with 1.1
78 SecurityManager security = System.getSecurityManager();
|
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
38 *
39 * @author Li Gong
40 * @author Roland Schemers
41 */
42 public class SecureClassLoader extends ClassLoader {
43 /*
44 * If initialization succeed this is set to true and security checks will
45 * succeed. Otherwise the object is not initialized and the object is
46 * useless.
47 */
48 private final boolean initialized;
49
50 // HashMap that maps CodeSource to ProtectionDomain
51 // @GuardedBy("pdcache")
52 private final HashMap<CodeSource, ProtectionDomain> pdcache =
53 new HashMap<>(11);
54
55 private static final Debug debug = Debug.getInstance("scl");
56
57 static {
58 ClassLoader.registerAsFullyConcurrent();
59 }
60
61 /**
62 * Creates a new SecureClassLoader using the specified parent
63 * class loader for delegation.
64 *
65 * <p>If there is a security manager, this method first
66 * calls the security manager's <code>checkCreateClassLoader</code>
67 * method to ensure creation of a class loader is allowed.
68 * <p>
69 * @param parent the parent ClassLoader
70 * @exception SecurityException if a security manager exists and its
71 * <code>checkCreateClassLoader</code> method doesn't allow
72 * creation of a class loader.
73 * @see SecurityManager#checkCreateClassLoader
74 */
75 protected SecureClassLoader(ClassLoader parent) {
76 super(parent);
77 // this is to make the stack depth consistent with 1.1
78 SecurityManager security = System.getSecurityManager();
|