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 23 * questions. 24 */ 25 26 package java.security; 27 28 import java.net.URL; 29 import java.util.ArrayList; 30 import java.util.Map; 31 import java.util.Objects; 32 import java.util.concurrent.ConcurrentHashMap; 33 import java.util.function.Function; 34 35 import sun.security.util.Debug; 36 37 /** 38 * This class extends ClassLoader with additional support for defining 39 * classes with an associated code source and permissions which are 40 * retrieved by the system policy by default. 41 * 42 * @author Li Gong 43 * @author Roland Schemers 44 */ 45 public class SecureClassLoader extends ClassLoader { 46 /* 47 * If initialization succeed this is set to true and security checks will 48 * succeed. Otherwise the object is not initialized and the object is 49 * useless. 97 * <p>If there is a security manager, this method first 98 * calls the security manager's {@code checkCreateClassLoader} 99 * method to ensure creation of a class loader is allowed. 100 * 101 * @exception SecurityException if a security manager exists and its 102 * {@code checkCreateClassLoader} method doesn't allow 103 * creation of a class loader. 104 * @see SecurityManager#checkCreateClassLoader 105 */ 106 protected SecureClassLoader() { 107 super(); 108 // this is to make the stack depth consistent with 1.1 109 SecurityManager security = System.getSecurityManager(); 110 if (security != null) { 111 security.checkCreateClassLoader(); 112 } 113 initialized = true; 114 } 115 116 /** 117 * Converts an array of bytes into an instance of class Class, 118 * with an optional CodeSource. Before the 119 * class can be used it must be resolved. 120 * <p> 121 * If a non-null CodeSource is supplied a ProtectionDomain is 122 * constructed and associated with the class being defined. 123 * 124 * @param name the expected name of the class, or {@code null} 125 * if not known, using '.' and not '/' as the separator 126 * and without a trailing ".class" suffix. 127 * @param b the bytes that make up the class data. The bytes in 128 * positions {@code off} through {@code off+len-1} 129 * should have the format of a valid class file as defined by 130 * <cite>The Java™ Virtual Machine Specification</cite>. 131 * @param off the start offset in {@code b} of the class data 132 * @param len the length of the class data 133 * @param cs the associated CodeSource, or {@code null} if none 134 * @return the {@code Class} object created from the data, 135 * and optional CodeSource. 136 * @exception ClassFormatError if the data did not contain a valid class | 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 23 * questions. 24 */ 25 26 package java.security; 27 28 import java.util.Map; 29 import java.util.Objects; 30 import java.util.concurrent.ConcurrentHashMap; 31 import java.util.function.Function; 32 33 import sun.security.util.Debug; 34 35 /** 36 * This class extends ClassLoader with additional support for defining 37 * classes with an associated code source and permissions which are 38 * retrieved by the system policy by default. 39 * 40 * @author Li Gong 41 * @author Roland Schemers 42 */ 43 public class SecureClassLoader extends ClassLoader { 44 /* 45 * If initialization succeed this is set to true and security checks will 46 * succeed. Otherwise the object is not initialized and the object is 47 * useless. 95 * <p>If there is a security manager, this method first 96 * calls the security manager's {@code checkCreateClassLoader} 97 * method to ensure creation of a class loader is allowed. 98 * 99 * @exception SecurityException if a security manager exists and its 100 * {@code checkCreateClassLoader} method doesn't allow 101 * creation of a class loader. 102 * @see SecurityManager#checkCreateClassLoader 103 */ 104 protected SecureClassLoader() { 105 super(); 106 // this is to make the stack depth consistent with 1.1 107 SecurityManager security = System.getSecurityManager(); 108 if (security != null) { 109 security.checkCreateClassLoader(); 110 } 111 initialized = true; 112 } 113 114 /** 115 * Creates a new {@code SecureClassLoader} of the specified name and 116 * using the specified parent class loader for delegation. 117 * 118 * @param name class loader name; or {@code null} if not named 119 * @param parent the parent class loader 120 * 121 * @throws SecurityException if a security manager exists and its 122 * {@link SecurityManager#checkCreateClassLoader()} method 123 * doesn't allow creation of a class loader. 124 * 125 * @since 9 126 */ 127 protected SecureClassLoader(String name, ClassLoader parent) { 128 super(name, parent); 129 SecurityManager security = System.getSecurityManager(); 130 if (security != null) { 131 security.checkCreateClassLoader(); 132 } 133 initialized = true; 134 } 135 136 /** 137 * Converts an array of bytes into an instance of class Class, 138 * with an optional CodeSource. Before the 139 * class can be used it must be resolved. 140 * <p> 141 * If a non-null CodeSource is supplied a ProtectionDomain is 142 * constructed and associated with the class being defined. 143 * 144 * @param name the expected name of the class, or {@code null} 145 * if not known, using '.' and not '/' as the separator 146 * and without a trailing ".class" suffix. 147 * @param b the bytes that make up the class data. The bytes in 148 * positions {@code off} through {@code off+len-1} 149 * should have the format of a valid class file as defined by 150 * <cite>The Java™ Virtual Machine Specification</cite>. 151 * @param off the start offset in {@code b} of the class data 152 * @param len the length of the class data 153 * @param cs the associated CodeSource, or {@code null} if none 154 * @return the {@code Class} object created from the data, 155 * and optional CodeSource. 156 * @exception ClassFormatError if the data did not contain a valid class |