author | coleenp |
Wed, 30 Aug 2017 19:18:22 -0400 | |
changeset 47098 | e704f55561c3 |
parent 45434 | 4582657c7260 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, 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 java.security; |
|
27 |
||
31804
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
28 |
import java.util.Map; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
29 |
import java.util.Objects; |
31183
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
30 |
import java.util.concurrent.ConcurrentHashMap; |
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
31 |
import java.util.function.Function; |
2 | 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 |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
43712
diff
changeset
|
42 |
* @since 1.2 |
2 | 43 |
*/ |
44 |
public class SecureClassLoader extends ClassLoader { |
|
45 |
/* |
|
46 |
* If initialization succeed this is set to true and security checks will |
|
47 |
* succeed. Otherwise the object is not initialized and the object is |
|
48 |
* useless. |
|
49 |
*/ |
|
2448
1e8128f3ff61
4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents:
2
diff
changeset
|
50 |
private final boolean initialized; |
2 | 51 |
|
31141
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
52 |
/* |
31804
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
53 |
* Map that maps the CodeSource to a ProtectionDomain. The key is a |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
54 |
* CodeSourceKey class that uses a String instead of a URL to avoid |
31141
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
55 |
* potential expensive name service lookups. This does mean that URLs that |
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
56 |
* are equivalent after nameservice lookup will be placed in separate |
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
57 |
* ProtectionDomains; however during policy enforcement these URLs will be |
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
58 |
* canonicalized and resolved resulting in a consistent set of granted |
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
59 |
* permissions. |
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
60 |
*/ |
31804
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
61 |
private final Map<CodeSourceKey, ProtectionDomain> pdcache |
31183
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
62 |
= new ConcurrentHashMap<>(11); |
2 | 63 |
|
2448
1e8128f3ff61
4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents:
2
diff
changeset
|
64 |
static { |
1e8128f3ff61
4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents:
2
diff
changeset
|
65 |
ClassLoader.registerAsParallelCapable(); |
1e8128f3ff61
4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents:
2
diff
changeset
|
66 |
} |
1e8128f3ff61
4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents:
2
diff
changeset
|
67 |
|
2 | 68 |
/** |
69 |
* Creates a new SecureClassLoader using the specified parent |
|
70 |
* class loader for delegation. |
|
71 |
* |
|
72 |
* <p>If there is a security manager, this method first |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
73 |
* calls the security manager's {@code checkCreateClassLoader} |
2 | 74 |
* method to ensure creation of a class loader is allowed. |
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
75 |
* |
2 | 76 |
* @param parent the parent ClassLoader |
77 |
* @exception SecurityException if a security manager exists and its |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
78 |
* {@code checkCreateClassLoader} method doesn't allow |
2 | 79 |
* creation of a class loader. |
80 |
* @see SecurityManager#checkCreateClassLoader |
|
81 |
*/ |
|
82 |
protected SecureClassLoader(ClassLoader parent) { |
|
83 |
super(parent); |
|
84 |
// this is to make the stack depth consistent with 1.1 |
|
85 |
SecurityManager security = System.getSecurityManager(); |
|
86 |
if (security != null) { |
|
87 |
security.checkCreateClassLoader(); |
|
88 |
} |
|
89 |
initialized = true; |
|
90 |
} |
|
91 |
||
92 |
/** |
|
93 |
* Creates a new SecureClassLoader using the default parent class |
|
94 |
* loader for delegation. |
|
95 |
* |
|
96 |
* <p>If there is a security manager, this method first |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
97 |
* calls the security manager's {@code checkCreateClassLoader} |
2 | 98 |
* method to ensure creation of a class loader is allowed. |
99 |
* |
|
100 |
* @exception SecurityException if a security manager exists and its |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
101 |
* {@code checkCreateClassLoader} method doesn't allow |
2 | 102 |
* creation of a class loader. |
103 |
* @see SecurityManager#checkCreateClassLoader |
|
104 |
*/ |
|
105 |
protected SecureClassLoader() { |
|
106 |
super(); |
|
107 |
// this is to make the stack depth consistent with 1.1 |
|
108 |
SecurityManager security = System.getSecurityManager(); |
|
109 |
if (security != null) { |
|
110 |
security.checkCreateClassLoader(); |
|
111 |
} |
|
112 |
initialized = true; |
|
113 |
} |
|
114 |
||
115 |
/** |
|
41911 | 116 |
* Creates a new {@code SecureClassLoader} of the specified name and |
117 |
* using the specified parent class loader for delegation. |
|
118 |
* |
|
119 |
* @param name class loader name; or {@code null} if not named |
|
120 |
* @param parent the parent class loader |
|
121 |
* |
|
122 |
* @throws IllegalArgumentException if the given name is empty. |
|
123 |
* |
|
124 |
* @throws SecurityException if a security manager exists and its |
|
125 |
* {@link SecurityManager#checkCreateClassLoader()} method |
|
126 |
* doesn't allow creation of a class loader. |
|
127 |
* |
|
128 |
* @since 9 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
41911
diff
changeset
|
129 |
* @spec JPMS |
41911 | 130 |
*/ |
131 |
protected SecureClassLoader(String name, ClassLoader parent) { |
|
132 |
super(name, parent); |
|
133 |
SecurityManager security = System.getSecurityManager(); |
|
134 |
if (security != null) { |
|
135 |
security.checkCreateClassLoader(); |
|
136 |
} |
|
137 |
initialized = true; |
|
138 |
} |
|
139 |
||
140 |
/** |
|
2 | 141 |
* Converts an array of bytes into an instance of class Class, |
142 |
* with an optional CodeSource. Before the |
|
143 |
* class can be used it must be resolved. |
|
144 |
* <p> |
|
145 |
* If a non-null CodeSource is supplied a ProtectionDomain is |
|
146 |
* constructed and associated with the class being defined. |
|
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
147 |
* |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
148 |
* @param name the expected name of the class, or {@code null} |
2 | 149 |
* if not known, using '.' and not '/' as the separator |
150 |
* and without a trailing ".class" suffix. |
|
151 |
* @param b the bytes that make up the class data. The bytes in |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
152 |
* positions {@code off} through {@code off+len-1} |
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7970
diff
changeset
|
153 |
* should have the format of a valid class file as defined by |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7970
diff
changeset
|
154 |
* <cite>The Java™ Virtual Machine Specification</cite>. |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
155 |
* @param off the start offset in {@code b} of the class data |
2 | 156 |
* @param len the length of the class data |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
157 |
* @param cs the associated CodeSource, or {@code null} if none |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
158 |
* @return the {@code Class} object created from the data, |
2 | 159 |
* and optional CodeSource. |
160 |
* @exception ClassFormatError if the data did not contain a valid class |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
161 |
* @exception IndexOutOfBoundsException if either {@code off} or |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
162 |
* {@code len} is negative, or if |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
163 |
* {@code off+len} is greater than {@code b.length}. |
2 | 164 |
* |
165 |
* @exception SecurityException if an attempt is made to add this class |
|
166 |
* to a package that contains classes that were signed by |
|
167 |
* a different set of certificates than this class, or if |
|
168 |
* the class name begins with "java.". |
|
169 |
*/ |
|
170 |
protected final Class<?> defineClass(String name, |
|
171 |
byte[] b, int off, int len, |
|
172 |
CodeSource cs) |
|
173 |
{ |
|
2448
1e8128f3ff61
4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents:
2
diff
changeset
|
174 |
return defineClass(name, b, off, len, getProtectionDomain(cs)); |
2 | 175 |
} |
176 |
||
177 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
178 |
* Converts a {@link java.nio.ByteBuffer ByteBuffer} |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
179 |
* into an instance of class {@code Class}, with an optional CodeSource. |
2 | 180 |
* Before the class can be used it must be resolved. |
181 |
* <p> |
|
182 |
* If a non-null CodeSource is supplied a ProtectionDomain is |
|
183 |
* constructed and associated with the class being defined. |
|
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
184 |
* |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
185 |
* @param name the expected name of the class, or {@code null} |
2 | 186 |
* if not known, using '.' and not '/' as the separator |
187 |
* and without a trailing ".class" suffix. |
|
188 |
* @param b the bytes that make up the class data. The bytes from positions |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
189 |
* {@code b.position()} through {@code b.position() + b.limit() -1} |
9266
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7970
diff
changeset
|
190 |
* should have the format of a valid class file as defined by |
121fb370f179
7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents:
7970
diff
changeset
|
191 |
* <cite>The Java™ Virtual Machine Specification</cite>. |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
192 |
* @param cs the associated CodeSource, or {@code null} if none |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
9275
diff
changeset
|
193 |
* @return the {@code Class} object created from the data, |
2 | 194 |
* and optional CodeSource. |
195 |
* @exception ClassFormatError if the data did not contain a valid class |
|
196 |
* @exception SecurityException if an attempt is made to add this class |
|
197 |
* to a package that contains classes that were signed by |
|
198 |
* a different set of certificates than this class, or if |
|
199 |
* the class name begins with "java.". |
|
200 |
* |
|
201 |
* @since 1.5 |
|
202 |
*/ |
|
203 |
protected final Class<?> defineClass(String name, java.nio.ByteBuffer b, |
|
204 |
CodeSource cs) |
|
205 |
{ |
|
2448
1e8128f3ff61
4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents:
2
diff
changeset
|
206 |
return defineClass(name, b, getProtectionDomain(cs)); |
2 | 207 |
} |
208 |
||
209 |
/** |
|
210 |
* Returns the permissions for the given CodeSource object. |
|
211 |
* <p> |
|
212 |
* This method is invoked by the defineClass method which takes |
|
213 |
* a CodeSource as an argument when it is constructing the |
|
214 |
* ProtectionDomain for the class being defined. |
|
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
215 |
* |
2 | 216 |
* @param codesource the codesource. |
217 |
* |
|
218 |
* @return the permissions granted to the codesource. |
|
219 |
* |
|
220 |
*/ |
|
221 |
protected PermissionCollection getPermissions(CodeSource codesource) |
|
222 |
{ |
|
223 |
check(); |
|
224 |
return new Permissions(); // ProtectionDomain defers the binding |
|
225 |
} |
|
226 |
||
227 |
/* |
|
37882
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
228 |
* holder class for the static field "debug" to delay its initialization |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
229 |
*/ |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
230 |
private static class DebugHolder { |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
231 |
private static final Debug debug = Debug.getInstance("scl"); |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
232 |
} |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
233 |
|
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
234 |
/* |
2 | 235 |
* Returned cached ProtectionDomain for the specified CodeSource. |
236 |
*/ |
|
237 |
private ProtectionDomain getProtectionDomain(CodeSource cs) { |
|
31141
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
238 |
if (cs == null) { |
2 | 239 |
return null; |
31141
ef5ddf021137
6826789: SecureClassLoader should not use CodeSource URLs as HashMap keys
mullan
parents:
29492
diff
changeset
|
240 |
} |
2 | 241 |
|
31804
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
242 |
// Use a CodeSourceKey object key. It should behave in the |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
243 |
// same manner as the CodeSource when compared for equality except |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
244 |
// that no nameservice lookup is done on the hostname (String comparison |
31183
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
245 |
// only), and the fragment is not considered. |
31804
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
246 |
CodeSourceKey key = new CodeSourceKey(cs); |
31183
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
247 |
return pdcache.computeIfAbsent(key, new Function<>() { |
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
248 |
@Override |
31804
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
249 |
public ProtectionDomain apply(CodeSourceKey key /* not used */) { |
31183
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
250 |
PermissionCollection perms |
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
251 |
= SecureClassLoader.this.getPermissions(cs); |
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
252 |
ProtectionDomain pd = new ProtectionDomain( |
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
253 |
cs, perms, SecureClassLoader.this, null); |
37882
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
254 |
if (DebugHolder.debug != null) { |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
255 |
DebugHolder.debug.println(" getPermissions " + pd); |
e7f3cf12e739
6328855: String: Matches hangs at short and easy Strings containing \r \n
sherman
parents:
31804
diff
changeset
|
256 |
DebugHolder.debug.println(""); |
2 | 257 |
} |
31183
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
258 |
return pd; |
2 | 259 |
} |
31183
eb0ffbecb4ba
8064890: SecureClassLoader should use a ConcurrentHashMap
weijun
parents:
31141
diff
changeset
|
260 |
}); |
2 | 261 |
} |
262 |
||
263 |
/* |
|
264 |
* Check to make sure the class loader has been initialized. |
|
265 |
*/ |
|
266 |
private void check() { |
|
267 |
if (!initialized) { |
|
268 |
throw new SecurityException("ClassLoader object not initialized"); |
|
269 |
} |
|
270 |
} |
|
271 |
||
31804
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
272 |
private static class CodeSourceKey { |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
273 |
private final CodeSource cs; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
274 |
|
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
275 |
CodeSourceKey(CodeSource cs) { |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
276 |
this.cs = cs; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
277 |
} |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
278 |
|
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
279 |
@Override |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
280 |
public int hashCode() { |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
281 |
String locationNoFrag = cs.getLocationNoFragString(); |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
282 |
return locationNoFrag != null ? locationNoFrag.hashCode() : 0; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
283 |
} |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
284 |
|
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
285 |
@Override |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
286 |
public boolean equals(Object obj) { |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
287 |
if (obj == this) { |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
288 |
return true; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
289 |
} |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
290 |
|
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
291 |
if (!(obj instanceof CodeSourceKey)) { |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
292 |
return false; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
293 |
} |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
294 |
|
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
295 |
CodeSourceKey csk = (CodeSourceKey) obj; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
296 |
|
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
297 |
if (!Objects.equals(cs.getLocationNoFragString(), |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
298 |
csk.cs.getLocationNoFragString())) { |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
299 |
return false; |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
300 |
} |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
301 |
|
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
302 |
return cs.matchCerts(csk.cs, true); |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
303 |
} |
013c14047253
8131486: SecureClassLoader key for ProtectionDomain cache also needs to take into account certificates
mullan
parents:
31183
diff
changeset
|
304 |
} |
2 | 305 |
} |