author | jjg |
Wed, 10 Aug 2011 13:44:58 -0700 | |
changeset 10324 | e28265130e4f |
parent 5506 | 202f599c92aa |
child 20805 | ae41216325dd |
permissions | -rw-r--r-- |
2 | 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 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.jndi.ldap; |
|
27 |
||
28 |
import java.net.URL; |
|
29 |
import java.net.URLClassLoader; |
|
30 |
import java.net.MalformedURLException; |
|
31 |
import java.security.AccessController; |
|
32 |
import java.security.PrivilegedAction; |
|
33 |
||
34 |
final class VersionHelper12 extends VersionHelper { |
|
35 |
||
2623 | 36 |
// System property to control whether classes may be loaded from an |
37 |
// arbitrary URL code base. |
|
38 |
private static final String TRUST_URL_CODEBASE_PROPERTY = |
|
39 |
"com.sun.jndi.ldap.object.trustURLCodebase"; |
|
40 |
||
41 |
// Determine whether classes may be loaded from an arbitrary URL code base. |
|
42 |
private static final String trustURLCodebase = |
|
43 |
AccessController.doPrivileged( |
|
44 |
new PrivilegedAction<String>() { |
|
45 |
public String run() { |
|
46 |
return System.getProperty(TRUST_URL_CODEBASE_PROPERTY, |
|
47 |
"false"); |
|
48 |
} |
|
49 |
} |
|
50 |
); |
|
51 |
||
2 | 52 |
VersionHelper12() {} // Disallow external from creating one of these. |
53 |
||
54 |
ClassLoader getURLClassLoader(String[] url) |
|
55 |
throws MalformedURLException { |
|
56 |
ClassLoader parent = getContextClassLoader(); |
|
2623 | 57 |
/* |
58 |
* Classes may only be loaded from an arbitrary URL code base when |
|
59 |
* the system property com.sun.jndi.ldap.object.trustURLCodebase |
|
60 |
* has been set to "true". |
|
61 |
*/ |
|
62 |
if (url != null && "true".equalsIgnoreCase(trustURLCodebase)) { |
|
2 | 63 |
return URLClassLoader.newInstance(getUrlArray(url), parent); |
64 |
} else { |
|
65 |
return parent; |
|
66 |
} |
|
67 |
} |
|
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 | 70 |
ClassLoader cl = getContextClassLoader(); |
71 |
return Class.forName(className, true, cl); |
|
72 |
} |
|
73 |
||
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 | 78 |
return Thread.currentThread().getContextClassLoader(); |
79 |
} |
|
80 |
} |
|
81 |
); |
|
82 |
} |
|
83 |
||
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 | 88 |
return new Thread(r); |
89 |
} |
|
90 |
} |
|
91 |
); |
|
92 |
} |
|
93 |
} |