author | weijun |
Thu, 13 Jun 2013 10:21:06 +0800 | |
changeset 20805 | ae41216325dd |
parent 10324 | e28265130e4f |
child 23010 | 6dadb192ad81 |
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.URLClassLoader; |
|
29 |
import java.net.MalformedURLException; |
|
20805 | 30 |
import java.security.AccessControlContext; |
2 | 31 |
import java.security.AccessController; |
32 |
import java.security.PrivilegedAction; |
|
20805 | 33 |
import sun.misc.SharedSecrets; |
2 | 34 |
|
35 |
final class VersionHelper12 extends VersionHelper { |
|
36 |
||
2623 | 37 |
// System property to control whether classes may be loaded from an |
38 |
// arbitrary URL code base. |
|
39 |
private static final String TRUST_URL_CODEBASE_PROPERTY = |
|
40 |
"com.sun.jndi.ldap.object.trustURLCodebase"; |
|
41 |
||
42 |
// Determine whether classes may be loaded from an arbitrary URL code base. |
|
43 |
private static final String trustURLCodebase = |
|
44 |
AccessController.doPrivileged( |
|
45 |
new PrivilegedAction<String>() { |
|
46 |
public String run() { |
|
47 |
return System.getProperty(TRUST_URL_CODEBASE_PROPERTY, |
|
48 |
"false"); |
|
49 |
} |
|
50 |
} |
|
51 |
); |
|
52 |
||
2 | 53 |
VersionHelper12() {} // Disallow external from creating one of these. |
54 |
||
55 |
ClassLoader getURLClassLoader(String[] url) |
|
56 |
throws MalformedURLException { |
|
57 |
ClassLoader parent = getContextClassLoader(); |
|
2623 | 58 |
/* |
59 |
* Classes may only be loaded from an arbitrary URL code base when |
|
60 |
* the system property com.sun.jndi.ldap.object.trustURLCodebase |
|
61 |
* has been set to "true". |
|
62 |
*/ |
|
63 |
if (url != null && "true".equalsIgnoreCase(trustURLCodebase)) { |
|
2 | 64 |
return URLClassLoader.newInstance(getUrlArray(url), parent); |
65 |
} else { |
|
66 |
return parent; |
|
67 |
} |
|
68 |
} |
|
69 |
||
10324
e28265130e4f
7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
70 |
Class<?> loadClass(String className) throws ClassNotFoundException { |
2 | 71 |
ClassLoader cl = getContextClassLoader(); |
72 |
return Class.forName(className, true, cl); |
|
73 |
} |
|
74 |
||
75 |
private ClassLoader getContextClassLoader() { |
|
10324
e28265130e4f
7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
76 |
return AccessController.doPrivileged( |
e28265130e4f
7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
77 |
new PrivilegedAction<ClassLoader>() { |
e28265130e4f
7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
78 |
public ClassLoader run() { |
2 | 79 |
return Thread.currentThread().getContextClassLoader(); |
80 |
} |
|
81 |
} |
|
82 |
); |
|
83 |
} |
|
84 |
||
85 |
Thread createThread(final Runnable r) { |
|
20805 | 86 |
final AccessControlContext acc = AccessController.getContext(); |
87 |
// 4290486: doPrivileged is needed to create a thread in |
|
88 |
// an environment that restricts "modifyThreadGroup". |
|
10324
e28265130e4f
7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents:
5506
diff
changeset
|
89 |
return AccessController.doPrivileged( |
20805 | 90 |
new PrivilegedAction<Thread>() { |
91 |
public Thread run() { |
|
92 |
return SharedSecrets.getJavaLangAccess() |
|
93 |
.newThreadWithAcc(r, acc); |
|
94 |
} |
|
2 | 95 |
} |
96 |
); |
|
97 |
} |
|
98 |
} |