jdk/src/share/classes/com/sun/jndi/ldap/VersionHelper12.java
author jjg
Wed, 10 Aug 2011 13:44:58 -0700
changeset 10324 e28265130e4f
parent 5506 202f599c92aa
child 20805 ae41216325dd
permissions -rw-r--r--
7072353: JNDI libraries do not build with javac -Xlint:all -Werror Reviewed-by: xuelei Contributed-by: alexandre.boulgakov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2623
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2623
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2623
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2623
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2623
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.jndi.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
final class VersionHelper12 extends VersionHelper {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
2623
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    36
    // System property to control whether classes may be loaded from an
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    37
    // arbitrary URL code base.
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    38
    private static final String TRUST_URL_CODEBASE_PROPERTY =
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    39
        "com.sun.jndi.ldap.object.trustURLCodebase";
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    40
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    41
    // Determine whether classes may be loaded from an arbitrary URL code base.
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    42
    private static final String trustURLCodebase =
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    43
        AccessController.doPrivileged(
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    44
            new PrivilegedAction<String>() {
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    45
                public String run() {
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    46
                    return System.getProperty(TRUST_URL_CODEBASE_PROPERTY,
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    47
                            "false");
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    48
                }
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    49
            }
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    50
        );
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    51
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    VersionHelper12() {} // Disallow external from creating one of these.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    ClassLoader getURLClassLoader(String[] url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        throws MalformedURLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            ClassLoader parent = getContextClassLoader();
2623
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    57
            /*
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    58
             * Classes may only be loaded from an arbitrary URL code base when
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    59
             * the system property com.sun.jndi.ldap.object.trustURLCodebase
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    60
             * has been set to "true".
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    61
             */
7ff092350529 6737315: LDAP serialized data vulnerability
vinnie
parents: 2
diff changeset
    62
            if (url != null && "true".equalsIgnoreCase(trustURLCodebase)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                return URLClassLoader.newInstance(getUrlArray(url), parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    69
    Class<?> loadClass(String className) throws ClassNotFoundException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        ClassLoader cl = getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return Class.forName(className, true, cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private ClassLoader getContextClassLoader() {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    75
        return AccessController.doPrivileged(
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    76
            new PrivilegedAction<ClassLoader>() {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    77
                public ClassLoader run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    Thread createThread(final Runnable r) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    85
        return AccessController.doPrivileged(
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    86
            new PrivilegedAction<Thread>() {
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    87
                public Thread run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    return new Thread(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}