Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/jndi/ldap/VersionHelper12.java
38924 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jndi.ldap;2627import java.net.URLClassLoader;28import java.net.MalformedURLException;29import java.security.AccessControlContext;30import java.security.AccessController;31import java.security.PrivilegedAction;32import sun.misc.SharedSecrets;3334final class VersionHelper12 extends VersionHelper {3536// System property to control whether classes may be loaded from an37// arbitrary URL code base.38private static final String TRUST_URL_CODEBASE_PROPERTY =39"com.sun.jndi.ldap.object.trustURLCodebase";4041// System property to control whether classes are allowed to be loaded from42// 'javaSerializedData' attribute43private static final String TRUST_SERIAL_DATA_PROPERTY =44"com.sun.jndi.ldap.object.trustSerialData";4546/**47* Determines whether objects may be deserialized from the content of48* 'javaSerializedData' attribute.49*/50private static final boolean trustSerialData;5152// Determine whether classes may be loaded from an arbitrary URL code base.53private static final boolean trustURLCodebase;5455static {56String trust = getPrivilegedProperty(TRUST_URL_CODEBASE_PROPERTY, "false");57trustURLCodebase = "true".equalsIgnoreCase(trust);58String trustSDString = getPrivilegedProperty(TRUST_SERIAL_DATA_PROPERTY, "true");59trustSerialData = "true".equalsIgnoreCase(trustSDString);60}6162private static String getPrivilegedProperty(String propertyName, String defaultVal) {63PrivilegedAction<String> action = () -> System.getProperty(propertyName, defaultVal);64if (System.getSecurityManager() == null) {65return action.run();66} else {67return AccessController.doPrivileged(action);68}69}7071VersionHelper12() {} // Disallow external from creating one of these.7273/**74* Returns true if deserialization of objects from 'javaSerializedData'75* LDAP attribute is allowed.76*77* @return true if deserialization is allowed; false - otherwise78*/79public static boolean isSerialDataAllowed() {80return trustSerialData;81}8283ClassLoader getURLClassLoader(String[] url)84throws MalformedURLException {85ClassLoader parent = getContextClassLoader();86/*87* Classes may only be loaded from an arbitrary URL code base when88* the system property com.sun.jndi.ldap.object.trustURLCodebase89* has been set to "true".90*/91if (url != null && trustURLCodebase) {92return URLClassLoader.newInstance(getUrlArray(url), parent);93} else {94return parent;95}96}9798Class<?> loadClass(String className) throws ClassNotFoundException {99ClassLoader cl = getContextClassLoader();100return Class.forName(className, true, cl);101}102103private ClassLoader getContextClassLoader() {104return AccessController.doPrivileged(105new PrivilegedAction<ClassLoader>() {106public ClassLoader run() {107return Thread.currentThread().getContextClassLoader();108}109}110);111}112113Thread createThread(final Runnable r) {114final AccessControlContext acc = AccessController.getContext();115// 4290486: doPrivileged is needed to create a thread in116// an environment that restricts "modifyThreadGroup".117return AccessController.doPrivileged(118new PrivilegedAction<Thread>() {119public Thread run() {120return SharedSecrets.getJavaLangAccess()121.newThreadWithAcc(r, acc);122}123}124);125}126}127128129