author | juh |
Mon, 01 Jul 2013 17:46:12 -0700 | |
changeset 18592 | 80cdfecea074 |
parent 18579 | b678846778ad |
child 21340 | 17142dadfffe |
permissions | -rw-r--r-- |
2 | 1 |
/* |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
2 |
* Copyright (c) 1996, 2013, 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 |
||
28 |
import java.io.*; |
|
29 |
import java.util.*; |
|
30 |
import static java.util.Locale.ENGLISH; |
|
31 |
import java.lang.ref.*; |
|
32 |
import java.lang.reflect.*; |
|
33 |
||
34 |
/** |
|
35 |
* This class represents a "provider" for the |
|
36 |
* Java Security API, where a provider implements some or all parts of |
|
37 |
* Java Security. Services that a provider may implement include: |
|
38 |
* |
|
39 |
* <ul> |
|
40 |
* |
|
41 |
* <li>Algorithms (such as DSA, RSA, MD5 or SHA-1). |
|
42 |
* |
|
43 |
* <li>Key generation, conversion, and management facilities (such as for |
|
44 |
* algorithm-specific keys). |
|
45 |
* |
|
46 |
*</ul> |
|
47 |
* |
|
48 |
* <p>Each provider has a name and a version number, and is configured |
|
49 |
* in each runtime it is installed in. |
|
50 |
* |
|
51 |
* <p>See <a href = |
|
52 |
* "../../../technotes/guides/security/crypto/CryptoSpec.html#Provider">The Provider Class</a> |
|
53 |
* in the "Java Cryptography Architecture API Specification & Reference" |
|
54 |
* for information about how a particular type of provider, the |
|
55 |
* cryptographic service provider, works and is installed. However, |
|
56 |
* please note that a provider can be used to implement any security |
|
57 |
* service in Java that uses a pluggable architecture with a choice |
|
58 |
* of implementations that fit underneath. |
|
59 |
* |
|
60 |
* <p>Some provider implementations may encounter unrecoverable internal |
|
61 |
* errors during their operation, for example a failure to communicate with a |
|
62 |
* security token. A {@link ProviderException} should be used to indicate |
|
63 |
* such errors. |
|
64 |
* |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
65 |
* <p>The service type {@code Provider} is reserved for use by the |
2 | 66 |
* security framework. Services of this type cannot be added, removed, |
67 |
* or modified by applications. |
|
68 |
* The following attributes are automatically placed in each Provider object: |
|
69 |
* <table cellspacing=4> |
|
18592
80cdfecea074
8019539: Fix doclint errors in java.security and its subpackages
juh
parents:
18579
diff
changeset
|
70 |
* <caption><b>Attributes Automatically Placed in a Provider Object</b></caption> |
2 | 71 |
* <tr><th>Name</th><th>Value</th> |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
72 |
* <tr><td>{@code Provider.id name}</td> |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
73 |
* <td>{@code String.valueOf(provider.getName())}</td> |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
74 |
* <tr><td>{@code Provider.id version}</td> |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
75 |
* <td>{@code String.valueOf(provider.getVersion())}</td> |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
76 |
* <tr><td>{@code Provider.id info}</td> |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
77 |
<td>{@code String.valueOf(provider.getInfo())}</td> |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
78 |
* <tr><td>{@code Provider.id className}</td> |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
79 |
* <td>{@code provider.getClass().getName()}</td> |
2 | 80 |
* </table> |
81 |
* |
|
82 |
* @author Benjamin Renaud |
|
83 |
* @author Andreas Sterbenz |
|
84 |
*/ |
|
85 |
public abstract class Provider extends Properties { |
|
86 |
||
87 |
// Declare serialVersionUID to be compatible with JDK1.1 |
|
88 |
static final long serialVersionUID = -4298000515446427739L; |
|
89 |
||
90 |
private static final sun.security.util.Debug debug = |
|
91 |
sun.security.util.Debug.getInstance |
|
92 |
("provider", "Provider"); |
|
93 |
||
94 |
/** |
|
95 |
* The provider name. |
|
96 |
* |
|
97 |
* @serial |
|
98 |
*/ |
|
99 |
private String name; |
|
100 |
||
101 |
/** |
|
102 |
* A description of the provider and its services. |
|
103 |
* |
|
104 |
* @serial |
|
105 |
*/ |
|
106 |
private String info; |
|
107 |
||
108 |
/** |
|
109 |
* The provider version number. |
|
110 |
* |
|
111 |
* @serial |
|
112 |
*/ |
|
113 |
private double version; |
|
114 |
||
115 |
||
116 |
private transient Set<Map.Entry<Object,Object>> entrySet = null; |
|
117 |
private transient int entrySetCallCount = 0; |
|
118 |
||
119 |
private transient boolean initialized; |
|
120 |
||
121 |
/** |
|
122 |
* Constructs a provider with the specified name, version number, |
|
123 |
* and information. |
|
124 |
* |
|
125 |
* @param name the provider name. |
|
126 |
* |
|
127 |
* @param version the provider version number. |
|
128 |
* |
|
129 |
* @param info a description of the provider and its services. |
|
130 |
*/ |
|
131 |
protected Provider(String name, double version, String info) { |
|
132 |
this.name = name; |
|
133 |
this.version = version; |
|
134 |
this.info = info; |
|
135 |
putId(); |
|
136 |
initialized = true; |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* Returns the name of this provider. |
|
141 |
* |
|
142 |
* @return the name of this provider. |
|
143 |
*/ |
|
144 |
public String getName() { |
|
145 |
return name; |
|
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Returns the version number for this provider. |
|
150 |
* |
|
151 |
* @return the version number for this provider. |
|
152 |
*/ |
|
153 |
public double getVersion() { |
|
154 |
return version; |
|
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Returns a human-readable description of the provider and its |
|
159 |
* services. This may return an HTML page, with relevant links. |
|
160 |
* |
|
161 |
* @return a description of the provider and its services. |
|
162 |
*/ |
|
163 |
public String getInfo() { |
|
164 |
return info; |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
* Returns a string with the name and the version number |
|
169 |
* of this provider. |
|
170 |
* |
|
171 |
* @return the string with the name and the version number |
|
172 |
* for this provider. |
|
173 |
*/ |
|
174 |
public String toString() { |
|
175 |
return name + " version " + version; |
|
176 |
} |
|
177 |
||
178 |
/* |
|
179 |
* override the following methods to ensure that provider |
|
180 |
* information can only be changed if the caller has the appropriate |
|
181 |
* permissions. |
|
182 |
*/ |
|
183 |
||
184 |
/** |
|
185 |
* Clears this provider so that it no longer contains the properties |
|
186 |
* used to look up facilities implemented by the provider. |
|
187 |
* |
|
188 |
* <p>First, if there is a security manager, its |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
189 |
* {@code checkSecurityAccess} method is called with the string |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
190 |
* {@code "clearProviderProperties."+name} (where {@code name} |
2 | 191 |
* is the provider name) to see if it's ok to clear this provider. |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
192 |
* If the default implementation of {@code checkSecurityAccess} |
2 | 193 |
* is used (that is, that method is not overriden), then this results in |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
194 |
* a call to the security manager's {@code checkPermission} method |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
195 |
* with a {@code SecurityPermission("clearProviderProperties."+name)} |
2 | 196 |
* permission. |
197 |
* |
|
198 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
199 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
200 |
* java.lang.SecurityManager#checkSecurityAccess} method |
2 | 201 |
* denies access to clear this provider |
202 |
* |
|
203 |
* @since 1.2 |
|
204 |
*/ |
|
205 |
public synchronized void clear() { |
|
206 |
check("clearProviderProperties."+name); |
|
207 |
if (debug != null) { |
|
208 |
debug.println("Remove " + name + " provider properties"); |
|
209 |
} |
|
210 |
implClear(); |
|
211 |
} |
|
212 |
||
213 |
/** |
|
214 |
* Reads a property list (key and element pairs) from the input stream. |
|
215 |
* |
|
216 |
* @param inStream the input stream. |
|
217 |
* @exception IOException if an error occurred when reading from the |
|
218 |
* input stream. |
|
219 |
* @see java.util.Properties#load |
|
220 |
*/ |
|
221 |
public synchronized void load(InputStream inStream) throws IOException { |
|
222 |
check("putProviderProperty."+name); |
|
223 |
if (debug != null) { |
|
224 |
debug.println("Load " + name + " provider properties"); |
|
225 |
} |
|
226 |
Properties tempProperties = new Properties(); |
|
227 |
tempProperties.load(inStream); |
|
228 |
implPutAll(tempProperties); |
|
229 |
} |
|
230 |
||
231 |
/** |
|
232 |
* Copies all of the mappings from the specified Map to this provider. |
|
233 |
* These mappings will replace any properties that this provider had |
|
234 |
* for any of the keys currently in the specified Map. |
|
235 |
* |
|
236 |
* @since 1.2 |
|
237 |
*/ |
|
238 |
public synchronized void putAll(Map<?,?> t) { |
|
239 |
check("putProviderProperty."+name); |
|
240 |
if (debug != null) { |
|
241 |
debug.println("Put all " + name + " provider properties"); |
|
242 |
} |
|
243 |
implPutAll(t); |
|
244 |
} |
|
245 |
||
246 |
/** |
|
247 |
* Returns an unmodifiable Set view of the property entries contained |
|
248 |
* in this Provider. |
|
249 |
* |
|
250 |
* @see java.util.Map.Entry |
|
251 |
* @since 1.2 |
|
252 |
*/ |
|
253 |
public synchronized Set<Map.Entry<Object,Object>> entrySet() { |
|
254 |
checkInitialized(); |
|
255 |
if (entrySet == null) { |
|
256 |
if (entrySetCallCount++ == 0) // Initial call |
|
257 |
entrySet = Collections.unmodifiableMap(this).entrySet(); |
|
258 |
else |
|
259 |
return super.entrySet(); // Recursive call |
|
260 |
} |
|
261 |
||
262 |
// This exception will be thrown if the implementation of |
|
263 |
// Collections.unmodifiableMap.entrySet() is changed such that it |
|
264 |
// no longer calls entrySet() on the backing Map. (Provider's |
|
265 |
// entrySet implementation depends on this "implementation detail", |
|
266 |
// which is unlikely to change. |
|
267 |
if (entrySetCallCount != 2) |
|
268 |
throw new RuntimeException("Internal error."); |
|
269 |
||
270 |
return entrySet; |
|
271 |
} |
|
272 |
||
273 |
/** |
|
274 |
* Returns an unmodifiable Set view of the property keys contained in |
|
275 |
* this provider. |
|
276 |
* |
|
277 |
* @since 1.2 |
|
278 |
*/ |
|
279 |
public Set<Object> keySet() { |
|
280 |
checkInitialized(); |
|
281 |
return Collections.unmodifiableSet(super.keySet()); |
|
282 |
} |
|
283 |
||
284 |
/** |
|
285 |
* Returns an unmodifiable Collection view of the property values |
|
286 |
* contained in this provider. |
|
287 |
* |
|
288 |
* @since 1.2 |
|
289 |
*/ |
|
290 |
public Collection<Object> values() { |
|
291 |
checkInitialized(); |
|
292 |
return Collections.unmodifiableCollection(super.values()); |
|
293 |
} |
|
294 |
||
295 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
296 |
* Sets the {@code key} property to have the specified |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
297 |
* {@code value}. |
2 | 298 |
* |
299 |
* <p>First, if there is a security manager, its |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
300 |
* {@code checkSecurityAccess} method is called with the string |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
301 |
* {@code "putProviderProperty."+name}, where {@code name} is the |
2 | 302 |
* provider name, to see if it's ok to set this provider's property values. |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
303 |
* If the default implementation of {@code checkSecurityAccess} |
2 | 304 |
* is used (that is, that method is not overriden), then this results in |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
305 |
* a call to the security manager's {@code checkPermission} method |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
306 |
* with a {@code SecurityPermission("putProviderProperty."+name)} |
2 | 307 |
* permission. |
308 |
* |
|
309 |
* @param key the property key. |
|
310 |
* |
|
311 |
* @param value the property value. |
|
312 |
* |
|
313 |
* @return the previous value of the specified property |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
314 |
* ({@code key}), or null if it did not have one. |
2 | 315 |
* |
316 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
317 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
318 |
* java.lang.SecurityManager#checkSecurityAccess} method |
2 | 319 |
* denies access to set property values. |
320 |
* |
|
321 |
* @since 1.2 |
|
322 |
*/ |
|
323 |
public synchronized Object put(Object key, Object value) { |
|
324 |
check("putProviderProperty."+name); |
|
325 |
if (debug != null) { |
|
326 |
debug.println("Set " + name + " provider property [" + |
|
327 |
key + "/" + value +"]"); |
|
328 |
} |
|
329 |
return implPut(key, value); |
|
330 |
} |
|
331 |
||
332 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
333 |
* Removes the {@code key} property (and its corresponding |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
334 |
* {@code value}). |
2 | 335 |
* |
336 |
* <p>First, if there is a security manager, its |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
337 |
* {@code checkSecurityAccess} method is called with the string |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
338 |
* {@code "removeProviderProperty."+name}, where {@code name} is |
2 | 339 |
* the provider name, to see if it's ok to remove this provider's |
340 |
* properties. If the default implementation of |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
341 |
* {@code checkSecurityAccess} is used (that is, that method is not |
2 | 342 |
* overriden), then this results in a call to the security manager's |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
343 |
* {@code checkPermission} method with a |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
344 |
* {@code SecurityPermission("removeProviderProperty."+name)} |
2 | 345 |
* permission. |
346 |
* |
|
347 |
* @param key the key for the property to be removed. |
|
348 |
* |
|
349 |
* @return the value to which the key had been mapped, |
|
350 |
* or null if the key did not have a mapping. |
|
351 |
* |
|
352 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
353 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
354 |
* java.lang.SecurityManager#checkSecurityAccess} method |
2 | 355 |
* denies access to remove this provider's properties. |
356 |
* |
|
357 |
* @since 1.2 |
|
358 |
*/ |
|
359 |
public synchronized Object remove(Object key) { |
|
360 |
check("removeProviderProperty."+name); |
|
361 |
if (debug != null) { |
|
362 |
debug.println("Remove " + name + " provider property " + key); |
|
363 |
} |
|
364 |
return implRemove(key); |
|
365 |
} |
|
366 |
||
367 |
// let javadoc show doc from superclass |
|
368 |
public Object get(Object key) { |
|
369 |
checkInitialized(); |
|
370 |
return super.get(key); |
|
371 |
} |
|
372 |
||
373 |
// let javadoc show doc from superclass |
|
374 |
public Enumeration<Object> keys() { |
|
375 |
checkInitialized(); |
|
376 |
return super.keys(); |
|
377 |
} |
|
378 |
||
379 |
// let javadoc show doc from superclass |
|
380 |
public Enumeration<Object> elements() { |
|
381 |
checkInitialized(); |
|
382 |
return super.elements(); |
|
383 |
} |
|
384 |
||
385 |
// let javadoc show doc from superclass |
|
386 |
public String getProperty(String key) { |
|
387 |
checkInitialized(); |
|
388 |
return super.getProperty(key); |
|
389 |
} |
|
390 |
||
391 |
private void checkInitialized() { |
|
392 |
if (!initialized) { |
|
393 |
throw new IllegalStateException(); |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
private void check(String directive) { |
|
398 |
checkInitialized(); |
|
399 |
SecurityManager security = System.getSecurityManager(); |
|
400 |
if (security != null) { |
|
401 |
security.checkSecurityAccess(directive); |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
// legacy properties changed since last call to any services method? |
|
406 |
private transient boolean legacyChanged; |
|
407 |
// serviceMap changed since last call to getServices() |
|
408 |
private transient boolean servicesChanged; |
|
409 |
||
410 |
// Map<String,String> |
|
411 |
private transient Map<String,String> legacyStrings; |
|
412 |
||
413 |
// Map<ServiceKey,Service> |
|
414 |
// used for services added via putService(), initialized on demand |
|
415 |
private transient Map<ServiceKey,Service> serviceMap; |
|
416 |
||
417 |
// Map<ServiceKey,Service> |
|
418 |
// used for services added via legacy methods, init on demand |
|
419 |
private transient Map<ServiceKey,Service> legacyMap; |
|
420 |
||
421 |
// Set<Service> |
|
422 |
// Unmodifiable set of all services. Initialized on demand. |
|
423 |
private transient Set<Service> serviceSet; |
|
424 |
||
425 |
// register the id attributes for this provider |
|
426 |
// this is to ensure that equals() and hashCode() do not incorrectly |
|
427 |
// report to different provider objects as the same |
|
428 |
private void putId() { |
|
429 |
// note: name and info may be null |
|
430 |
super.put("Provider.id name", String.valueOf(name)); |
|
431 |
super.put("Provider.id version", String.valueOf(version)); |
|
432 |
super.put("Provider.id info", String.valueOf(info)); |
|
433 |
super.put("Provider.id className", this.getClass().getName()); |
|
434 |
} |
|
435 |
||
436 |
private void readObject(ObjectInputStream in) |
|
437 |
throws IOException, ClassNotFoundException { |
|
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
438 |
Map<Object,Object> copy = new HashMap<>(); |
2 | 439 |
for (Map.Entry<Object,Object> entry : super.entrySet()) { |
440 |
copy.put(entry.getKey(), entry.getValue()); |
|
441 |
} |
|
442 |
defaults = null; |
|
443 |
in.defaultReadObject(); |
|
444 |
implClear(); |
|
445 |
initialized = true; |
|
446 |
putAll(copy); |
|
447 |
} |
|
448 |
||
449 |
/** |
|
450 |
* Copies all of the mappings from the specified Map to this provider. |
|
451 |
* Internal method to be called AFTER the security check has been |
|
452 |
* performed. |
|
453 |
*/ |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
454 |
private void implPutAll(Map<?,?> t) { |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
455 |
for (Map.Entry<?,?> e : t.entrySet()) { |
2 | 456 |
implPut(e.getKey(), e.getValue()); |
457 |
} |
|
458 |
} |
|
459 |
||
460 |
private Object implRemove(Object key) { |
|
461 |
if (key instanceof String) { |
|
462 |
String keyString = (String)key; |
|
463 |
if (keyString.startsWith("Provider.")) { |
|
464 |
return null; |
|
465 |
} |
|
466 |
legacyChanged = true; |
|
467 |
if (legacyStrings == null) { |
|
468 |
legacyStrings = new LinkedHashMap<String,String>(); |
|
469 |
} |
|
470 |
legacyStrings.remove(keyString); |
|
471 |
} |
|
472 |
return super.remove(key); |
|
473 |
} |
|
474 |
||
475 |
private Object implPut(Object key, Object value) { |
|
476 |
if ((key instanceof String) && (value instanceof String)) { |
|
477 |
String keyString = (String)key; |
|
478 |
if (keyString.startsWith("Provider.")) { |
|
479 |
return null; |
|
480 |
} |
|
481 |
legacyChanged = true; |
|
482 |
if (legacyStrings == null) { |
|
483 |
legacyStrings = new LinkedHashMap<String,String>(); |
|
484 |
} |
|
485 |
legacyStrings.put(keyString, (String)value); |
|
486 |
} |
|
487 |
return super.put(key, value); |
|
488 |
} |
|
489 |
||
490 |
private void implClear() { |
|
491 |
if (legacyStrings != null) { |
|
492 |
legacyStrings.clear(); |
|
493 |
} |
|
494 |
if (legacyMap != null) { |
|
495 |
legacyMap.clear(); |
|
496 |
} |
|
497 |
if (serviceMap != null) { |
|
498 |
serviceMap.clear(); |
|
499 |
} |
|
500 |
legacyChanged = false; |
|
501 |
servicesChanged = false; |
|
502 |
serviceSet = null; |
|
503 |
super.clear(); |
|
504 |
putId(); |
|
505 |
} |
|
506 |
||
507 |
// used as key in the serviceMap and legacyMap HashMaps |
|
508 |
private static class ServiceKey { |
|
509 |
private final String type; |
|
510 |
private final String algorithm; |
|
511 |
private final String originalAlgorithm; |
|
512 |
private ServiceKey(String type, String algorithm, boolean intern) { |
|
513 |
this.type = type; |
|
514 |
this.originalAlgorithm = algorithm; |
|
515 |
algorithm = algorithm.toUpperCase(ENGLISH); |
|
516 |
this.algorithm = intern ? algorithm.intern() : algorithm; |
|
517 |
} |
|
518 |
public int hashCode() { |
|
519 |
return type.hashCode() + algorithm.hashCode(); |
|
520 |
} |
|
521 |
public boolean equals(Object obj) { |
|
522 |
if (this == obj) { |
|
523 |
return true; |
|
524 |
} |
|
525 |
if (obj instanceof ServiceKey == false) { |
|
526 |
return false; |
|
527 |
} |
|
528 |
ServiceKey other = (ServiceKey)obj; |
|
529 |
return this.type.equals(other.type) |
|
530 |
&& this.algorithm.equals(other.algorithm); |
|
531 |
} |
|
532 |
boolean matches(String type, String algorithm) { |
|
533 |
return (this.type == type) && (this.originalAlgorithm == algorithm); |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
/** |
|
538 |
* Ensure all the legacy String properties are fully parsed into |
|
539 |
* service objects. |
|
540 |
*/ |
|
541 |
private void ensureLegacyParsed() { |
|
542 |
if ((legacyChanged == false) || (legacyStrings == null)) { |
|
543 |
return; |
|
544 |
} |
|
545 |
serviceSet = null; |
|
546 |
if (legacyMap == null) { |
|
547 |
legacyMap = new LinkedHashMap<ServiceKey,Service>(); |
|
548 |
} else { |
|
549 |
legacyMap.clear(); |
|
550 |
} |
|
551 |
for (Map.Entry<String,String> entry : legacyStrings.entrySet()) { |
|
552 |
parseLegacyPut(entry.getKey(), entry.getValue()); |
|
553 |
} |
|
554 |
removeInvalidServices(legacyMap); |
|
555 |
legacyChanged = false; |
|
556 |
} |
|
557 |
||
558 |
/** |
|
559 |
* Remove all invalid services from the Map. Invalid services can only |
|
560 |
* occur if the legacy properties are inconsistent or incomplete. |
|
561 |
*/ |
|
562 |
private void removeInvalidServices(Map<ServiceKey,Service> map) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
563 |
for (Iterator<Map.Entry<ServiceKey, Service>> t = |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
564 |
map.entrySet().iterator(); t.hasNext(); ) { |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
565 |
Service s = t.next().getValue(); |
2 | 566 |
if (s.isValid() == false) { |
567 |
t.remove(); |
|
568 |
} |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
private String[] getTypeAndAlgorithm(String key) { |
|
573 |
int i = key.indexOf("."); |
|
574 |
if (i < 1) { |
|
575 |
if (debug != null) { |
|
576 |
debug.println("Ignoring invalid entry in provider " |
|
577 |
+ name + ":" + key); |
|
578 |
} |
|
579 |
return null; |
|
580 |
} |
|
581 |
String type = key.substring(0, i); |
|
582 |
String alg = key.substring(i + 1); |
|
583 |
return new String[] {type, alg}; |
|
584 |
} |
|
585 |
||
586 |
private final static String ALIAS_PREFIX = "Alg.Alias."; |
|
587 |
private final static String ALIAS_PREFIX_LOWER = "alg.alias."; |
|
588 |
private final static int ALIAS_LENGTH = ALIAS_PREFIX.length(); |
|
589 |
||
590 |
private void parseLegacyPut(String name, String value) { |
|
591 |
if (name.toLowerCase(ENGLISH).startsWith(ALIAS_PREFIX_LOWER)) { |
|
592 |
// e.g. put("Alg.Alias.MessageDigest.SHA", "SHA-1"); |
|
593 |
// aliasKey ~ MessageDigest.SHA |
|
594 |
String stdAlg = value; |
|
595 |
String aliasKey = name.substring(ALIAS_LENGTH); |
|
596 |
String[] typeAndAlg = getTypeAndAlgorithm(aliasKey); |
|
597 |
if (typeAndAlg == null) { |
|
598 |
return; |
|
599 |
} |
|
600 |
String type = getEngineName(typeAndAlg[0]); |
|
601 |
String aliasAlg = typeAndAlg[1].intern(); |
|
602 |
ServiceKey key = new ServiceKey(type, stdAlg, true); |
|
603 |
Service s = legacyMap.get(key); |
|
604 |
if (s == null) { |
|
605 |
s = new Service(this); |
|
606 |
s.type = type; |
|
607 |
s.algorithm = stdAlg; |
|
608 |
legacyMap.put(key, s); |
|
609 |
} |
|
610 |
legacyMap.put(new ServiceKey(type, aliasAlg, true), s); |
|
611 |
s.addAlias(aliasAlg); |
|
612 |
} else { |
|
613 |
String[] typeAndAlg = getTypeAndAlgorithm(name); |
|
614 |
if (typeAndAlg == null) { |
|
615 |
return; |
|
616 |
} |
|
617 |
int i = typeAndAlg[1].indexOf(' '); |
|
618 |
if (i == -1) { |
|
619 |
// e.g. put("MessageDigest.SHA-1", "sun.security.provider.SHA"); |
|
620 |
String type = getEngineName(typeAndAlg[0]); |
|
621 |
String stdAlg = typeAndAlg[1].intern(); |
|
622 |
String className = value; |
|
623 |
ServiceKey key = new ServiceKey(type, stdAlg, true); |
|
624 |
Service s = legacyMap.get(key); |
|
625 |
if (s == null) { |
|
626 |
s = new Service(this); |
|
627 |
s.type = type; |
|
628 |
s.algorithm = stdAlg; |
|
629 |
legacyMap.put(key, s); |
|
630 |
} |
|
631 |
s.className = className; |
|
632 |
} else { // attribute |
|
633 |
// e.g. put("MessageDigest.SHA-1 ImplementedIn", "Software"); |
|
634 |
String attributeValue = value; |
|
635 |
String type = getEngineName(typeAndAlg[0]); |
|
636 |
String attributeString = typeAndAlg[1]; |
|
637 |
String stdAlg = attributeString.substring(0, i).intern(); |
|
638 |
String attributeName = attributeString.substring(i + 1); |
|
639 |
// kill additional spaces |
|
640 |
while (attributeName.startsWith(" ")) { |
|
641 |
attributeName = attributeName.substring(1); |
|
642 |
} |
|
643 |
attributeName = attributeName.intern(); |
|
644 |
ServiceKey key = new ServiceKey(type, stdAlg, true); |
|
645 |
Service s = legacyMap.get(key); |
|
646 |
if (s == null) { |
|
647 |
s = new Service(this); |
|
648 |
s.type = type; |
|
649 |
s.algorithm = stdAlg; |
|
650 |
legacyMap.put(key, s); |
|
651 |
} |
|
652 |
s.addAttribute(attributeName, attributeValue); |
|
653 |
} |
|
654 |
} |
|
655 |
} |
|
656 |
||
657 |
/** |
|
658 |
* Get the service describing this Provider's implementation of the |
|
659 |
* specified type of this algorithm or alias. If no such |
|
660 |
* implementation exists, this method returns null. If there are two |
|
661 |
* matching services, one added to this provider using |
|
662 |
* {@link #putService putService()} and one added via {@link #put put()}, |
|
663 |
* the service added via {@link #putService putService()} is returned. |
|
664 |
* |
|
665 |
* @param type the type of {@link Service service} requested |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
666 |
* (for example, {@code MessageDigest}) |
2 | 667 |
* @param algorithm the case insensitive algorithm name (or alternate |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
668 |
* alias) of the service requested (for example, {@code SHA-1}) |
2 | 669 |
* |
670 |
* @return the service describing this Provider's matching service |
|
671 |
* or null if no such service exists |
|
672 |
* |
|
673 |
* @throws NullPointerException if type or algorithm is null |
|
674 |
* |
|
675 |
* @since 1.5 |
|
676 |
*/ |
|
677 |
public synchronized Service getService(String type, String algorithm) { |
|
678 |
checkInitialized(); |
|
679 |
// avoid allocating a new key object if possible |
|
680 |
ServiceKey key = previousKey; |
|
681 |
if (key.matches(type, algorithm) == false) { |
|
682 |
key = new ServiceKey(type, algorithm, false); |
|
683 |
previousKey = key; |
|
684 |
} |
|
685 |
if (serviceMap != null) { |
|
686 |
Service service = serviceMap.get(key); |
|
687 |
if (service != null) { |
|
688 |
return service; |
|
689 |
} |
|
690 |
} |
|
691 |
ensureLegacyParsed(); |
|
692 |
return (legacyMap != null) ? legacyMap.get(key) : null; |
|
693 |
} |
|
694 |
||
695 |
// ServiceKey from previous getService() call |
|
696 |
// by re-using it if possible we avoid allocating a new object |
|
697 |
// and the toUpperCase() call. |
|
698 |
// re-use will occur e.g. as the framework traverses the provider |
|
699 |
// list and queries each provider with the same values until it finds |
|
700 |
// a matching service |
|
701 |
private static volatile ServiceKey previousKey = |
|
702 |
new ServiceKey("", "", false); |
|
703 |
||
704 |
/** |
|
705 |
* Get an unmodifiable Set of all services supported by |
|
706 |
* this Provider. |
|
707 |
* |
|
708 |
* @return an unmodifiable Set of all services supported by |
|
709 |
* this Provider |
|
710 |
* |
|
711 |
* @since 1.5 |
|
712 |
*/ |
|
713 |
public synchronized Set<Service> getServices() { |
|
714 |
checkInitialized(); |
|
715 |
if (legacyChanged || servicesChanged) { |
|
716 |
serviceSet = null; |
|
717 |
} |
|
718 |
if (serviceSet == null) { |
|
719 |
ensureLegacyParsed(); |
|
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
720 |
Set<Service> set = new LinkedHashSet<>(); |
2 | 721 |
if (serviceMap != null) { |
722 |
set.addAll(serviceMap.values()); |
|
723 |
} |
|
724 |
if (legacyMap != null) { |
|
725 |
set.addAll(legacyMap.values()); |
|
726 |
} |
|
727 |
serviceSet = Collections.unmodifiableSet(set); |
|
728 |
servicesChanged = false; |
|
729 |
} |
|
730 |
return serviceSet; |
|
731 |
} |
|
732 |
||
733 |
/** |
|
734 |
* Add a service. If a service of the same type with the same algorithm |
|
735 |
* name exists and it was added using {@link #putService putService()}, |
|
736 |
* it is replaced by the new service. |
|
737 |
* This method also places information about this service |
|
738 |
* in the provider's Hashtable values in the format described in the |
|
739 |
* <a href="../../../technotes/guides/security/crypto/CryptoSpec.html"> |
|
740 |
* Java Cryptography Architecture API Specification & Reference </a>. |
|
741 |
* |
|
742 |
* <p>Also, if there is a security manager, its |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
743 |
* {@code checkSecurityAccess} method is called with the string |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
744 |
* {@code "putProviderProperty."+name}, where {@code name} is |
2 | 745 |
* the provider name, to see if it's ok to set this provider's property |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
746 |
* values. If the default implementation of {@code checkSecurityAccess} |
2 | 747 |
* is used (that is, that method is not overriden), then this results in |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
748 |
* a call to the security manager's {@code checkPermission} method with |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
749 |
* a {@code SecurityPermission("putProviderProperty."+name)} |
2 | 750 |
* permission. |
751 |
* |
|
752 |
* @param s the Service to add |
|
753 |
* |
|
754 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
755 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
756 |
* java.lang.SecurityManager#checkSecurityAccess} method denies |
2 | 757 |
* access to set property values. |
758 |
* @throws NullPointerException if s is null |
|
759 |
* |
|
760 |
* @since 1.5 |
|
761 |
*/ |
|
762 |
protected synchronized void putService(Service s) { |
|
763 |
check("putProviderProperty." + name); |
|
764 |
if (debug != null) { |
|
765 |
debug.println(name + ".putService(): " + s); |
|
766 |
} |
|
767 |
if (s == null) { |
|
768 |
throw new NullPointerException(); |
|
769 |
} |
|
770 |
if (s.getProvider() != this) { |
|
771 |
throw new IllegalArgumentException |
|
772 |
("service.getProvider() must match this Provider object"); |
|
773 |
} |
|
774 |
if (serviceMap == null) { |
|
775 |
serviceMap = new LinkedHashMap<ServiceKey,Service>(); |
|
776 |
} |
|
777 |
servicesChanged = true; |
|
778 |
String type = s.getType(); |
|
779 |
String algorithm = s.getAlgorithm(); |
|
780 |
ServiceKey key = new ServiceKey(type, algorithm, true); |
|
781 |
// remove existing service |
|
782 |
implRemoveService(serviceMap.get(key)); |
|
783 |
serviceMap.put(key, s); |
|
784 |
for (String alias : s.getAliases()) { |
|
785 |
serviceMap.put(new ServiceKey(type, alias, true), s); |
|
786 |
} |
|
787 |
putPropertyStrings(s); |
|
788 |
} |
|
789 |
||
790 |
/** |
|
791 |
* Put the string properties for this Service in this Provider's |
|
792 |
* Hashtable. |
|
793 |
*/ |
|
794 |
private void putPropertyStrings(Service s) { |
|
795 |
String type = s.getType(); |
|
796 |
String algorithm = s.getAlgorithm(); |
|
797 |
// use super() to avoid permission check and other processing |
|
798 |
super.put(type + "." + algorithm, s.getClassName()); |
|
799 |
for (String alias : s.getAliases()) { |
|
800 |
super.put(ALIAS_PREFIX + type + "." + alias, algorithm); |
|
801 |
} |
|
802 |
for (Map.Entry<UString,String> entry : s.attributes.entrySet()) { |
|
803 |
String key = type + "." + algorithm + " " + entry.getKey(); |
|
804 |
super.put(key, entry.getValue()); |
|
805 |
} |
|
806 |
} |
|
807 |
||
808 |
/** |
|
809 |
* Remove the string properties for this Service from this Provider's |
|
810 |
* Hashtable. |
|
811 |
*/ |
|
812 |
private void removePropertyStrings(Service s) { |
|
813 |
String type = s.getType(); |
|
814 |
String algorithm = s.getAlgorithm(); |
|
815 |
// use super() to avoid permission check and other processing |
|
816 |
super.remove(type + "." + algorithm); |
|
817 |
for (String alias : s.getAliases()) { |
|
818 |
super.remove(ALIAS_PREFIX + type + "." + alias); |
|
819 |
} |
|
820 |
for (Map.Entry<UString,String> entry : s.attributes.entrySet()) { |
|
821 |
String key = type + "." + algorithm + " " + entry.getKey(); |
|
822 |
super.remove(key); |
|
823 |
} |
|
824 |
} |
|
825 |
||
826 |
/** |
|
827 |
* Remove a service previously added using |
|
828 |
* {@link #putService putService()}. The specified service is removed from |
|
829 |
* this provider. It will no longer be returned by |
|
830 |
* {@link #getService getService()} and its information will be removed |
|
831 |
* from this provider's Hashtable. |
|
832 |
* |
|
833 |
* <p>Also, if there is a security manager, its |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
834 |
* {@code checkSecurityAccess} method is called with the string |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
835 |
* {@code "removeProviderProperty."+name}, where {@code name} is |
2 | 836 |
* the provider name, to see if it's ok to remove this provider's |
837 |
* properties. If the default implementation of |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
838 |
* {@code checkSecurityAccess} is used (that is, that method is not |
2 | 839 |
* overriden), then this results in a call to the security manager's |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
840 |
* {@code checkPermission} method with a |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
841 |
* {@code SecurityPermission("removeProviderProperty."+name)} |
2 | 842 |
* permission. |
843 |
* |
|
844 |
* @param s the Service to be removed |
|
845 |
* |
|
846 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
847 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
848 |
* java.lang.SecurityManager#checkSecurityAccess} method denies |
2 | 849 |
* access to remove this provider's properties. |
850 |
* @throws NullPointerException if s is null |
|
851 |
* |
|
852 |
* @since 1.5 |
|
853 |
*/ |
|
854 |
protected synchronized void removeService(Service s) { |
|
855 |
check("removeProviderProperty." + name); |
|
856 |
if (debug != null) { |
|
857 |
debug.println(name + ".removeService(): " + s); |
|
858 |
} |
|
859 |
if (s == null) { |
|
860 |
throw new NullPointerException(); |
|
861 |
} |
|
862 |
implRemoveService(s); |
|
863 |
} |
|
864 |
||
865 |
private void implRemoveService(Service s) { |
|
866 |
if ((s == null) || (serviceMap == null)) { |
|
867 |
return; |
|
868 |
} |
|
869 |
String type = s.getType(); |
|
870 |
String algorithm = s.getAlgorithm(); |
|
871 |
ServiceKey key = new ServiceKey(type, algorithm, false); |
|
872 |
Service oldService = serviceMap.get(key); |
|
873 |
if (s != oldService) { |
|
874 |
return; |
|
875 |
} |
|
876 |
servicesChanged = true; |
|
877 |
serviceMap.remove(key); |
|
878 |
for (String alias : s.getAliases()) { |
|
879 |
serviceMap.remove(new ServiceKey(type, alias, false)); |
|
880 |
} |
|
881 |
removePropertyStrings(s); |
|
882 |
} |
|
883 |
||
884 |
// Wrapped String that behaves in a case insensitive way for equals/hashCode |
|
885 |
private static class UString { |
|
886 |
final String string; |
|
887 |
final String lowerString; |
|
888 |
||
889 |
UString(String s) { |
|
890 |
this.string = s; |
|
891 |
this.lowerString = s.toLowerCase(ENGLISH); |
|
892 |
} |
|
893 |
||
894 |
public int hashCode() { |
|
895 |
return lowerString.hashCode(); |
|
896 |
} |
|
897 |
||
898 |
public boolean equals(Object obj) { |
|
899 |
if (this == obj) { |
|
900 |
return true; |
|
901 |
} |
|
902 |
if (obj instanceof UString == false) { |
|
903 |
return false; |
|
904 |
} |
|
905 |
UString other = (UString)obj; |
|
906 |
return lowerString.equals(other.lowerString); |
|
907 |
} |
|
908 |
||
909 |
public String toString() { |
|
910 |
return string; |
|
911 |
} |
|
912 |
} |
|
913 |
||
914 |
// describe relevant properties of a type of engine |
|
915 |
private static class EngineDescription { |
|
916 |
final String name; |
|
917 |
final boolean supportsParameter; |
|
918 |
final String constructorParameterClassName; |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
919 |
private volatile Class<?> constructorParameterClass; |
2 | 920 |
|
921 |
EngineDescription(String name, boolean sp, String paramName) { |
|
922 |
this.name = name; |
|
923 |
this.supportsParameter = sp; |
|
924 |
this.constructorParameterClassName = paramName; |
|
925 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
926 |
Class<?> getConstructorParameterClass() throws ClassNotFoundException { |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
927 |
Class<?> clazz = constructorParameterClass; |
2 | 928 |
if (clazz == null) { |
929 |
clazz = Class.forName(constructorParameterClassName); |
|
930 |
constructorParameterClass = clazz; |
|
931 |
} |
|
932 |
return clazz; |
|
933 |
} |
|
934 |
} |
|
935 |
||
936 |
// built in knowledge of the engine types shipped as part of the JDK |
|
937 |
private static final Map<String,EngineDescription> knownEngines; |
|
938 |
||
939 |
private static void addEngine(String name, boolean sp, String paramName) { |
|
940 |
EngineDescription ed = new EngineDescription(name, sp, paramName); |
|
941 |
// also index by canonical name to avoid toLowerCase() for some lookups |
|
942 |
knownEngines.put(name.toLowerCase(ENGLISH), ed); |
|
943 |
knownEngines.put(name, ed); |
|
944 |
} |
|
945 |
||
946 |
static { |
|
947 |
knownEngines = new HashMap<String,EngineDescription>(); |
|
948 |
// JCA |
|
949 |
addEngine("AlgorithmParameterGenerator", false, null); |
|
950 |
addEngine("AlgorithmParameters", false, null); |
|
951 |
addEngine("KeyFactory", false, null); |
|
952 |
addEngine("KeyPairGenerator", false, null); |
|
953 |
addEngine("KeyStore", false, null); |
|
954 |
addEngine("MessageDigest", false, null); |
|
955 |
addEngine("SecureRandom", false, null); |
|
956 |
addEngine("Signature", true, null); |
|
957 |
addEngine("CertificateFactory", false, null); |
|
958 |
addEngine("CertPathBuilder", false, null); |
|
959 |
addEngine("CertPathValidator", false, null); |
|
960 |
addEngine("CertStore", false, |
|
961 |
"java.security.cert.CertStoreParameters"); |
|
962 |
// JCE |
|
963 |
addEngine("Cipher", true, null); |
|
964 |
addEngine("ExemptionMechanism", false, null); |
|
965 |
addEngine("Mac", true, null); |
|
966 |
addEngine("KeyAgreement", true, null); |
|
967 |
addEngine("KeyGenerator", false, null); |
|
968 |
addEngine("SecretKeyFactory", false, null); |
|
969 |
// JSSE |
|
970 |
addEngine("KeyManagerFactory", false, null); |
|
971 |
addEngine("SSLContext", false, null); |
|
972 |
addEngine("TrustManagerFactory", false, null); |
|
973 |
// JGSS |
|
974 |
addEngine("GssApiMechanism", false, null); |
|
975 |
// SASL |
|
976 |
addEngine("SaslClientFactory", false, null); |
|
977 |
addEngine("SaslServerFactory", false, null); |
|
978 |
// POLICY |
|
979 |
addEngine("Policy", false, |
|
980 |
"java.security.Policy$Parameters"); |
|
981 |
// CONFIGURATION |
|
982 |
addEngine("Configuration", false, |
|
983 |
"javax.security.auth.login.Configuration$Parameters"); |
|
984 |
// XML DSig |
|
985 |
addEngine("XMLSignatureFactory", false, null); |
|
986 |
addEngine("KeyInfoFactory", false, null); |
|
987 |
addEngine("TransformService", false, null); |
|
988 |
// Smart Card I/O |
|
989 |
addEngine("TerminalFactory", false, |
|
990 |
"java.lang.Object"); |
|
991 |
} |
|
992 |
||
993 |
// get the "standard" (mixed-case) engine name for arbitary case engine name |
|
994 |
// if there is no known engine by that name, return s |
|
995 |
private static String getEngineName(String s) { |
|
996 |
// try original case first, usually correct |
|
997 |
EngineDescription e = knownEngines.get(s); |
|
998 |
if (e == null) { |
|
999 |
e = knownEngines.get(s.toLowerCase(ENGLISH)); |
|
1000 |
} |
|
1001 |
return (e == null) ? s : e.name; |
|
1002 |
} |
|
1003 |
||
1004 |
/** |
|
1005 |
* The description of a security service. It encapsulates the properties |
|
1006 |
* of a service and contains a factory method to obtain new implementation |
|
1007 |
* instances of this service. |
|
1008 |
* |
|
1009 |
* <p>Each service has a provider that offers the service, a type, |
|
1010 |
* an algorithm name, and the name of the class that implements the |
|
1011 |
* service. Optionally, it also includes a list of alternate algorithm |
|
1012 |
* names for this service (aliases) and attributes, which are a map of |
|
1013 |
* (name, value) String pairs. |
|
1014 |
* |
|
1015 |
* <p>This class defines the methods {@link #supportsParameter |
|
1016 |
* supportsParameter()} and {@link #newInstance newInstance()} |
|
1017 |
* which are used by the Java security framework when it searches for |
|
1018 |
* suitable services and instantes them. The valid arguments to those |
|
1019 |
* methods depend on the type of service. For the service types defined |
|
1020 |
* within Java SE, see the |
|
1021 |
* <a href="../../../technotes/guides/security/crypto/CryptoSpec.html"> |
|
1022 |
* Java Cryptography Architecture API Specification & Reference </a> |
|
1023 |
* for the valid values. |
|
1024 |
* Note that components outside of Java SE can define additional types of |
|
1025 |
* services and their behavior. |
|
1026 |
* |
|
1027 |
* <p>Instances of this class are immutable. |
|
1028 |
* |
|
1029 |
* @since 1.5 |
|
1030 |
*/ |
|
1031 |
public static class Service { |
|
1032 |
||
1033 |
private String type, algorithm, className; |
|
1034 |
private final Provider provider; |
|
1035 |
private List<String> aliases; |
|
1036 |
private Map<UString,String> attributes; |
|
1037 |
||
1038 |
// Reference to the cached implementation Class object |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1039 |
private volatile Reference<Class<?>> classRef; |
2 | 1040 |
|
1041 |
// flag indicating whether this service has its attributes for |
|
1042 |
// supportedKeyFormats or supportedKeyClasses set |
|
1043 |
// if null, the values have not been initialized |
|
1044 |
// if TRUE, at least one of supportedFormats/Classes is non null |
|
1045 |
private volatile Boolean hasKeyAttributes; |
|
1046 |
||
1047 |
// supported encoding formats |
|
1048 |
private String[] supportedFormats; |
|
1049 |
||
1050 |
// names of the supported key (super) classes |
|
1051 |
private Class[] supportedClasses; |
|
1052 |
||
1053 |
// whether this service has been registered with the Provider |
|
1054 |
private boolean registered; |
|
1055 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1056 |
private static final Class<?>[] CLASS0 = new Class<?>[0]; |
2 | 1057 |
|
1058 |
// this constructor and these methods are used for parsing |
|
1059 |
// the legacy string properties. |
|
1060 |
||
1061 |
private Service(Provider provider) { |
|
1062 |
this.provider = provider; |
|
1063 |
aliases = Collections.<String>emptyList(); |
|
1064 |
attributes = Collections.<UString,String>emptyMap(); |
|
1065 |
} |
|
1066 |
||
1067 |
private boolean isValid() { |
|
1068 |
return (type != null) && (algorithm != null) && (className != null); |
|
1069 |
} |
|
1070 |
||
1071 |
private void addAlias(String alias) { |
|
1072 |
if (aliases.isEmpty()) { |
|
1073 |
aliases = new ArrayList<String>(2); |
|
1074 |
} |
|
1075 |
aliases.add(alias); |
|
1076 |
} |
|
1077 |
||
1078 |
void addAttribute(String type, String value) { |
|
1079 |
if (attributes.isEmpty()) { |
|
1080 |
attributes = new HashMap<UString,String>(8); |
|
1081 |
} |
|
1082 |
attributes.put(new UString(type), value); |
|
1083 |
} |
|
1084 |
||
1085 |
/** |
|
1086 |
* Construct a new service. |
|
1087 |
* |
|
1088 |
* @param provider the provider that offers this service |
|
1089 |
* @param type the type of this service |
|
1090 |
* @param algorithm the algorithm name |
|
1091 |
* @param className the name of the class implementing this service |
|
1092 |
* @param aliases List of aliases or null if algorithm has no aliases |
|
1093 |
* @param attributes Map of attributes or null if this implementation |
|
1094 |
* has no attributes |
|
1095 |
* |
|
1096 |
* @throws NullPointerException if provider, type, algorithm, or |
|
1097 |
* className is null |
|
1098 |
*/ |
|
1099 |
public Service(Provider provider, String type, String algorithm, |
|
1100 |
String className, List<String> aliases, |
|
1101 |
Map<String,String> attributes) { |
|
1102 |
if ((provider == null) || (type == null) || |
|
1103 |
(algorithm == null) || (className == null)) { |
|
1104 |
throw new NullPointerException(); |
|
1105 |
} |
|
1106 |
this.provider = provider; |
|
1107 |
this.type = getEngineName(type); |
|
1108 |
this.algorithm = algorithm; |
|
1109 |
this.className = className; |
|
1110 |
if (aliases == null) { |
|
1111 |
this.aliases = Collections.<String>emptyList(); |
|
1112 |
} else { |
|
1113 |
this.aliases = new ArrayList<String>(aliases); |
|
1114 |
} |
|
1115 |
if (attributes == null) { |
|
1116 |
this.attributes = Collections.<UString,String>emptyMap(); |
|
1117 |
} else { |
|
1118 |
this.attributes = new HashMap<UString,String>(); |
|
1119 |
for (Map.Entry<String,String> entry : attributes.entrySet()) { |
|
1120 |
this.attributes.put(new UString(entry.getKey()), entry.getValue()); |
|
1121 |
} |
|
1122 |
} |
|
1123 |
} |
|
1124 |
||
1125 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1126 |
* Get the type of this service. For example, {@code MessageDigest}. |
2 | 1127 |
* |
1128 |
* @return the type of this service |
|
1129 |
*/ |
|
1130 |
public final String getType() { |
|
1131 |
return type; |
|
1132 |
} |
|
1133 |
||
1134 |
/** |
|
1135 |
* Return the name of the algorithm of this service. For example, |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1136 |
* {@code SHA-1}. |
2 | 1137 |
* |
1138 |
* @return the algorithm of this service |
|
1139 |
*/ |
|
1140 |
public final String getAlgorithm() { |
|
1141 |
return algorithm; |
|
1142 |
} |
|
1143 |
||
1144 |
/** |
|
1145 |
* Return the Provider of this service. |
|
1146 |
* |
|
1147 |
* @return the Provider of this service |
|
1148 |
*/ |
|
1149 |
public final Provider getProvider() { |
|
1150 |
return provider; |
|
1151 |
} |
|
1152 |
||
1153 |
/** |
|
1154 |
* Return the name of the class implementing this service. |
|
1155 |
* |
|
1156 |
* @return the name of the class implementing this service |
|
1157 |
*/ |
|
1158 |
public final String getClassName() { |
|
1159 |
return className; |
|
1160 |
} |
|
1161 |
||
1162 |
// internal only |
|
1163 |
private final List<String> getAliases() { |
|
1164 |
return aliases; |
|
1165 |
} |
|
1166 |
||
1167 |
/** |
|
1168 |
* Return the value of the specified attribute or null if this |
|
1169 |
* attribute is not set for this Service. |
|
1170 |
* |
|
1171 |
* @param name the name of the requested attribute |
|
1172 |
* |
|
1173 |
* @return the value of the specified attribute or null if the |
|
1174 |
* attribute is not present |
|
1175 |
* |
|
1176 |
* @throws NullPointerException if name is null |
|
1177 |
*/ |
|
1178 |
public final String getAttribute(String name) { |
|
1179 |
if (name == null) { |
|
1180 |
throw new NullPointerException(); |
|
1181 |
} |
|
1182 |
return attributes.get(new UString(name)); |
|
1183 |
} |
|
1184 |
||
1185 |
/** |
|
1186 |
* Return a new instance of the implementation described by this |
|
1187 |
* service. The security provider framework uses this method to |
|
1188 |
* construct implementations. Applications will typically not need |
|
1189 |
* to call it. |
|
1190 |
* |
|
1191 |
* <p>The default implementation uses reflection to invoke the |
|
1192 |
* standard constructor for this type of service. |
|
1193 |
* Security providers can override this method to implement |
|
1194 |
* instantiation in a different way. |
|
1195 |
* For details and the values of constructorParameter that are |
|
1196 |
* valid for the various types of services see the |
|
1197 |
* <a href="../../../technotes/guides/security/crypto/CryptoSpec.html"> |
|
1198 |
* Java Cryptography Architecture API Specification & |
|
1199 |
* Reference</a>. |
|
1200 |
* |
|
1201 |
* @param constructorParameter the value to pass to the constructor, |
|
1202 |
* or null if this type of service does not use a constructorParameter. |
|
1203 |
* |
|
1204 |
* @return a new implementation of this service |
|
1205 |
* |
|
1206 |
* @throws InvalidParameterException if the value of |
|
1207 |
* constructorParameter is invalid for this type of service. |
|
1208 |
* @throws NoSuchAlgorithmException if instantation failed for |
|
1209 |
* any other reason. |
|
1210 |
*/ |
|
1211 |
public Object newInstance(Object constructorParameter) |
|
1212 |
throws NoSuchAlgorithmException { |
|
1213 |
if (registered == false) { |
|
1214 |
if (provider.getService(type, algorithm) != this) { |
|
1215 |
throw new NoSuchAlgorithmException |
|
1216 |
("Service not registered with Provider " |
|
1217 |
+ provider.getName() + ": " + this); |
|
1218 |
} |
|
1219 |
registered = true; |
|
1220 |
} |
|
1221 |
try { |
|
1222 |
EngineDescription cap = knownEngines.get(type); |
|
1223 |
if (cap == null) { |
|
1224 |
// unknown engine type, use generic code |
|
1225 |
// this is the code path future for non-core |
|
1226 |
// optional packages |
|
1227 |
return newInstanceGeneric(constructorParameter); |
|
1228 |
} |
|
1229 |
if (cap.constructorParameterClassName == null) { |
|
1230 |
if (constructorParameter != null) { |
|
1231 |
throw new InvalidParameterException |
|
1232 |
("constructorParameter not used with " + type |
|
1233 |
+ " engines"); |
|
1234 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1235 |
Class<?> clazz = getImplClass(); |
2 | 1236 |
return clazz.newInstance(); |
1237 |
} else { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1238 |
Class<?> paramClass = cap.getConstructorParameterClass(); |
2 | 1239 |
if (constructorParameter != null) { |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1240 |
Class<?> argClass = constructorParameter.getClass(); |
2 | 1241 |
if (paramClass.isAssignableFrom(argClass) == false) { |
1242 |
throw new InvalidParameterException |
|
1243 |
("constructorParameter must be instanceof " |
|
1244 |
+ cap.constructorParameterClassName.replace('$', '.') |
|
1245 |
+ " for engine type " + type); |
|
1246 |
} |
|
1247 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1248 |
Class<?> clazz = getImplClass(); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1249 |
Constructor<?> cons = clazz.getConstructor(paramClass); |
2 | 1250 |
return cons.newInstance(constructorParameter); |
1251 |
} |
|
1252 |
} catch (NoSuchAlgorithmException e) { |
|
1253 |
throw e; |
|
1254 |
} catch (InvocationTargetException e) { |
|
1255 |
throw new NoSuchAlgorithmException |
|
1256 |
("Error constructing implementation (algorithm: " |
|
1257 |
+ algorithm + ", provider: " + provider.getName() |
|
1258 |
+ ", class: " + className + ")", e.getCause()); |
|
1259 |
} catch (Exception e) { |
|
1260 |
throw new NoSuchAlgorithmException |
|
1261 |
("Error constructing implementation (algorithm: " |
|
1262 |
+ algorithm + ", provider: " + provider.getName() |
|
1263 |
+ ", class: " + className + ")", e); |
|
1264 |
} |
|
1265 |
} |
|
1266 |
||
1267 |
// return the implementation Class object for this service |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1268 |
private Class<?> getImplClass() throws NoSuchAlgorithmException { |
2 | 1269 |
try { |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1270 |
Reference<Class<?>> ref = classRef; |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1271 |
Class<?> clazz = (ref == null) ? null : ref.get(); |
2 | 1272 |
if (clazz == null) { |
1273 |
ClassLoader cl = provider.getClass().getClassLoader(); |
|
1274 |
if (cl == null) { |
|
1275 |
clazz = Class.forName(className); |
|
1276 |
} else { |
|
1277 |
clazz = cl.loadClass(className); |
|
1278 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1279 |
classRef = new WeakReference<Class<?>>(clazz); |
2 | 1280 |
} |
1281 |
return clazz; |
|
1282 |
} catch (ClassNotFoundException e) { |
|
1283 |
throw new NoSuchAlgorithmException |
|
1284 |
("class configured for " + type + "(provider: " + |
|
1285 |
provider.getName() + ")" + "cannot be found.", e); |
|
1286 |
} |
|
1287 |
} |
|
1288 |
||
1289 |
/** |
|
1290 |
* Generic code path for unknown engine types. Call the |
|
1291 |
* no-args constructor if constructorParameter is null, otherwise |
|
1292 |
* use the first matching constructor. |
|
1293 |
*/ |
|
1294 |
private Object newInstanceGeneric(Object constructorParameter) |
|
1295 |
throws Exception { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1296 |
Class<?> clazz = getImplClass(); |
2 | 1297 |
if (constructorParameter == null) { |
1298 |
Object o = clazz.newInstance(); |
|
1299 |
return o; |
|
1300 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1301 |
Class<?> argClass = constructorParameter.getClass(); |
2 | 1302 |
Constructor[] cons = clazz.getConstructors(); |
1303 |
// find first public constructor that can take the |
|
1304 |
// argument as parameter |
|
1305 |
for (int i = 0; i < cons.length; i++) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1306 |
Constructor<?> con = cons[i]; |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1307 |
Class<?>[] paramTypes = con.getParameterTypes(); |
2 | 1308 |
if (paramTypes.length != 1) { |
1309 |
continue; |
|
1310 |
} |
|
1311 |
if (paramTypes[0].isAssignableFrom(argClass) == false) { |
|
1312 |
continue; |
|
1313 |
} |
|
1314 |
Object o = con.newInstance(new Object[] {constructorParameter}); |
|
1315 |
return o; |
|
1316 |
} |
|
1317 |
throw new NoSuchAlgorithmException("No constructor matching " |
|
1318 |
+ argClass.getName() + " found in class " + className); |
|
1319 |
} |
|
1320 |
||
1321 |
/** |
|
1322 |
* Test whether this Service can use the specified parameter. |
|
1323 |
* Returns false if this service cannot use the parameter. Returns |
|
1324 |
* true if this service can use the parameter, if a fast test is |
|
1325 |
* infeasible, or if the status is unknown. |
|
1326 |
* |
|
1327 |
* <p>The security provider framework uses this method with |
|
1328 |
* some types of services to quickly exclude non-matching |
|
1329 |
* implementations for consideration. |
|
1330 |
* Applications will typically not need to call it. |
|
1331 |
* |
|
1332 |
* <p>For details and the values of parameter that are valid for the |
|
1333 |
* various types of services see the top of this class and the |
|
1334 |
* <a href="../../../technotes/guides/security/crypto/CryptoSpec.html"> |
|
1335 |
* Java Cryptography Architecture API Specification & |
|
1336 |
* Reference</a>. |
|
1337 |
* Security providers can override it to implement their own test. |
|
1338 |
* |
|
1339 |
* @param parameter the parameter to test |
|
1340 |
* |
|
1341 |
* @return false if this this service cannot use the specified |
|
1342 |
* parameter; true if it can possibly use the parameter |
|
1343 |
* |
|
1344 |
* @throws InvalidParameterException if the value of parameter is |
|
1345 |
* invalid for this type of service or if this method cannot be |
|
1346 |
* used with this type of service |
|
1347 |
*/ |
|
1348 |
public boolean supportsParameter(Object parameter) { |
|
1349 |
EngineDescription cap = knownEngines.get(type); |
|
1350 |
if (cap == null) { |
|
1351 |
// unknown engine type, return true by default |
|
1352 |
return true; |
|
1353 |
} |
|
1354 |
if (cap.supportsParameter == false) { |
|
1355 |
throw new InvalidParameterException("supportsParameter() not " |
|
1356 |
+ "used with " + type + " engines"); |
|
1357 |
} |
|
1358 |
// allow null for keys without attributes for compatibility |
|
1359 |
if ((parameter != null) && (parameter instanceof Key == false)) { |
|
1360 |
throw new InvalidParameterException |
|
1361 |
("Parameter must be instanceof Key for engine " + type); |
|
1362 |
} |
|
1363 |
if (hasKeyAttributes() == false) { |
|
1364 |
return true; |
|
1365 |
} |
|
1366 |
if (parameter == null) { |
|
1367 |
return false; |
|
1368 |
} |
|
1369 |
Key key = (Key)parameter; |
|
1370 |
if (supportsKeyFormat(key)) { |
|
1371 |
return true; |
|
1372 |
} |
|
1373 |
if (supportsKeyClass(key)) { |
|
1374 |
return true; |
|
1375 |
} |
|
1376 |
return false; |
|
1377 |
} |
|
1378 |
||
1379 |
/** |
|
1380 |
* Return whether this service has its Supported* properties for |
|
1381 |
* keys defined. Parses the attributes if not yet initialized. |
|
1382 |
*/ |
|
1383 |
private boolean hasKeyAttributes() { |
|
1384 |
Boolean b = hasKeyAttributes; |
|
1385 |
if (b == null) { |
|
1386 |
synchronized (this) { |
|
1387 |
String s; |
|
1388 |
s = getAttribute("SupportedKeyFormats"); |
|
1389 |
if (s != null) { |
|
1390 |
supportedFormats = s.split("\\|"); |
|
1391 |
} |
|
1392 |
s = getAttribute("SupportedKeyClasses"); |
|
1393 |
if (s != null) { |
|
1394 |
String[] classNames = s.split("\\|"); |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1395 |
List<Class<?>> classList = |
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
1396 |
new ArrayList<>(classNames.length); |
2 | 1397 |
for (String className : classNames) { |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1398 |
Class<?> clazz = getKeyClass(className); |
2 | 1399 |
if (clazz != null) { |
1400 |
classList.add(clazz); |
|
1401 |
} |
|
1402 |
} |
|
1403 |
supportedClasses = classList.toArray(CLASS0); |
|
1404 |
} |
|
1405 |
boolean bool = (supportedFormats != null) |
|
1406 |
|| (supportedClasses != null); |
|
1407 |
b = Boolean.valueOf(bool); |
|
1408 |
hasKeyAttributes = b; |
|
1409 |
} |
|
1410 |
} |
|
1411 |
return b.booleanValue(); |
|
1412 |
} |
|
1413 |
||
1414 |
// get the key class object of the specified name |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1415 |
private Class<?> getKeyClass(String name) { |
2 | 1416 |
try { |
1417 |
return Class.forName(name); |
|
1418 |
} catch (ClassNotFoundException e) { |
|
1419 |
// ignore |
|
1420 |
} |
|
1421 |
try { |
|
1422 |
ClassLoader cl = provider.getClass().getClassLoader(); |
|
1423 |
if (cl != null) { |
|
1424 |
return cl.loadClass(name); |
|
1425 |
} |
|
1426 |
} catch (ClassNotFoundException e) { |
|
1427 |
// ignore |
|
1428 |
} |
|
1429 |
return null; |
|
1430 |
} |
|
1431 |
||
1432 |
private boolean supportsKeyFormat(Key key) { |
|
1433 |
if (supportedFormats == null) { |
|
1434 |
return false; |
|
1435 |
} |
|
1436 |
String format = key.getFormat(); |
|
1437 |
if (format == null) { |
|
1438 |
return false; |
|
1439 |
} |
|
1440 |
for (String supportedFormat : supportedFormats) { |
|
1441 |
if (supportedFormat.equals(format)) { |
|
1442 |
return true; |
|
1443 |
} |
|
1444 |
} |
|
1445 |
return false; |
|
1446 |
} |
|
1447 |
||
1448 |
private boolean supportsKeyClass(Key key) { |
|
1449 |
if (supportedClasses == null) { |
|
1450 |
return false; |
|
1451 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1452 |
Class<?> keyClass = key.getClass(); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1453 |
for (Class<?> clazz : supportedClasses) { |
2 | 1454 |
if (clazz.isAssignableFrom(keyClass)) { |
1455 |
return true; |
|
1456 |
} |
|
1457 |
} |
|
1458 |
return false; |
|
1459 |
} |
|
1460 |
||
1461 |
/** |
|
1462 |
* Return a String representation of this service. |
|
1463 |
* |
|
1464 |
* @return a String representation of this service. |
|
1465 |
*/ |
|
1466 |
public String toString() { |
|
1467 |
String aString = aliases.isEmpty() |
|
1468 |
? "" : "\r\n aliases: " + aliases.toString(); |
|
1469 |
String attrs = attributes.isEmpty() |
|
1470 |
? "" : "\r\n attributes: " + attributes.toString(); |
|
1471 |
return provider.getName() + ": " + type + "." + algorithm |
|
1472 |
+ " -> " + className + aString + attrs + "\r\n"; |
|
1473 |
} |
|
1474 |
||
1475 |
} |
|
1476 |
||
1477 |
} |