author | phh |
Wed, 25 Sep 2019 08:29:03 -0700 | |
changeset 58337 | 270abce77942 |
parent 58242 | 94bb65cb37d3 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
52995
diff
changeset
|
2 |
* Copyright (c) 1996, 2019, 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.*; |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
33 |
import java.util.function.BiConsumer; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
34 |
import java.util.function.BiFunction; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
35 |
import java.util.function.Function; |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
36 |
import java.util.concurrent.ConcurrentHashMap; |
2 | 37 |
|
38 |
/** |
|
39 |
* This class represents a "provider" for the |
|
40 |
* Java Security API, where a provider implements some or all parts of |
|
41 |
* Java Security. Services that a provider may implement include: |
|
42 |
* |
|
43 |
* <ul> |
|
44 |
* |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
45 |
* <li>Algorithms (such as DSA, RSA, or SHA-256). |
2 | 46 |
* |
47 |
* <li>Key generation, conversion, and management facilities (such as for |
|
48 |
* algorithm-specific keys). |
|
49 |
* |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
50 |
* </ul> |
2 | 51 |
* |
52 |
* <p>Some provider implementations may encounter unrecoverable internal |
|
53 |
* errors during their operation, for example a failure to communicate with a |
|
54 |
* security token. A {@link ProviderException} should be used to indicate |
|
55 |
* such errors. |
|
56 |
* |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
57 |
* <p>Please note that a provider can be used to implement any security |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
58 |
* service in Java that uses a pluggable architecture with a choice |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
59 |
* of implementations that fit underneath. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
60 |
* |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
61 |
* <p>The service type {@code Provider} is reserved for use by the |
2 | 62 |
* security framework. Services of this type cannot be added, removed, |
63 |
* or modified by applications. |
|
64 |
* The following attributes are automatically placed in each Provider object: |
|
46153 | 65 |
* <table class="striped"> |
18592
80cdfecea074
8019539: Fix doclint errors in java.security and its subpackages
juh
parents:
18579
diff
changeset
|
66 |
* <caption><b>Attributes Automatically Placed in a Provider Object</b></caption> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
40416
diff
changeset
|
67 |
* <thead> |
46153 | 68 |
* <tr><th scope="col">Name</th><th scope="col">Value</th> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
40416
diff
changeset
|
69 |
* </thead> |
46153 | 70 |
* <tbody style="text-align:left"> |
71 |
* <tr><th scope="row">{@code Provider.id name}</th> |
|
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
40416
diff
changeset
|
72 |
* <td>{@code String.valueOf(provider.getName())}</td> |
46153 | 73 |
* <tr><th scope="row">{@code Provider.id version}</th> |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
74 |
* <td>{@code String.valueOf(provider.getVersionStr())}</td> |
46153 | 75 |
* <tr><th scope="row">{@code Provider.id info}</th> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
40416
diff
changeset
|
76 |
* <td>{@code String.valueOf(provider.getInfo())}</td> |
46153 | 77 |
* <tr><th scope="row">{@code Provider.id className}</th> |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
78 |
* <td>{@code provider.getClass().getName()}</td> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
40416
diff
changeset
|
79 |
* </tbody> |
2 | 80 |
* </table> |
81 |
* |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
82 |
* <p>Each provider has a name and a version string. A provider normally |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
83 |
* identifies itself with a file named {@code java.security.Provider} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
84 |
* in the resource directory {@code META-INF/services}. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
85 |
* Security providers are looked up via the {@link ServiceLoader} mechanism |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
86 |
* using the {@link ClassLoader#getSystemClassLoader application class loader}. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
87 |
* |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
88 |
* <p>Providers may be configured such that they are automatically |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
89 |
* installed and made available at runtime via the |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
90 |
* {@link Security#getProviders() Security.getProviders()} method. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
91 |
* The mechanism for configuring and installing security providers is |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
92 |
* implementation-specific. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
93 |
* |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
94 |
* @implNote |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
95 |
* The JDK implementation supports static registration of the security |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
96 |
* providers via the {@code conf/security/java.security} file in the Java |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
97 |
* installation directory. These providers are automatically installed by |
45665 | 98 |
* the JDK runtime, see {@extLink security_guide_jca_provider |
99 |
* The Provider Class} |
|
100 |
* in the Java Cryptography Architecture (JCA) Reference Guide |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
101 |
* for information about how a particular type of provider, the cryptographic |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
102 |
* service provider, works and is installed. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
103 |
* |
2 | 104 |
* @author Benjamin Renaud |
105 |
* @author Andreas Sterbenz |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
45124
diff
changeset
|
106 |
* @since 1.1 |
2 | 107 |
*/ |
108 |
public abstract class Provider extends Properties { |
|
109 |
||
110 |
// Declare serialVersionUID to be compatible with JDK1.1 |
|
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
52995
diff
changeset
|
111 |
@java.io.Serial |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
112 |
private static final long serialVersionUID = -4298000515446427739L; |
2 | 113 |
|
114 |
private static final sun.security.util.Debug debug = |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
115 |
sun.security.util.Debug.getInstance("provider", "Provider"); |
2 | 116 |
|
117 |
/** |
|
118 |
* The provider name. |
|
119 |
* |
|
120 |
* @serial |
|
121 |
*/ |
|
122 |
private String name; |
|
123 |
||
124 |
/** |
|
125 |
* A description of the provider and its services. |
|
126 |
* |
|
127 |
* @serial |
|
128 |
*/ |
|
129 |
private String info; |
|
130 |
||
131 |
/** |
|
132 |
* The provider version number. |
|
133 |
* |
|
134 |
* @serial |
|
135 |
*/ |
|
136 |
private double version; |
|
137 |
||
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
138 |
/** |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
139 |
* The provider version string. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
140 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
141 |
* @serial |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
142 |
*/ |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
143 |
private String versionStr; |
2 | 144 |
|
145 |
private transient Set<Map.Entry<Object,Object>> entrySet = null; |
|
146 |
private transient int entrySetCallCount = 0; |
|
147 |
||
148 |
private transient boolean initialized; |
|
149 |
||
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
150 |
private static Object newInstanceUtil(final Class<?> clazz, |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
151 |
final Class<?> ctrParamClz, final Object ctorParamObj) |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
152 |
throws Exception { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
153 |
if (ctrParamClz == null) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
154 |
Constructor<?> con = clazz.getConstructor(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
155 |
return con.newInstance(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
156 |
} else { |
37796
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
157 |
// Looking for the constructor with a params first and fallback |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
158 |
// to one without if not found. This is to support the enhanced |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
159 |
// SecureRandom where both styles of constructors are supported. |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
160 |
// Before jdk9, there was no params support (only getInstance(alg)) |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
161 |
// and an impl only had the params-less constructor. Since jdk9, |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
162 |
// there is getInstance(alg,params) and an impl can contain |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
163 |
// an Impl(params) constructor. |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
164 |
try { |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
165 |
Constructor<?> con = clazz.getConstructor(ctrParamClz); |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
166 |
return con.newInstance(ctorParamObj); |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
167 |
} catch (NoSuchMethodException nsme) { |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
168 |
// For pre-jdk9 SecureRandom implementations, they only |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
169 |
// have params-less constructors which still works when |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
170 |
// the input ctorParamObj is null. |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
171 |
// |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
172 |
// For other primitives using params, ctorParamObj should not |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
173 |
// be null and nsme is thrown, just like before. |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
174 |
if (ctorParamObj == null) { |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
175 |
try { |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
176 |
Constructor<?> con = clazz.getConstructor(); |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
177 |
return con.newInstance(); |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
178 |
} catch (NoSuchMethodException nsme2) { |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
179 |
nsme.addSuppressed(nsme2); |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
180 |
throw nsme; |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
181 |
} |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
182 |
} else { |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
183 |
throw nsme; |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
184 |
} |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
185 |
} |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
186 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
187 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
188 |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
189 |
private static double parseVersionStr(String s) { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
190 |
try { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
191 |
int firstDotIdx = s.indexOf('.'); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
192 |
int nextDotIdx = s.indexOf('.', firstDotIdx + 1); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
193 |
if (nextDotIdx != -1) { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
194 |
s = s.substring(0, nextDotIdx); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
195 |
} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
196 |
int endIdx = s.indexOf('-'); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
197 |
if (endIdx > 0) { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
198 |
s = s.substring(0, endIdx); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
199 |
} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
200 |
endIdx = s.indexOf('+'); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
201 |
if (endIdx > 0) { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
202 |
s = s.substring(0, endIdx); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
203 |
} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
204 |
return Double.parseDouble(s); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
205 |
} catch (NullPointerException | NumberFormatException e) { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
206 |
return 0d; |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
207 |
} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
208 |
} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
209 |
|
2 | 210 |
/** |
211 |
* Constructs a provider with the specified name, version number, |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
212 |
* and information. Calling this constructor is equivalent to call the |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
213 |
* {@link #Provider(String, String, String)} with {@code name} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
214 |
* name, {@code Double.toString(version)}, and {@code info}. |
2 | 215 |
* |
216 |
* @param name the provider name. |
|
217 |
* |
|
218 |
* @param version the provider version number. |
|
219 |
* |
|
220 |
* @param info a description of the provider and its services. |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
221 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
222 |
* @deprecated use {@link #Provider(String, String, String)} instead. |
2 | 223 |
*/ |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
224 |
@Deprecated(since="9") |
2 | 225 |
protected Provider(String name, double version, String info) { |
226 |
this.name = name; |
|
227 |
this.version = version; |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
228 |
this.versionStr = Double.toString(version); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
229 |
this.info = info; |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
230 |
this.serviceMap = new ConcurrentHashMap<>(); |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
231 |
putId(); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
232 |
initialized = true; |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
233 |
} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
234 |
|
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
235 |
/** |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
236 |
* Constructs a provider with the specified name, version string, |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
237 |
* and information. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
238 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
239 |
* <p>The version string contains a version number optionally followed |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
240 |
* by other information separated by one of the characters of '+', '-'. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
241 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
242 |
* The format for the version number is: |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
243 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
244 |
* <blockquote><pre> |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
245 |
* ^[0-9]+(\.[0-9]+)* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
246 |
* </pre></blockquote> |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
247 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
248 |
* <p>In order to return the version number in a double, when there are |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
249 |
* more than two components (separated by '.' as defined above), only |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
250 |
* the first two components are retained. The resulting string is then |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
251 |
* passed to {@link Double#valueOf(String)} to generate version number, |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
252 |
* i.e. {@link #getVersion}. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
253 |
* <p>If the conversion failed, value 0 will be used. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
254 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
255 |
* @param name the provider name. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
256 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
257 |
* @param versionStr the provider version string. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
258 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
259 |
* @param info a description of the provider and its services. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
260 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
261 |
* @since 9 |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
262 |
*/ |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
263 |
protected Provider(String name, String versionStr, String info) { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
264 |
this.name = name; |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
265 |
this.versionStr = versionStr; |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
266 |
this.version = parseVersionStr(versionStr); |
2 | 267 |
this.info = info; |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
268 |
this.serviceMap = new ConcurrentHashMap<>(); |
2 | 269 |
putId(); |
270 |
initialized = true; |
|
271 |
} |
|
272 |
||
273 |
/** |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
274 |
* Apply the supplied configuration argument to this provider instance |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
275 |
* and return the configured provider. Note that if this provider cannot |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
276 |
* be configured in-place, a new provider will be created and returned. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
277 |
* Therefore, callers should always use the returned provider. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
278 |
* |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
279 |
* @implSpec |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
280 |
* The default implementation throws {@code UnsupportedOperationException}. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
281 |
* Subclasses should override this method only if a configuration argument |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
282 |
* is supported. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
283 |
* |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
284 |
* @param configArg the configuration information for configuring this |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
285 |
* provider. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
286 |
* |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
287 |
* @throws UnsupportedOperationException if a configuration argument is |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
288 |
* not supported. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
289 |
* @throws NullPointerException if the supplied configuration argument is |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
290 |
null. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
291 |
* @throws InvalidParameterException if the supplied configuration argument |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
292 |
* is invalid. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
293 |
* @return a provider configured with the supplied configuration argument. |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
294 |
* |
32931
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
295 |
* @since 9 |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
296 |
*/ |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
297 |
public Provider configure(String configArg) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
298 |
throw new UnsupportedOperationException("configure is not supported"); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
299 |
} |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
300 |
|
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
301 |
/** |
32931
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
302 |
* Check if this provider instance has been configured. |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
303 |
* |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
304 |
* @implSpec |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
305 |
* The default implementation returns true. |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
306 |
* Subclasses should override this method if the provider instance requires |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
307 |
* an explicit {@code configure} call after being constructed. |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
308 |
* |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
309 |
* @return true if no further configuration is needed, false otherwise. |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
310 |
* |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
311 |
* @since 9 |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
312 |
*/ |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
313 |
public boolean isConfigured() { |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
314 |
return true; |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
315 |
} |
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
316 |
|
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
317 |
|
2ba4f06f8684
8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents:
32649
diff
changeset
|
318 |
/** |
2 | 319 |
* Returns the name of this provider. |
320 |
* |
|
321 |
* @return the name of this provider. |
|
322 |
*/ |
|
323 |
public String getName() { |
|
324 |
return name; |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
* Returns the version number for this provider. |
|
329 |
* |
|
330 |
* @return the version number for this provider. |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
331 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
332 |
* @deprecated use {@link #getVersionStr} instead. |
2 | 333 |
*/ |
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
334 |
@Deprecated(since="9") |
2 | 335 |
public double getVersion() { |
336 |
return version; |
|
337 |
} |
|
338 |
||
339 |
/** |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
340 |
* Returns the version string for this provider. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
341 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
342 |
* @return the version string for this provider. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
343 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
344 |
* @since 9 |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
345 |
*/ |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
346 |
public String getVersionStr() { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
347 |
return versionStr; |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
348 |
} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
349 |
|
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
350 |
/** |
2 | 351 |
* Returns a human-readable description of the provider and its |
352 |
* services. This may return an HTML page, with relevant links. |
|
353 |
* |
|
354 |
* @return a description of the provider and its services. |
|
355 |
*/ |
|
356 |
public String getInfo() { |
|
357 |
return info; |
|
358 |
} |
|
359 |
||
360 |
/** |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
361 |
* Returns a string with the name and the version string |
2 | 362 |
* of this provider. |
363 |
* |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
364 |
* @return the string with the name and the version string |
2 | 365 |
* for this provider. |
366 |
*/ |
|
367 |
public String toString() { |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
368 |
return name + " version " + versionStr; |
2 | 369 |
} |
370 |
||
371 |
/* |
|
372 |
* override the following methods to ensure that provider |
|
373 |
* information can only be changed if the caller has the appropriate |
|
374 |
* permissions. |
|
375 |
*/ |
|
376 |
||
377 |
/** |
|
378 |
* Clears this provider so that it no longer contains the properties |
|
379 |
* used to look up facilities implemented by the provider. |
|
380 |
* |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
381 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
382 |
* method is called with the string {@code "clearProviderProperties."+name} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
383 |
* (where {@code name} is the provider name) to see if it's ok to clear |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
384 |
* this provider. |
2 | 385 |
* |
386 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
387 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
388 |
* java.lang.SecurityManager#checkSecurityAccess} method |
2 | 389 |
* denies access to clear this provider |
390 |
* |
|
391 |
* @since 1.2 |
|
392 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
393 |
@Override |
2 | 394 |
public synchronized void clear() { |
395 |
check("clearProviderProperties."+name); |
|
396 |
if (debug != null) { |
|
397 |
debug.println("Remove " + name + " provider properties"); |
|
398 |
} |
|
399 |
implClear(); |
|
400 |
} |
|
401 |
||
402 |
/** |
|
403 |
* Reads a property list (key and element pairs) from the input stream. |
|
404 |
* |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
405 |
* @param inStream the input stream. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57950
diff
changeset
|
406 |
* @throws IOException if an error occurred when reading from the |
2 | 407 |
* input stream. |
408 |
* @see java.util.Properties#load |
|
409 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
410 |
@Override |
2 | 411 |
public synchronized void load(InputStream inStream) throws IOException { |
412 |
check("putProviderProperty."+name); |
|
413 |
if (debug != null) { |
|
414 |
debug.println("Load " + name + " provider properties"); |
|
415 |
} |
|
416 |
Properties tempProperties = new Properties(); |
|
417 |
tempProperties.load(inStream); |
|
418 |
implPutAll(tempProperties); |
|
419 |
} |
|
420 |
||
421 |
/** |
|
422 |
* Copies all of the mappings from the specified Map to this provider. |
|
423 |
* These mappings will replace any properties that this provider had |
|
424 |
* for any of the keys currently in the specified Map. |
|
425 |
* |
|
426 |
* @since 1.2 |
|
427 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
428 |
@Override |
2 | 429 |
public synchronized void putAll(Map<?,?> t) { |
430 |
check("putProviderProperty."+name); |
|
431 |
if (debug != null) { |
|
432 |
debug.println("Put all " + name + " provider properties"); |
|
433 |
} |
|
434 |
implPutAll(t); |
|
435 |
} |
|
436 |
||
437 |
/** |
|
438 |
* Returns an unmodifiable Set view of the property entries contained |
|
439 |
* in this Provider. |
|
440 |
* |
|
441 |
* @see java.util.Map.Entry |
|
442 |
* @since 1.2 |
|
443 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
444 |
@Override |
2 | 445 |
public synchronized Set<Map.Entry<Object,Object>> entrySet() { |
446 |
checkInitialized(); |
|
447 |
if (entrySet == null) { |
|
448 |
if (entrySetCallCount++ == 0) // Initial call |
|
449 |
entrySet = Collections.unmodifiableMap(this).entrySet(); |
|
450 |
else |
|
451 |
return super.entrySet(); // Recursive call |
|
452 |
} |
|
453 |
||
454 |
// This exception will be thrown if the implementation of |
|
455 |
// Collections.unmodifiableMap.entrySet() is changed such that it |
|
456 |
// no longer calls entrySet() on the backing Map. (Provider's |
|
457 |
// entrySet implementation depends on this "implementation detail", |
|
458 |
// which is unlikely to change. |
|
459 |
if (entrySetCallCount != 2) |
|
460 |
throw new RuntimeException("Internal error."); |
|
461 |
||
462 |
return entrySet; |
|
463 |
} |
|
464 |
||
465 |
/** |
|
466 |
* Returns an unmodifiable Set view of the property keys contained in |
|
467 |
* this provider. |
|
468 |
* |
|
469 |
* @since 1.2 |
|
470 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
471 |
@Override |
2 | 472 |
public Set<Object> keySet() { |
473 |
checkInitialized(); |
|
474 |
return Collections.unmodifiableSet(super.keySet()); |
|
475 |
} |
|
476 |
||
477 |
/** |
|
478 |
* Returns an unmodifiable Collection view of the property values |
|
479 |
* contained in this provider. |
|
480 |
* |
|
481 |
* @since 1.2 |
|
482 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
483 |
@Override |
2 | 484 |
public Collection<Object> values() { |
485 |
checkInitialized(); |
|
486 |
return Collections.unmodifiableCollection(super.values()); |
|
487 |
} |
|
488 |
||
489 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
490 |
* 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
|
491 |
* {@code value}. |
2 | 492 |
* |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
493 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
494 |
* method is called with the string {@code "putProviderProperty."+name}, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
495 |
* where {@code name} is the provider name, to see if it's ok to set this |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
496 |
* provider's property values. |
2 | 497 |
* |
498 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
499 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
500 |
* java.lang.SecurityManager#checkSecurityAccess} method |
2 | 501 |
* denies access to set property values. |
502 |
* |
|
503 |
* @since 1.2 |
|
504 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
505 |
@Override |
2 | 506 |
public synchronized Object put(Object key, Object value) { |
507 |
check("putProviderProperty."+name); |
|
508 |
if (debug != null) { |
|
509 |
debug.println("Set " + name + " provider property [" + |
|
510 |
key + "/" + value +"]"); |
|
511 |
} |
|
512 |
return implPut(key, value); |
|
513 |
} |
|
514 |
||
515 |
/** |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
516 |
* If the specified key is not already associated with a value (or is mapped |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
517 |
* to {@code null}) associates it with the given value and returns |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
518 |
* {@code null}, else returns the current value. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
519 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
520 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
521 |
* method is called with the string {@code "putProviderProperty."+name}, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
522 |
* where {@code name} is the provider name, to see if it's ok to set this |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
523 |
* provider's property values. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
524 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
525 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
526 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
527 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
528 |
* denies access to set property values. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
529 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
530 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
531 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
532 |
@Override |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
533 |
public synchronized Object putIfAbsent(Object key, Object value) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
534 |
check("putProviderProperty."+name); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
535 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
536 |
debug.println("Set " + name + " provider property [" + |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
537 |
key + "/" + value +"]"); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
538 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
539 |
return implPutIfAbsent(key, value); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
540 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
541 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
542 |
/** |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
543 |
* Removes the {@code key} property (and its corresponding |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
544 |
* {@code value}). |
2 | 545 |
* |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
546 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
547 |
* method is called with the string {@code "removeProviderProperty."+name}, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
548 |
* where {@code name} is the provider name, to see if it's ok to remove this |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
549 |
* provider's properties. |
2 | 550 |
* |
551 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
552 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
553 |
* java.lang.SecurityManager#checkSecurityAccess} method |
2 | 554 |
* denies access to remove this provider's properties. |
555 |
* |
|
556 |
* @since 1.2 |
|
557 |
*/ |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
558 |
@Override |
2 | 559 |
public synchronized Object remove(Object key) { |
560 |
check("removeProviderProperty."+name); |
|
561 |
if (debug != null) { |
|
562 |
debug.println("Remove " + name + " provider property " + key); |
|
563 |
} |
|
564 |
return implRemove(key); |
|
565 |
} |
|
566 |
||
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
567 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
568 |
* Removes the entry for the specified key only if it is currently |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
569 |
* mapped to the specified value. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
570 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
571 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
572 |
* method is called with the string {@code "removeProviderProperty."+name}, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
573 |
* where {@code name} is the provider name, to see if it's ok to remove this |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
574 |
* provider's properties. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
575 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
576 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
577 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
578 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
579 |
* denies access to remove this provider's properties. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
580 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
581 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
582 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
583 |
@Override |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
584 |
public synchronized boolean remove(Object key, Object value) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
585 |
check("removeProviderProperty."+name); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
586 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
587 |
debug.println("Remove " + name + " provider property " + key); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
588 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
589 |
return implRemove(key, value); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
590 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
591 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
592 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
593 |
* Replaces the entry for the specified key only if currently |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
594 |
* mapped to the specified value. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
595 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
596 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
597 |
* method is called with the string {@code "putProviderProperty."+name}, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
598 |
* where {@code name} is the provider name, to see if it's ok to set this |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
599 |
* provider's property values. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
600 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
601 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
602 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
603 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
604 |
* denies access to set property values. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
605 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
606 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
607 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
608 |
@Override |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
609 |
public synchronized boolean replace(Object key, Object oldValue, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
610 |
Object newValue) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
611 |
check("putProviderProperty." + name); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
612 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
613 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
614 |
debug.println("Replace " + name + " provider property " + key); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
615 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
616 |
return implReplace(key, oldValue, newValue); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
617 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
618 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
619 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
620 |
* Replaces the entry for the specified key only if it is |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
621 |
* currently mapped to some value. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
622 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
623 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
624 |
* method is called with the string {@code "putProviderProperty."+name}, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
625 |
* where {@code name} is the provider name, to see if it's ok to set this |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
626 |
* provider's property values. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
627 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
628 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
629 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
630 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
631 |
* denies access to set property values. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
632 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
633 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
634 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
635 |
@Override |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
636 |
public synchronized Object replace(Object key, Object value) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
637 |
check("putProviderProperty." + name); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
638 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
639 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
640 |
debug.println("Replace " + name + " provider property " + key); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
641 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
642 |
return implReplace(key, value); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
643 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
644 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
645 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
646 |
* Replaces each entry's value with the result of invoking the given |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
647 |
* function on that entry, in the order entries are returned by an entry |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
648 |
* set iterator, until all entries have been processed or the function |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
649 |
* throws an exception. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
650 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
651 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
652 |
* method is called with the string {@code "putProviderProperty."+name}, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
653 |
* where {@code name} is the provider name, to see if it's ok to set this |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
654 |
* provider's property values. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
655 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
656 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
657 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
658 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
659 |
* denies access to set property values. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
660 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
661 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
662 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
663 |
@Override |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
664 |
public synchronized void replaceAll(BiFunction<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
665 |
? super Object, ? extends Object> function) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
666 |
check("putProviderProperty." + name); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
667 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
668 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
669 |
debug.println("ReplaceAll " + name + " provider property "); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
670 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
671 |
implReplaceAll(function); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
672 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
673 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
674 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
675 |
* Attempts to compute a mapping for the specified key and its |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
676 |
* current mapped value (or {@code null} if there is no current |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
677 |
* mapping). |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
678 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
679 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
680 |
* method is called with the strings {@code "putProviderProperty."+name} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
681 |
* and {@code "removeProviderProperty."+name}, where {@code name} is the |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
682 |
* provider name, to see if it's ok to set this provider's property values |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
683 |
* and remove this provider's properties. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
684 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
685 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
686 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
687 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
688 |
* denies access to set property values or remove properties. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
689 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
690 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
691 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
692 |
@Override |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
693 |
public synchronized Object compute(Object key, BiFunction<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
694 |
? super Object, ? extends Object> remappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
695 |
check("putProviderProperty." + name); |
40404
167b711cf138
8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents:
39759
diff
changeset
|
696 |
check("removeProviderProperty." + name); |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
697 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
698 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
699 |
debug.println("Compute " + name + " provider property " + key); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
700 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
701 |
return implCompute(key, remappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
702 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
703 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
704 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
705 |
* If the specified key is not already associated with a value (or |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
706 |
* is mapped to {@code null}), attempts to compute its value using |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
707 |
* the given mapping function and enters it into this map unless |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
708 |
* {@code null}. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
709 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
710 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
711 |
* method is called with the strings {@code "putProviderProperty."+name} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
712 |
* and {@code "removeProviderProperty."+name}, where {@code name} is the |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
713 |
* provider name, to see if it's ok to set this provider's property values |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
714 |
* and remove this provider's properties. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
715 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
716 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
717 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
718 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
719 |
* denies access to set property values and remove properties. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
720 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
721 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
722 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
723 |
@Override |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
724 |
public synchronized Object computeIfAbsent(Object key, Function<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
725 |
? extends Object> mappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
726 |
check("putProviderProperty." + name); |
40404
167b711cf138
8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents:
39759
diff
changeset
|
727 |
check("removeProviderProperty." + name); |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
728 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
729 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
730 |
debug.println("ComputeIfAbsent " + name + " provider property " + |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
731 |
key); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
732 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
733 |
return implComputeIfAbsent(key, mappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
734 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
735 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
736 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
737 |
* If the value for the specified key is present and non-null, attempts to |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
738 |
* compute a new mapping given the key and its current mapped value. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
739 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
740 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
741 |
* method is called with the strings {@code "putProviderProperty."+name} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
742 |
* and {@code "removeProviderProperty."+name}, where {@code name} is the |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
743 |
* provider name, to see if it's ok to set this provider's property values |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
744 |
* and remove this provider's properties. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
745 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
746 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
747 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
748 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
749 |
* denies access to set property values or remove properties. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
750 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
751 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
752 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
753 |
@Override |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
754 |
public synchronized Object computeIfPresent(Object key, BiFunction<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
755 |
? super Object, ? extends Object> remappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
756 |
check("putProviderProperty." + name); |
40404
167b711cf138
8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents:
39759
diff
changeset
|
757 |
check("removeProviderProperty." + name); |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
758 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
759 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
760 |
debug.println("ComputeIfPresent " + name + " provider property " + |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
761 |
key); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
762 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
763 |
return implComputeIfPresent(key, remappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
764 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
765 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
766 |
/** |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
767 |
* If the specified key is not already associated with a value or is |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
768 |
* associated with null, associates it with the given value. Otherwise, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
769 |
* replaces the value with the results of the given remapping function, |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
770 |
* or removes if the result is null. This method may be of use when |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
771 |
* combining multiple mapped values for a key. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
772 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
773 |
* <p>If a security manager is enabled, its {@code checkSecurityAccess} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
774 |
* method is called with the strings {@code "putProviderProperty."+name} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
775 |
* and {@code "removeProviderProperty."+name}, where {@code name} is the |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
776 |
* provider name, to see if it's ok to set this provider's property values |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
777 |
* and remove this provider's properties. |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
778 |
* |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
779 |
* @throws SecurityException |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
780 |
* if a security manager exists and its {@link |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
781 |
* java.lang.SecurityManager#checkSecurityAccess} method |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
782 |
* denies access to set property values or remove properties. |
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
783 |
* |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
784 |
* @since 1.8 |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
785 |
*/ |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
786 |
@Override |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
787 |
public synchronized Object merge(Object key, Object value, BiFunction<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
788 |
? super Object, ? extends Object> remappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
789 |
check("putProviderProperty." + name); |
40404
167b711cf138
8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents:
39759
diff
changeset
|
790 |
check("removeProviderProperty." + name); |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
791 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
792 |
if (debug != null) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
793 |
debug.println("Merge " + name + " provider property " + key); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
794 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
795 |
return implMerge(key, value, remappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
796 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
797 |
|
2 | 798 |
// let javadoc show doc from superclass |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
799 |
@Override |
2 | 800 |
public Object get(Object key) { |
801 |
checkInitialized(); |
|
802 |
return super.get(key); |
|
803 |
} |
|
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
804 |
/** |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
805 |
* @since 1.8 |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
806 |
*/ |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
807 |
@Override |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
808 |
public synchronized Object getOrDefault(Object key, Object defaultValue) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
809 |
checkInitialized(); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
810 |
return super.getOrDefault(key, defaultValue); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
811 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
812 |
|
21979
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
813 |
/** |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
814 |
* @since 1.8 |
3dcd1bc15edd
8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents:
21340
diff
changeset
|
815 |
*/ |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
816 |
@Override |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
817 |
public synchronized void forEach(BiConsumer<? super Object, ? super Object> action) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
818 |
checkInitialized(); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
819 |
super.forEach(action); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
820 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
821 |
|
2 | 822 |
// let javadoc show doc from superclass |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
823 |
@Override |
2 | 824 |
public Enumeration<Object> keys() { |
825 |
checkInitialized(); |
|
826 |
return super.keys(); |
|
827 |
} |
|
828 |
||
829 |
// let javadoc show doc from superclass |
|
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
830 |
@Override |
2 | 831 |
public Enumeration<Object> elements() { |
832 |
checkInitialized(); |
|
833 |
return super.elements(); |
|
834 |
} |
|
835 |
||
836 |
// let javadoc show doc from superclass |
|
837 |
public String getProperty(String key) { |
|
838 |
checkInitialized(); |
|
839 |
return super.getProperty(key); |
|
840 |
} |
|
841 |
||
842 |
private void checkInitialized() { |
|
843 |
if (!initialized) { |
|
844 |
throw new IllegalStateException(); |
|
845 |
} |
|
846 |
} |
|
847 |
||
848 |
private void check(String directive) { |
|
849 |
checkInitialized(); |
|
850 |
SecurityManager security = System.getSecurityManager(); |
|
851 |
if (security != null) { |
|
852 |
security.checkSecurityAccess(directive); |
|
853 |
} |
|
854 |
} |
|
855 |
||
856 |
// legacy properties changed since last call to any services method? |
|
857 |
private transient boolean legacyChanged; |
|
858 |
// serviceMap changed since last call to getServices() |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
859 |
private volatile transient boolean servicesChanged; |
2 | 860 |
|
861 |
// Map<ServiceKey,Service> |
|
862 |
// used for services added via putService(), initialized on demand |
|
863 |
private transient Map<ServiceKey,Service> serviceMap; |
|
864 |
||
865 |
// Map<ServiceKey,Service> |
|
866 |
// used for services added via legacy methods, init on demand |
|
867 |
private transient Map<ServiceKey,Service> legacyMap; |
|
868 |
||
869 |
// Set<Service> |
|
870 |
// Unmodifiable set of all services. Initialized on demand. |
|
871 |
private transient Set<Service> serviceSet; |
|
872 |
||
873 |
// register the id attributes for this provider |
|
874 |
// this is to ensure that equals() and hashCode() do not incorrectly |
|
875 |
// report to different provider objects as the same |
|
876 |
private void putId() { |
|
877 |
// note: name and info may be null |
|
878 |
super.put("Provider.id name", String.valueOf(name)); |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
879 |
super.put("Provider.id version", String.valueOf(versionStr)); |
2 | 880 |
super.put("Provider.id info", String.valueOf(info)); |
881 |
super.put("Provider.id className", this.getClass().getName()); |
|
882 |
} |
|
883 |
||
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
884 |
/** |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
885 |
* Reads the {@code ObjectInputStream} for the default serializable fields. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
886 |
* If the serialized field {@code versionStr} is found in the STREAM FIELDS, |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
887 |
* its String value will be used to populate both the version string and |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
888 |
* version number. If {@code versionStr} is not found, but {@code version} |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
889 |
* is, then its double value will be used to populate both fields. |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
890 |
* |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
891 |
* @param in the {@code ObjectInputStream} to read |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
892 |
* @serial |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
893 |
*/ |
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
52995
diff
changeset
|
894 |
@java.io.Serial |
2 | 895 |
private void readObject(ObjectInputStream in) |
896 |
throws IOException, ClassNotFoundException { |
|
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
897 |
Map<Object,Object> copy = new HashMap<>(); |
2 | 898 |
for (Map.Entry<Object,Object> entry : super.entrySet()) { |
899 |
copy.put(entry.getKey(), entry.getValue()); |
|
900 |
} |
|
901 |
defaults = null; |
|
902 |
in.defaultReadObject(); |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
903 |
if (this.versionStr == null) { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
904 |
// set versionStr based on version when not found in serialized bytes |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
905 |
this.versionStr = Double.toString(this.version); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
906 |
} else { |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
907 |
// otherwise, set version based on versionStr |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
908 |
this.version = parseVersionStr(this.versionStr); |
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
40404
diff
changeset
|
909 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
910 |
this.serviceMap = new ConcurrentHashMap<>(); |
2 | 911 |
implClear(); |
912 |
initialized = true; |
|
913 |
putAll(copy); |
|
914 |
} |
|
915 |
||
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
916 |
private static boolean isProviderInfo(Object key) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
917 |
String keyString = (String)key; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
918 |
if (keyString.startsWith("Provider.")) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
919 |
return true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
920 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
921 |
return false; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
922 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
923 |
|
2 | 924 |
/** |
925 |
* Copies all of the mappings from the specified Map to this provider. |
|
926 |
* Internal method to be called AFTER the security check has been |
|
927 |
* performed. |
|
928 |
*/ |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
929 |
private void implPutAll(Map<?,?> t) { |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
930 |
for (Map.Entry<?,?> e : t.entrySet()) { |
2 | 931 |
implPut(e.getKey(), e.getValue()); |
932 |
} |
|
933 |
} |
|
934 |
||
935 |
private Object implRemove(Object key) { |
|
936 |
if (key instanceof String) { |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
937 |
if (isProviderInfo(key)) { |
2 | 938 |
return null; |
939 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
940 |
legacyChanged = true; |
2 | 941 |
} |
942 |
return super.remove(key); |
|
943 |
} |
|
944 |
||
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
945 |
private boolean implRemove(Object key, Object value) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
946 |
if (key instanceof String && value instanceof String) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
947 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
948 |
return false; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
949 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
950 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
951 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
952 |
return super.remove(key, value); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
953 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
954 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
955 |
private boolean implReplace(Object key, Object oldValue, Object newValue) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
956 |
if ((key instanceof String) && (oldValue instanceof String) && |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
957 |
(newValue instanceof String)) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
958 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
959 |
return false; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
960 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
961 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
962 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
963 |
return super.replace(key, oldValue, newValue); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
964 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
965 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
966 |
private Object implReplace(Object key, Object value) { |
2 | 967 |
if ((key instanceof String) && (value instanceof String)) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
968 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
969 |
return null; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
970 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
971 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
972 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
973 |
return super.replace(key, value); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
974 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
975 |
|
23062
ece6b5d8a71b
8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents:
22117
diff
changeset
|
976 |
@SuppressWarnings("unchecked") // Function must actually operate over strings |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
977 |
private void implReplaceAll(BiFunction<? super Object, ? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
978 |
? extends Object> function) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
979 |
legacyChanged = true; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
980 |
super.replaceAll(function); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
981 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
982 |
|
23062
ece6b5d8a71b
8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents:
22117
diff
changeset
|
983 |
@SuppressWarnings("unchecked") // Function must actually operate over strings |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
984 |
private Object implMerge(Object key, Object value, BiFunction<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
985 |
? super Object, ? extends Object> remappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
986 |
if ((key instanceof String) && (value instanceof String)) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
987 |
if (isProviderInfo(key)) { |
2 | 988 |
return null; |
989 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
990 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
991 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
992 |
return super.merge(key, value, remappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
993 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
994 |
|
23062
ece6b5d8a71b
8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents:
22117
diff
changeset
|
995 |
@SuppressWarnings("unchecked") // Function must actually operate over strings |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
996 |
private Object implCompute(Object key, BiFunction<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
997 |
? super Object, ? extends Object> remappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
998 |
if (key instanceof String) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
999 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1000 |
return null; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1001 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1002 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1003 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1004 |
return super.compute(key, remappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1005 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1006 |
|
23062
ece6b5d8a71b
8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents:
22117
diff
changeset
|
1007 |
@SuppressWarnings("unchecked") // Function must actually operate over strings |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
1008 |
private Object implComputeIfAbsent(Object key, Function<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
1009 |
? extends Object> mappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1010 |
if (key instanceof String) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1011 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1012 |
return null; |
2 | 1013 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1014 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1015 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1016 |
return super.computeIfAbsent(key, mappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1017 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1018 |
|
23062
ece6b5d8a71b
8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents:
22117
diff
changeset
|
1019 |
@SuppressWarnings("unchecked") // Function must actually operate over strings |
38448
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
1020 |
private Object implComputeIfPresent(Object key, BiFunction<? super Object, |
1008868d499d
8155575: Provider.java contains very long lines because of lambda
snikandrova
parents:
37880
diff
changeset
|
1021 |
? super Object, ? extends Object> remappingFunction) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1022 |
if (key instanceof String) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1023 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1024 |
return null; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1025 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1026 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1027 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1028 |
return super.computeIfPresent(key, remappingFunction); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1029 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1030 |
|
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1031 |
private Object implPut(Object key, Object value) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1032 |
if ((key instanceof String) && (value instanceof String)) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1033 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1034 |
return null; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1035 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1036 |
legacyChanged = true; |
2 | 1037 |
} |
1038 |
return super.put(key, value); |
|
1039 |
} |
|
1040 |
||
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1041 |
private Object implPutIfAbsent(Object key, Object value) { |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1042 |
if ((key instanceof String) && (value instanceof String)) { |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1043 |
if (isProviderInfo(key)) { |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1044 |
return null; |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1045 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1046 |
legacyChanged = true; |
21340
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1047 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1048 |
return super.putIfAbsent(key, value); |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1049 |
} |
17142dadfffe
8025763: Provider does not override new Hashtable methods
ascarpino
parents:
18592
diff
changeset
|
1050 |
|
2 | 1051 |
private void implClear() { |
1052 |
if (legacyMap != null) { |
|
1053 |
legacyMap.clear(); |
|
1054 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1055 |
serviceMap.clear(); |
2 | 1056 |
legacyChanged = false; |
1057 |
servicesChanged = false; |
|
1058 |
serviceSet = null; |
|
1059 |
super.clear(); |
|
1060 |
putId(); |
|
1061 |
} |
|
1062 |
||
1063 |
// used as key in the serviceMap and legacyMap HashMaps |
|
1064 |
private static class ServiceKey { |
|
1065 |
private final String type; |
|
1066 |
private final String algorithm; |
|
1067 |
private final String originalAlgorithm; |
|
1068 |
private ServiceKey(String type, String algorithm, boolean intern) { |
|
1069 |
this.type = type; |
|
1070 |
this.originalAlgorithm = algorithm; |
|
1071 |
algorithm = algorithm.toUpperCase(ENGLISH); |
|
1072 |
this.algorithm = intern ? algorithm.intern() : algorithm; |
|
1073 |
} |
|
1074 |
public int hashCode() { |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1075 |
return Objects.hash(type, algorithm); |
2 | 1076 |
} |
1077 |
public boolean equals(Object obj) { |
|
1078 |
if (this == obj) { |
|
1079 |
return true; |
|
1080 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1081 |
if (!(obj instanceof ServiceKey)) { |
2 | 1082 |
return false; |
1083 |
} |
|
1084 |
ServiceKey other = (ServiceKey)obj; |
|
1085 |
return this.type.equals(other.type) |
|
1086 |
&& this.algorithm.equals(other.algorithm); |
|
1087 |
} |
|
1088 |
boolean matches(String type, String algorithm) { |
|
1089 |
return (this.type == type) && (this.originalAlgorithm == algorithm); |
|
1090 |
} |
|
1091 |
} |
|
1092 |
||
1093 |
/** |
|
1094 |
* Ensure all the legacy String properties are fully parsed into |
|
1095 |
* service objects. |
|
1096 |
*/ |
|
1097 |
private void ensureLegacyParsed() { |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1098 |
if (legacyChanged == false) { |
2 | 1099 |
return; |
1100 |
} |
|
1101 |
serviceSet = null; |
|
1102 |
if (legacyMap == null) { |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1103 |
legacyMap = new ConcurrentHashMap<>(); |
2 | 1104 |
} else { |
1105 |
legacyMap.clear(); |
|
1106 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1107 |
for (Map.Entry<?,?> entry : super.entrySet()) { |
2 | 1108 |
parseLegacyPut(entry.getKey(), entry.getValue()); |
1109 |
} |
|
1110 |
removeInvalidServices(legacyMap); |
|
1111 |
legacyChanged = false; |
|
1112 |
} |
|
1113 |
||
1114 |
/** |
|
1115 |
* Remove all invalid services from the Map. Invalid services can only |
|
1116 |
* occur if the legacy properties are inconsistent or incomplete. |
|
1117 |
*/ |
|
1118 |
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
|
1119 |
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
|
1120 |
map.entrySet().iterator(); t.hasNext(); ) { |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1121 |
Service s = t.next().getValue(); |
2 | 1122 |
if (s.isValid() == false) { |
1123 |
t.remove(); |
|
1124 |
} |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
1128 |
private String[] getTypeAndAlgorithm(String key) { |
|
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
23926
diff
changeset
|
1129 |
int i = key.indexOf('.'); |
2 | 1130 |
if (i < 1) { |
1131 |
if (debug != null) { |
|
1132 |
debug.println("Ignoring invalid entry in provider " |
|
1133 |
+ name + ":" + key); |
|
1134 |
} |
|
1135 |
return null; |
|
1136 |
} |
|
1137 |
String type = key.substring(0, i); |
|
1138 |
String alg = key.substring(i + 1); |
|
1139 |
return new String[] {type, alg}; |
|
1140 |
} |
|
1141 |
||
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
31270
diff
changeset
|
1142 |
private static final String ALIAS_PREFIX = "Alg.Alias."; |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
31270
diff
changeset
|
1143 |
private static final String ALIAS_PREFIX_LOWER = "alg.alias."; |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
31270
diff
changeset
|
1144 |
private static final int ALIAS_LENGTH = ALIAS_PREFIX.length(); |
2 | 1145 |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1146 |
private void parseLegacyPut(Object k, Object v) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1147 |
if (!(k instanceof String) || !(v instanceof String)) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1148 |
return; |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1149 |
} |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1150 |
String name = (String) k; |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1151 |
String value = (String) v; |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1152 |
if (isProviderInfo(name)) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1153 |
return; |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1154 |
} |
2 | 1155 |
if (name.toLowerCase(ENGLISH).startsWith(ALIAS_PREFIX_LOWER)) { |
1156 |
// e.g. put("Alg.Alias.MessageDigest.SHA", "SHA-1"); |
|
1157 |
// aliasKey ~ MessageDigest.SHA |
|
1158 |
String stdAlg = value; |
|
1159 |
String aliasKey = name.substring(ALIAS_LENGTH); |
|
1160 |
String[] typeAndAlg = getTypeAndAlgorithm(aliasKey); |
|
1161 |
if (typeAndAlg == null) { |
|
1162 |
return; |
|
1163 |
} |
|
1164 |
String type = getEngineName(typeAndAlg[0]); |
|
1165 |
String aliasAlg = typeAndAlg[1].intern(); |
|
1166 |
ServiceKey key = new ServiceKey(type, stdAlg, true); |
|
1167 |
Service s = legacyMap.get(key); |
|
1168 |
if (s == null) { |
|
1169 |
s = new Service(this); |
|
1170 |
s.type = type; |
|
1171 |
s.algorithm = stdAlg; |
|
1172 |
legacyMap.put(key, s); |
|
1173 |
} |
|
1174 |
legacyMap.put(new ServiceKey(type, aliasAlg, true), s); |
|
1175 |
s.addAlias(aliasAlg); |
|
1176 |
} else { |
|
1177 |
String[] typeAndAlg = getTypeAndAlgorithm(name); |
|
1178 |
if (typeAndAlg == null) { |
|
1179 |
return; |
|
1180 |
} |
|
1181 |
int i = typeAndAlg[1].indexOf(' '); |
|
1182 |
if (i == -1) { |
|
1183 |
// e.g. put("MessageDigest.SHA-1", "sun.security.provider.SHA"); |
|
1184 |
String type = getEngineName(typeAndAlg[0]); |
|
1185 |
String stdAlg = typeAndAlg[1].intern(); |
|
1186 |
String className = value; |
|
1187 |
ServiceKey key = new ServiceKey(type, stdAlg, true); |
|
1188 |
Service s = legacyMap.get(key); |
|
1189 |
if (s == null) { |
|
1190 |
s = new Service(this); |
|
1191 |
s.type = type; |
|
1192 |
s.algorithm = stdAlg; |
|
1193 |
legacyMap.put(key, s); |
|
1194 |
} |
|
1195 |
s.className = className; |
|
1196 |
} else { // attribute |
|
1197 |
// e.g. put("MessageDigest.SHA-1 ImplementedIn", "Software"); |
|
1198 |
String attributeValue = value; |
|
1199 |
String type = getEngineName(typeAndAlg[0]); |
|
1200 |
String attributeString = typeAndAlg[1]; |
|
1201 |
String stdAlg = attributeString.substring(0, i).intern(); |
|
1202 |
String attributeName = attributeString.substring(i + 1); |
|
1203 |
// kill additional spaces |
|
1204 |
while (attributeName.startsWith(" ")) { |
|
1205 |
attributeName = attributeName.substring(1); |
|
1206 |
} |
|
1207 |
attributeName = attributeName.intern(); |
|
1208 |
ServiceKey key = new ServiceKey(type, stdAlg, true); |
|
1209 |
Service s = legacyMap.get(key); |
|
1210 |
if (s == null) { |
|
1211 |
s = new Service(this); |
|
1212 |
s.type = type; |
|
1213 |
s.algorithm = stdAlg; |
|
1214 |
legacyMap.put(key, s); |
|
1215 |
} |
|
1216 |
s.addAttribute(attributeName, attributeValue); |
|
1217 |
} |
|
1218 |
} |
|
1219 |
} |
|
1220 |
||
1221 |
/** |
|
1222 |
* Get the service describing this Provider's implementation of the |
|
1223 |
* specified type of this algorithm or alias. If no such |
|
1224 |
* implementation exists, this method returns null. If there are two |
|
1225 |
* matching services, one added to this provider using |
|
1226 |
* {@link #putService putService()} and one added via {@link #put put()}, |
|
1227 |
* the service added via {@link #putService putService()} is returned. |
|
1228 |
* |
|
1229 |
* @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
|
1230 |
* (for example, {@code MessageDigest}) |
2 | 1231 |
* @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
|
1232 |
* alias) of the service requested (for example, {@code SHA-1}) |
2 | 1233 |
* |
1234 |
* @return the service describing this Provider's matching service |
|
1235 |
* or null if no such service exists |
|
1236 |
* |
|
1237 |
* @throws NullPointerException if type or algorithm is null |
|
1238 |
* |
|
1239 |
* @since 1.5 |
|
1240 |
*/ |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1241 |
public Service getService(String type, String algorithm) { |
2 | 1242 |
checkInitialized(); |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1243 |
|
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1244 |
// avoid allocating a new ServiceKey object if possible |
2 | 1245 |
ServiceKey key = previousKey; |
1246 |
if (key.matches(type, algorithm) == false) { |
|
1247 |
key = new ServiceKey(type, algorithm, false); |
|
1248 |
previousKey = key; |
|
1249 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1250 |
if (!serviceMap.isEmpty()) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1251 |
Service s = serviceMap.get(key); |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1252 |
if (s != null) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1253 |
return s; |
2 | 1254 |
} |
1255 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1256 |
synchronized (this) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1257 |
ensureLegacyParsed(); |
58337
270abce77942
8231387: java.security.Provider.getService returns random result due to race condition with mutating methods in the same class
phh
parents:
58242
diff
changeset
|
1258 |
if (legacyMap != null && !legacyMap.isEmpty()) { |
270abce77942
8231387: java.security.Provider.getService returns random result due to race condition with mutating methods in the same class
phh
parents:
58242
diff
changeset
|
1259 |
return legacyMap.get(key); |
270abce77942
8231387: java.security.Provider.getService returns random result due to race condition with mutating methods in the same class
phh
parents:
58242
diff
changeset
|
1260 |
} |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1261 |
} |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1262 |
return null; |
2 | 1263 |
} |
1264 |
||
1265 |
// ServiceKey from previous getService() call |
|
1266 |
// by re-using it if possible we avoid allocating a new object |
|
1267 |
// and the toUpperCase() call. |
|
1268 |
// re-use will occur e.g. as the framework traverses the provider |
|
1269 |
// list and queries each provider with the same values until it finds |
|
1270 |
// a matching service |
|
1271 |
private static volatile ServiceKey previousKey = |
|
1272 |
new ServiceKey("", "", false); |
|
1273 |
||
1274 |
/** |
|
1275 |
* Get an unmodifiable Set of all services supported by |
|
1276 |
* this Provider. |
|
1277 |
* |
|
1278 |
* @return an unmodifiable Set of all services supported by |
|
1279 |
* this Provider |
|
1280 |
* |
|
1281 |
* @since 1.5 |
|
1282 |
*/ |
|
1283 |
public synchronized Set<Service> getServices() { |
|
1284 |
checkInitialized(); |
|
1285 |
if (legacyChanged || servicesChanged) { |
|
1286 |
serviceSet = null; |
|
1287 |
} |
|
1288 |
if (serviceSet == null) { |
|
1289 |
ensureLegacyParsed(); |
|
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
1290 |
Set<Service> set = new LinkedHashSet<>(); |
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1291 |
if (!serviceMap.isEmpty()) { |
2 | 1292 |
set.addAll(serviceMap.values()); |
1293 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1294 |
if (legacyMap != null && !legacyMap.isEmpty()) { |
2 | 1295 |
set.addAll(legacyMap.values()); |
1296 |
} |
|
1297 |
serviceSet = Collections.unmodifiableSet(set); |
|
1298 |
servicesChanged = false; |
|
1299 |
} |
|
1300 |
return serviceSet; |
|
1301 |
} |
|
1302 |
||
1303 |
/** |
|
1304 |
* Add a service. If a service of the same type with the same algorithm |
|
1305 |
* name exists and it was added using {@link #putService putService()}, |
|
1306 |
* it is replaced by the new service. |
|
1307 |
* This method also places information about this service |
|
1308 |
* in the provider's Hashtable values in the format described in the |
|
45665 | 1309 |
* {@extLink security_guide_jca |
1310 |
* Java Cryptography Architecture (JCA) Reference Guide}. |
|
2 | 1311 |
* |
1312 |
* <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
|
1313 |
* {@code checkSecurityAccess} method is called with the string |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1314 |
* {@code "putProviderProperty."+name}, where {@code name} is |
2 | 1315 |
* 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
|
1316 |
* values. If the default implementation of {@code checkSecurityAccess} |
51759
ac6e9a2ebc04
8210786: Typo s/overriden/overridden/ in several places
igerasim
parents:
47216
diff
changeset
|
1317 |
* is used (that is, that method is not overridden), then this results in |
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1318 |
* 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
|
1319 |
* a {@code SecurityPermission("putProviderProperty."+name)} |
2 | 1320 |
* permission. |
1321 |
* |
|
1322 |
* @param s the Service to add |
|
1323 |
* |
|
1324 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1325 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1326 |
* java.lang.SecurityManager#checkSecurityAccess} method denies |
2 | 1327 |
* access to set property values. |
1328 |
* @throws NullPointerException if s is null |
|
1329 |
* |
|
1330 |
* @since 1.5 |
|
1331 |
*/ |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1332 |
protected void putService(Service s) { |
2 | 1333 |
check("putProviderProperty." + name); |
1334 |
if (debug != null) { |
|
1335 |
debug.println(name + ".putService(): " + s); |
|
1336 |
} |
|
1337 |
if (s == null) { |
|
1338 |
throw new NullPointerException(); |
|
1339 |
} |
|
1340 |
if (s.getProvider() != this) { |
|
1341 |
throw new IllegalArgumentException |
|
1342 |
("service.getProvider() must match this Provider object"); |
|
1343 |
} |
|
1344 |
String type = s.getType(); |
|
1345 |
String algorithm = s.getAlgorithm(); |
|
1346 |
ServiceKey key = new ServiceKey(type, algorithm, true); |
|
1347 |
implRemoveService(serviceMap.get(key)); |
|
1348 |
serviceMap.put(key, s); |
|
1349 |
for (String alias : s.getAliases()) { |
|
1350 |
serviceMap.put(new ServiceKey(type, alias, true), s); |
|
1351 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1352 |
servicesChanged = true; |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1353 |
synchronized (this) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1354 |
putPropertyStrings(s); |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1355 |
} |
2 | 1356 |
} |
1357 |
||
1358 |
/** |
|
1359 |
* Put the string properties for this Service in this Provider's |
|
1360 |
* Hashtable. |
|
1361 |
*/ |
|
1362 |
private void putPropertyStrings(Service s) { |
|
1363 |
String type = s.getType(); |
|
1364 |
String algorithm = s.getAlgorithm(); |
|
1365 |
// use super() to avoid permission check and other processing |
|
1366 |
super.put(type + "." + algorithm, s.getClassName()); |
|
1367 |
for (String alias : s.getAliases()) { |
|
1368 |
super.put(ALIAS_PREFIX + type + "." + alias, algorithm); |
|
1369 |
} |
|
1370 |
for (Map.Entry<UString,String> entry : s.attributes.entrySet()) { |
|
1371 |
String key = type + "." + algorithm + " " + entry.getKey(); |
|
1372 |
super.put(key, entry.getValue()); |
|
1373 |
} |
|
1374 |
} |
|
1375 |
||
1376 |
/** |
|
1377 |
* Remove the string properties for this Service from this Provider's |
|
1378 |
* Hashtable. |
|
1379 |
*/ |
|
1380 |
private void removePropertyStrings(Service s) { |
|
1381 |
String type = s.getType(); |
|
1382 |
String algorithm = s.getAlgorithm(); |
|
1383 |
// use super() to avoid permission check and other processing |
|
1384 |
super.remove(type + "." + algorithm); |
|
1385 |
for (String alias : s.getAliases()) { |
|
1386 |
super.remove(ALIAS_PREFIX + type + "." + alias); |
|
1387 |
} |
|
1388 |
for (Map.Entry<UString,String> entry : s.attributes.entrySet()) { |
|
1389 |
String key = type + "." + algorithm + " " + entry.getKey(); |
|
1390 |
super.remove(key); |
|
1391 |
} |
|
1392 |
} |
|
1393 |
||
1394 |
/** |
|
1395 |
* Remove a service previously added using |
|
1396 |
* {@link #putService putService()}. The specified service is removed from |
|
1397 |
* this provider. It will no longer be returned by |
|
1398 |
* {@link #getService getService()} and its information will be removed |
|
1399 |
* from this provider's Hashtable. |
|
1400 |
* |
|
1401 |
* <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
|
1402 |
* {@code checkSecurityAccess} method is called with the string |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1403 |
* {@code "removeProviderProperty."+name}, where {@code name} is |
2 | 1404 |
* the provider name, to see if it's ok to remove this provider's |
1405 |
* properties. If the default implementation of |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1406 |
* {@code checkSecurityAccess} is used (that is, that method is not |
51759
ac6e9a2ebc04
8210786: Typo s/overriden/overridden/ in several places
igerasim
parents:
47216
diff
changeset
|
1407 |
* overridden), 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
|
1408 |
* {@code checkPermission} method with a |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1409 |
* {@code SecurityPermission("removeProviderProperty."+name)} |
2 | 1410 |
* permission. |
1411 |
* |
|
1412 |
* @param s the Service to be removed |
|
1413 |
* |
|
1414 |
* @throws SecurityException |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1415 |
* if a security manager exists and its {@link |
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1416 |
* java.lang.SecurityManager#checkSecurityAccess} method denies |
2 | 1417 |
* access to remove this provider's properties. |
1418 |
* @throws NullPointerException if s is null |
|
1419 |
* |
|
1420 |
* @since 1.5 |
|
1421 |
*/ |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1422 |
protected void removeService(Service s) { |
2 | 1423 |
check("removeProviderProperty." + name); |
1424 |
if (debug != null) { |
|
1425 |
debug.println(name + ".removeService(): " + s); |
|
1426 |
} |
|
1427 |
if (s == null) { |
|
1428 |
throw new NullPointerException(); |
|
1429 |
} |
|
1430 |
implRemoveService(s); |
|
1431 |
} |
|
1432 |
||
1433 |
private void implRemoveService(Service s) { |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1434 |
if ((s == null) || serviceMap.isEmpty()) { |
2 | 1435 |
return; |
1436 |
} |
|
1437 |
String type = s.getType(); |
|
1438 |
String algorithm = s.getAlgorithm(); |
|
1439 |
ServiceKey key = new ServiceKey(type, algorithm, false); |
|
1440 |
Service oldService = serviceMap.get(key); |
|
1441 |
if (s != oldService) { |
|
1442 |
return; |
|
1443 |
} |
|
1444 |
servicesChanged = true; |
|
1445 |
serviceMap.remove(key); |
|
1446 |
for (String alias : s.getAliases()) { |
|
1447 |
serviceMap.remove(new ServiceKey(type, alias, false)); |
|
1448 |
} |
|
52995
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1449 |
synchronized (this) { |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1450 |
removePropertyStrings(s); |
9af672cab7cb
7092821: java.security.Provider.getService() is synchronized and became scalability bottleneck
valeriep
parents:
51759
diff
changeset
|
1451 |
} |
2 | 1452 |
} |
1453 |
||
1454 |
// Wrapped String that behaves in a case insensitive way for equals/hashCode |
|
1455 |
private static class UString { |
|
1456 |
final String string; |
|
1457 |
final String lowerString; |
|
1458 |
||
1459 |
UString(String s) { |
|
1460 |
this.string = s; |
|
1461 |
this.lowerString = s.toLowerCase(ENGLISH); |
|
1462 |
} |
|
1463 |
||
1464 |
public int hashCode() { |
|
1465 |
return lowerString.hashCode(); |
|
1466 |
} |
|
1467 |
||
1468 |
public boolean equals(Object obj) { |
|
1469 |
if (this == obj) { |
|
1470 |
return true; |
|
1471 |
} |
|
1472 |
if (obj instanceof UString == false) { |
|
1473 |
return false; |
|
1474 |
} |
|
1475 |
UString other = (UString)obj; |
|
1476 |
return lowerString.equals(other.lowerString); |
|
1477 |
} |
|
1478 |
||
1479 |
public String toString() { |
|
1480 |
return string; |
|
1481 |
} |
|
1482 |
} |
|
1483 |
||
1484 |
// describe relevant properties of a type of engine |
|
1485 |
private static class EngineDescription { |
|
1486 |
final String name; |
|
1487 |
final boolean supportsParameter; |
|
1488 |
final String constructorParameterClassName; |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1489 |
private volatile Class<?> constructorParameterClass; |
2 | 1490 |
|
1491 |
EngineDescription(String name, boolean sp, String paramName) { |
|
1492 |
this.name = name; |
|
1493 |
this.supportsParameter = sp; |
|
1494 |
this.constructorParameterClassName = paramName; |
|
1495 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1496 |
Class<?> getConstructorParameterClass() throws ClassNotFoundException { |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1497 |
Class<?> clazz = constructorParameterClass; |
2 | 1498 |
if (clazz == null) { |
1499 |
clazz = Class.forName(constructorParameterClassName); |
|
1500 |
constructorParameterClass = clazz; |
|
1501 |
} |
|
1502 |
return clazz; |
|
1503 |
} |
|
1504 |
} |
|
1505 |
||
1506 |
// built in knowledge of the engine types shipped as part of the JDK |
|
1507 |
private static final Map<String,EngineDescription> knownEngines; |
|
1508 |
||
1509 |
private static void addEngine(String name, boolean sp, String paramName) { |
|
1510 |
EngineDescription ed = new EngineDescription(name, sp, paramName); |
|
1511 |
// also index by canonical name to avoid toLowerCase() for some lookups |
|
1512 |
knownEngines.put(name.toLowerCase(ENGLISH), ed); |
|
1513 |
knownEngines.put(name, ed); |
|
1514 |
} |
|
1515 |
||
1516 |
static { |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
28059
diff
changeset
|
1517 |
knownEngines = new HashMap<>(); |
2 | 1518 |
// JCA |
1519 |
addEngine("AlgorithmParameterGenerator", false, null); |
|
1520 |
addEngine("AlgorithmParameters", false, null); |
|
1521 |
addEngine("KeyFactory", false, null); |
|
1522 |
addEngine("KeyPairGenerator", false, null); |
|
1523 |
addEngine("KeyStore", false, null); |
|
1524 |
addEngine("MessageDigest", false, null); |
|
37796
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
1525 |
addEngine("SecureRandom", false, |
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
1526 |
"java.security.SecureRandomParameters"); |
2 | 1527 |
addEngine("Signature", true, null); |
1528 |
addEngine("CertificateFactory", false, null); |
|
1529 |
addEngine("CertPathBuilder", false, null); |
|
1530 |
addEngine("CertPathValidator", false, null); |
|
1531 |
addEngine("CertStore", false, |
|
1532 |
"java.security.cert.CertStoreParameters"); |
|
1533 |
// JCE |
|
1534 |
addEngine("Cipher", true, null); |
|
1535 |
addEngine("ExemptionMechanism", false, null); |
|
1536 |
addEngine("Mac", true, null); |
|
1537 |
addEngine("KeyAgreement", true, null); |
|
1538 |
addEngine("KeyGenerator", false, null); |
|
1539 |
addEngine("SecretKeyFactory", false, null); |
|
1540 |
// JSSE |
|
1541 |
addEngine("KeyManagerFactory", false, null); |
|
1542 |
addEngine("SSLContext", false, null); |
|
1543 |
addEngine("TrustManagerFactory", false, null); |
|
1544 |
// JGSS |
|
23926
ebade3f50c1f
8039853: Provider.Service.newInstance() does not work with current JDK JGSS Mechanisms
weijun
parents:
23735
diff
changeset
|
1545 |
addEngine("GssApiMechanism", false, null); |
2 | 1546 |
// SASL |
1547 |
addEngine("SaslClientFactory", false, null); |
|
1548 |
addEngine("SaslServerFactory", false, null); |
|
1549 |
// POLICY |
|
1550 |
addEngine("Policy", false, |
|
1551 |
"java.security.Policy$Parameters"); |
|
1552 |
// CONFIGURATION |
|
1553 |
addEngine("Configuration", false, |
|
1554 |
"javax.security.auth.login.Configuration$Parameters"); |
|
1555 |
// XML DSig |
|
1556 |
addEngine("XMLSignatureFactory", false, null); |
|
1557 |
addEngine("KeyInfoFactory", false, null); |
|
1558 |
addEngine("TransformService", false, null); |
|
1559 |
// Smart Card I/O |
|
1560 |
addEngine("TerminalFactory", false, |
|
1561 |
"java.lang.Object"); |
|
1562 |
} |
|
1563 |
||
1564 |
// get the "standard" (mixed-case) engine name for arbitary case engine name |
|
1565 |
// if there is no known engine by that name, return s |
|
1566 |
private static String getEngineName(String s) { |
|
1567 |
// try original case first, usually correct |
|
1568 |
EngineDescription e = knownEngines.get(s); |
|
1569 |
if (e == null) { |
|
1570 |
e = knownEngines.get(s.toLowerCase(ENGLISH)); |
|
1571 |
} |
|
1572 |
return (e == null) ? s : e.name; |
|
1573 |
} |
|
1574 |
||
1575 |
/** |
|
1576 |
* The description of a security service. It encapsulates the properties |
|
1577 |
* of a service and contains a factory method to obtain new implementation |
|
1578 |
* instances of this service. |
|
1579 |
* |
|
1580 |
* <p>Each service has a provider that offers the service, a type, |
|
1581 |
* an algorithm name, and the name of the class that implements the |
|
1582 |
* service. Optionally, it also includes a list of alternate algorithm |
|
1583 |
* names for this service (aliases) and attributes, which are a map of |
|
1584 |
* (name, value) String pairs. |
|
1585 |
* |
|
1586 |
* <p>This class defines the methods {@link #supportsParameter |
|
1587 |
* supportsParameter()} and {@link #newInstance newInstance()} |
|
1588 |
* which are used by the Java security framework when it searches for |
|
25542 | 1589 |
* suitable services and instantiates them. The valid arguments to those |
2 | 1590 |
* methods depend on the type of service. For the service types defined |
1591 |
* within Java SE, see the |
|
45665 | 1592 |
* {@extLink security_guide_jca |
1593 |
* Java Cryptography Architecture (JCA) Reference Guide} |
|
2 | 1594 |
* for the valid values. |
1595 |
* Note that components outside of Java SE can define additional types of |
|
1596 |
* services and their behavior. |
|
1597 |
* |
|
1598 |
* <p>Instances of this class are immutable. |
|
1599 |
* |
|
1600 |
* @since 1.5 |
|
1601 |
*/ |
|
1602 |
public static class Service { |
|
1603 |
||
1604 |
private String type, algorithm, className; |
|
1605 |
private final Provider provider; |
|
1606 |
private List<String> aliases; |
|
1607 |
private Map<UString,String> attributes; |
|
1608 |
||
1609 |
// 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
|
1610 |
private volatile Reference<Class<?>> classRef; |
2 | 1611 |
|
1612 |
// flag indicating whether this service has its attributes for |
|
1613 |
// supportedKeyFormats or supportedKeyClasses set |
|
1614 |
// if null, the values have not been initialized |
|
1615 |
// if TRUE, at least one of supportedFormats/Classes is non null |
|
1616 |
private volatile Boolean hasKeyAttributes; |
|
1617 |
||
1618 |
// supported encoding formats |
|
1619 |
private String[] supportedFormats; |
|
1620 |
||
1621 |
// names of the supported key (super) classes |
|
22117
1efafbb25acb
8031302: Fix raw types lint warnings in java.security
darcy
parents:
21979
diff
changeset
|
1622 |
private Class<?>[] supportedClasses; |
2 | 1623 |
|
1624 |
// whether this service has been registered with the Provider |
|
1625 |
private boolean registered; |
|
1626 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1627 |
private static final Class<?>[] CLASS0 = new Class<?>[0]; |
2 | 1628 |
|
1629 |
// this constructor and these methods are used for parsing |
|
1630 |
// the legacy string properties. |
|
1631 |
||
1632 |
private Service(Provider provider) { |
|
1633 |
this.provider = provider; |
|
1634 |
aliases = Collections.<String>emptyList(); |
|
1635 |
attributes = Collections.<UString,String>emptyMap(); |
|
1636 |
} |
|
1637 |
||
1638 |
private boolean isValid() { |
|
1639 |
return (type != null) && (algorithm != null) && (className != null); |
|
1640 |
} |
|
1641 |
||
1642 |
private void addAlias(String alias) { |
|
1643 |
if (aliases.isEmpty()) { |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
28059
diff
changeset
|
1644 |
aliases = new ArrayList<>(2); |
2 | 1645 |
} |
1646 |
aliases.add(alias); |
|
1647 |
} |
|
1648 |
||
1649 |
void addAttribute(String type, String value) { |
|
1650 |
if (attributes.isEmpty()) { |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
28059
diff
changeset
|
1651 |
attributes = new HashMap<>(8); |
2 | 1652 |
} |
1653 |
attributes.put(new UString(type), value); |
|
1654 |
} |
|
1655 |
||
1656 |
/** |
|
1657 |
* Construct a new service. |
|
1658 |
* |
|
1659 |
* @param provider the provider that offers this service |
|
1660 |
* @param type the type of this service |
|
1661 |
* @param algorithm the algorithm name |
|
1662 |
* @param className the name of the class implementing this service |
|
1663 |
* @param aliases List of aliases or null if algorithm has no aliases |
|
1664 |
* @param attributes Map of attributes or null if this implementation |
|
1665 |
* has no attributes |
|
1666 |
* |
|
1667 |
* @throws NullPointerException if provider, type, algorithm, or |
|
1668 |
* className is null |
|
1669 |
*/ |
|
1670 |
public Service(Provider provider, String type, String algorithm, |
|
1671 |
String className, List<String> aliases, |
|
1672 |
Map<String,String> attributes) { |
|
1673 |
if ((provider == null) || (type == null) || |
|
1674 |
(algorithm == null) || (className == null)) { |
|
1675 |
throw new NullPointerException(); |
|
1676 |
} |
|
1677 |
this.provider = provider; |
|
1678 |
this.type = getEngineName(type); |
|
1679 |
this.algorithm = algorithm; |
|
1680 |
this.className = className; |
|
1681 |
if (aliases == null) { |
|
1682 |
this.aliases = Collections.<String>emptyList(); |
|
1683 |
} else { |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
28059
diff
changeset
|
1684 |
this.aliases = new ArrayList<>(aliases); |
2 | 1685 |
} |
1686 |
if (attributes == null) { |
|
1687 |
this.attributes = Collections.<UString,String>emptyMap(); |
|
1688 |
} else { |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
28059
diff
changeset
|
1689 |
this.attributes = new HashMap<>(); |
2 | 1690 |
for (Map.Entry<String,String> entry : attributes.entrySet()) { |
1691 |
this.attributes.put(new UString(entry.getKey()), entry.getValue()); |
|
1692 |
} |
|
1693 |
} |
|
1694 |
} |
|
1695 |
||
1696 |
/** |
|
18579
b678846778ad
8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents:
10336
diff
changeset
|
1697 |
* Get the type of this service. For example, {@code MessageDigest}. |
2 | 1698 |
* |
1699 |
* @return the type of this service |
|
1700 |
*/ |
|
1701 |
public final String getType() { |
|
1702 |
return type; |
|
1703 |
} |
|
1704 |
||
1705 |
/** |
|
1706 |
* 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
|
1707 |
* {@code SHA-1}. |
2 | 1708 |
* |
1709 |
* @return the algorithm of this service |
|
1710 |
*/ |
|
1711 |
public final String getAlgorithm() { |
|
1712 |
return algorithm; |
|
1713 |
} |
|
1714 |
||
1715 |
/** |
|
1716 |
* Return the Provider of this service. |
|
1717 |
* |
|
1718 |
* @return the Provider of this service |
|
1719 |
*/ |
|
1720 |
public final Provider getProvider() { |
|
1721 |
return provider; |
|
1722 |
} |
|
1723 |
||
1724 |
/** |
|
1725 |
* Return the name of the class implementing this service. |
|
1726 |
* |
|
1727 |
* @return the name of the class implementing this service |
|
1728 |
*/ |
|
1729 |
public final String getClassName() { |
|
1730 |
return className; |
|
1731 |
} |
|
1732 |
||
1733 |
// internal only |
|
1734 |
private final List<String> getAliases() { |
|
1735 |
return aliases; |
|
1736 |
} |
|
1737 |
||
1738 |
/** |
|
1739 |
* Return the value of the specified attribute or null if this |
|
1740 |
* attribute is not set for this Service. |
|
1741 |
* |
|
1742 |
* @param name the name of the requested attribute |
|
1743 |
* |
|
1744 |
* @return the value of the specified attribute or null if the |
|
1745 |
* attribute is not present |
|
1746 |
* |
|
1747 |
* @throws NullPointerException if name is null |
|
1748 |
*/ |
|
1749 |
public final String getAttribute(String name) { |
|
1750 |
if (name == null) { |
|
1751 |
throw new NullPointerException(); |
|
1752 |
} |
|
1753 |
return attributes.get(new UString(name)); |
|
1754 |
} |
|
1755 |
||
1756 |
/** |
|
1757 |
* Return a new instance of the implementation described by this |
|
1758 |
* service. The security provider framework uses this method to |
|
1759 |
* construct implementations. Applications will typically not need |
|
1760 |
* to call it. |
|
1761 |
* |
|
1762 |
* <p>The default implementation uses reflection to invoke the |
|
1763 |
* standard constructor for this type of service. |
|
1764 |
* Security providers can override this method to implement |
|
1765 |
* instantiation in a different way. |
|
1766 |
* For details and the values of constructorParameter that are |
|
1767 |
* valid for the various types of services see the |
|
45665 | 1768 |
* {@extLink security_guide_jca |
1769 |
* Java Cryptography Architecture (JCA) Reference Guide}. |
|
2 | 1770 |
* |
1771 |
* @param constructorParameter the value to pass to the constructor, |
|
1772 |
* or null if this type of service does not use a constructorParameter. |
|
1773 |
* |
|
1774 |
* @return a new implementation of this service |
|
1775 |
* |
|
1776 |
* @throws InvalidParameterException if the value of |
|
1777 |
* constructorParameter is invalid for this type of service. |
|
25542 | 1778 |
* @throws NoSuchAlgorithmException if instantiation failed for |
2 | 1779 |
* any other reason. |
1780 |
*/ |
|
1781 |
public Object newInstance(Object constructorParameter) |
|
1782 |
throws NoSuchAlgorithmException { |
|
1783 |
if (registered == false) { |
|
1784 |
if (provider.getService(type, algorithm) != this) { |
|
1785 |
throw new NoSuchAlgorithmException |
|
1786 |
("Service not registered with Provider " |
|
1787 |
+ provider.getName() + ": " + this); |
|
1788 |
} |
|
1789 |
registered = true; |
|
1790 |
} |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1791 |
Class<?> ctrParamClz; |
2 | 1792 |
try { |
1793 |
EngineDescription cap = knownEngines.get(type); |
|
1794 |
if (cap == null) { |
|
1795 |
// unknown engine type, use generic code |
|
1796 |
// this is the code path future for non-core |
|
1797 |
// optional packages |
|
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1798 |
ctrParamClz = constructorParameter == null? |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1799 |
null : constructorParameter.getClass(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1800 |
} else { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1801 |
ctrParamClz = cap.constructorParameterClassName == null? |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1802 |
null : Class.forName(cap.constructorParameterClassName); |
2 | 1803 |
if (constructorParameter != null) { |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1804 |
if (ctrParamClz == null) { |
2 | 1805 |
throw new InvalidParameterException |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1806 |
("constructorParameter not used with " + type |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1807 |
+ " engines"); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1808 |
} else { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1809 |
Class<?> argClass = constructorParameter.getClass(); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1810 |
if (ctrParamClz.isAssignableFrom(argClass) == false) { |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1811 |
throw new InvalidParameterException |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1812 |
("constructorParameter must be instanceof " |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1813 |
+ cap.constructorParameterClassName.replace('$', '.') |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1814 |
+ " for engine type " + type); |
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1815 |
} |
2 | 1816 |
} |
1817 |
} |
|
1818 |
} |
|
37796
256c45c4af5d
8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents:
32931
diff
changeset
|
1819 |
// constructorParameter can be null if not provided |
31270
e6470b24700d
7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
30033
diff
changeset
|
1820 |
return newInstanceUtil(getImplClass(), ctrParamClz, constructorParameter); |
2 | 1821 |
} catch (NoSuchAlgorithmException e) { |
1822 |
throw e; |
|
1823 |
} catch (InvocationTargetException e) { |
|
1824 |
throw new NoSuchAlgorithmException |
|
1825 |
("Error constructing implementation (algorithm: " |
|
1826 |
+ algorithm + ", provider: " + provider.getName() |
|
1827 |
+ ", class: " + className + ")", e.getCause()); |
|
1828 |
} catch (Exception e) { |
|
1829 |
throw new NoSuchAlgorithmException |
|
1830 |
("Error constructing implementation (algorithm: " |
|
1831 |
+ algorithm + ", provider: " + provider.getName() |
|
1832 |
+ ", class: " + className + ")", e); |
|
1833 |
} |
|
1834 |
} |
|
1835 |
||
1836 |
// 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
|
1837 |
private Class<?> getImplClass() throws NoSuchAlgorithmException { |
2 | 1838 |
try { |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1839 |
Reference<Class<?>> ref = classRef; |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1840 |
Class<?> clazz = (ref == null) ? null : ref.get(); |
2 | 1841 |
if (clazz == null) { |
1842 |
ClassLoader cl = provider.getClass().getClassLoader(); |
|
1843 |
if (cl == null) { |
|
1844 |
clazz = Class.forName(className); |
|
1845 |
} else { |
|
1846 |
clazz = cl.loadClass(className); |
|
1847 |
} |
|
25542 | 1848 |
if (!Modifier.isPublic(clazz.getModifiers())) { |
1849 |
throw new NoSuchAlgorithmException |
|
1850 |
("class configured for " + type + " (provider: " + |
|
1851 |
provider.getName() + ") is not public."); |
|
1852 |
} |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
28059
diff
changeset
|
1853 |
classRef = new WeakReference<>(clazz); |
2 | 1854 |
} |
1855 |
return clazz; |
|
1856 |
} catch (ClassNotFoundException e) { |
|
1857 |
throw new NoSuchAlgorithmException |
|
25542 | 1858 |
("class configured for " + type + " (provider: " + |
1859 |
provider.getName() + ") cannot be found.", e); |
|
2 | 1860 |
} |
1861 |
} |
|
1862 |
||
1863 |
/** |
|
1864 |
* Test whether this Service can use the specified parameter. |
|
1865 |
* Returns false if this service cannot use the parameter. Returns |
|
1866 |
* true if this service can use the parameter, if a fast test is |
|
1867 |
* infeasible, or if the status is unknown. |
|
1868 |
* |
|
1869 |
* <p>The security provider framework uses this method with |
|
1870 |
* some types of services to quickly exclude non-matching |
|
1871 |
* implementations for consideration. |
|
1872 |
* Applications will typically not need to call it. |
|
1873 |
* |
|
1874 |
* <p>For details and the values of parameter that are valid for the |
|
1875 |
* various types of services see the top of this class and the |
|
45665 | 1876 |
* {@extLink security_guide_jca |
1877 |
* Java Cryptography Architecture (JCA) Reference Guide}. |
|
2 | 1878 |
* Security providers can override it to implement their own test. |
1879 |
* |
|
1880 |
* @param parameter the parameter to test |
|
1881 |
* |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
25859
diff
changeset
|
1882 |
* @return false if this service cannot use the specified |
2 | 1883 |
* parameter; true if it can possibly use the parameter |
1884 |
* |
|
1885 |
* @throws InvalidParameterException if the value of parameter is |
|
1886 |
* invalid for this type of service or if this method cannot be |
|
1887 |
* used with this type of service |
|
1888 |
*/ |
|
1889 |
public boolean supportsParameter(Object parameter) { |
|
1890 |
EngineDescription cap = knownEngines.get(type); |
|
1891 |
if (cap == null) { |
|
1892 |
// unknown engine type, return true by default |
|
1893 |
return true; |
|
1894 |
} |
|
1895 |
if (cap.supportsParameter == false) { |
|
1896 |
throw new InvalidParameterException("supportsParameter() not " |
|
1897 |
+ "used with " + type + " engines"); |
|
1898 |
} |
|
1899 |
// allow null for keys without attributes for compatibility |
|
1900 |
if ((parameter != null) && (parameter instanceof Key == false)) { |
|
1901 |
throw new InvalidParameterException |
|
1902 |
("Parameter must be instanceof Key for engine " + type); |
|
1903 |
} |
|
1904 |
if (hasKeyAttributes() == false) { |
|
1905 |
return true; |
|
1906 |
} |
|
1907 |
if (parameter == null) { |
|
1908 |
return false; |
|
1909 |
} |
|
1910 |
Key key = (Key)parameter; |
|
1911 |
if (supportsKeyFormat(key)) { |
|
1912 |
return true; |
|
1913 |
} |
|
1914 |
if (supportsKeyClass(key)) { |
|
1915 |
return true; |
|
1916 |
} |
|
1917 |
return false; |
|
1918 |
} |
|
1919 |
||
1920 |
/** |
|
37880 | 1921 |
* Return whether this service has its supported properties for |
2 | 1922 |
* keys defined. Parses the attributes if not yet initialized. |
1923 |
*/ |
|
1924 |
private boolean hasKeyAttributes() { |
|
1925 |
Boolean b = hasKeyAttributes; |
|
1926 |
if (b == null) { |
|
1927 |
synchronized (this) { |
|
1928 |
String s; |
|
1929 |
s = getAttribute("SupportedKeyFormats"); |
|
1930 |
if (s != null) { |
|
1931 |
supportedFormats = s.split("\\|"); |
|
1932 |
} |
|
1933 |
s = getAttribute("SupportedKeyClasses"); |
|
1934 |
if (s != null) { |
|
1935 |
String[] classNames = s.split("\\|"); |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1936 |
List<Class<?>> classList = |
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
5506
diff
changeset
|
1937 |
new ArrayList<>(classNames.length); |
2 | 1938 |
for (String className : classNames) { |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1939 |
Class<?> clazz = getKeyClass(className); |
2 | 1940 |
if (clazz != null) { |
1941 |
classList.add(clazz); |
|
1942 |
} |
|
1943 |
} |
|
1944 |
supportedClasses = classList.toArray(CLASS0); |
|
1945 |
} |
|
1946 |
boolean bool = (supportedFormats != null) |
|
1947 |
|| (supportedClasses != null); |
|
1948 |
b = Boolean.valueOf(bool); |
|
1949 |
hasKeyAttributes = b; |
|
1950 |
} |
|
1951 |
} |
|
1952 |
return b.booleanValue(); |
|
1953 |
} |
|
1954 |
||
1955 |
// 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
|
1956 |
private Class<?> getKeyClass(String name) { |
2 | 1957 |
try { |
1958 |
return Class.forName(name); |
|
1959 |
} catch (ClassNotFoundException e) { |
|
1960 |
// ignore |
|
1961 |
} |
|
1962 |
try { |
|
1963 |
ClassLoader cl = provider.getClass().getClassLoader(); |
|
1964 |
if (cl != null) { |
|
1965 |
return cl.loadClass(name); |
|
1966 |
} |
|
1967 |
} catch (ClassNotFoundException e) { |
|
1968 |
// ignore |
|
1969 |
} |
|
1970 |
return null; |
|
1971 |
} |
|
1972 |
||
1973 |
private boolean supportsKeyFormat(Key key) { |
|
1974 |
if (supportedFormats == null) { |
|
1975 |
return false; |
|
1976 |
} |
|
1977 |
String format = key.getFormat(); |
|
1978 |
if (format == null) { |
|
1979 |
return false; |
|
1980 |
} |
|
1981 |
for (String supportedFormat : supportedFormats) { |
|
1982 |
if (supportedFormat.equals(format)) { |
|
1983 |
return true; |
|
1984 |
} |
|
1985 |
} |
|
1986 |
return false; |
|
1987 |
} |
|
1988 |
||
1989 |
private boolean supportsKeyClass(Key key) { |
|
1990 |
if (supportedClasses == null) { |
|
1991 |
return false; |
|
1992 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1993 |
Class<?> keyClass = key.getClass(); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1994 |
for (Class<?> clazz : supportedClasses) { |
2 | 1995 |
if (clazz.isAssignableFrom(keyClass)) { |
1996 |
return true; |
|
1997 |
} |
|
1998 |
} |
|
1999 |
return false; |
|
2000 |
} |
|
2001 |
||
2002 |
/** |
|
2003 |
* Return a String representation of this service. |
|
2004 |
* |
|
2005 |
* @return a String representation of this service. |
|
2006 |
*/ |
|
2007 |
public String toString() { |
|
2008 |
String aString = aliases.isEmpty() |
|
2009 |
? "" : "\r\n aliases: " + aliases.toString(); |
|
2010 |
String attrs = attributes.isEmpty() |
|
2011 |
? "" : "\r\n attributes: " + attributes.toString(); |
|
2012 |
return provider.getName() + ": " + type + "." + algorithm |
|
2013 |
+ " -> " + className + aString + attrs + "\r\n"; |
|
2014 |
} |
|
2015 |
} |
|
2016 |
} |