author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58519 | 6e017b301287 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1998, 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 javax.security.auth; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
import java.io.*; |
|
30 |
import java.lang.reflect.*; |
|
31 |
import java.text.MessageFormat; |
|
32 |
import java.security.AccessController; |
|
33 |
import java.security.AccessControlContext; |
|
34 |
import java.security.DomainCombiner; |
|
35 |
import java.security.Permission; |
|
36 |
import java.security.PermissionCollection; |
|
37 |
import java.security.Principal; |
|
38 |
import java.security.PrivilegedAction; |
|
39 |
import java.security.PrivilegedExceptionAction; |
|
40 |
import java.security.PrivilegedActionException; |
|
41 |
import java.security.ProtectionDomain; |
|
42 |
import sun.security.util.ResourcesMgr; |
|
43 |
||
44 |
/** |
|
18830 | 45 |
* <p> A {@code Subject} represents a grouping of related information |
2 | 46 |
* for a single entity, such as a person. |
47 |
* Such information includes the Subject's identities as well as |
|
48 |
* its security-related attributes |
|
49 |
* (passwords and cryptographic keys, for example). |
|
50 |
* |
|
51 |
* <p> Subjects may potentially have multiple identities. |
|
18830 | 52 |
* Each identity is represented as a {@code Principal} |
53 |
* within the {@code Subject}. Principals simply bind names to a |
|
54 |
* {@code Subject}. For example, a {@code Subject} that happens |
|
2 | 55 |
* to be a person, Alice, might have two Principals: |
56 |
* one which binds "Alice Bar", the name on her driver license, |
|
18830 | 57 |
* to the {@code Subject}, and another which binds, |
2 | 58 |
* "999-99-9999", the number on her student identification card, |
18830 | 59 |
* to the {@code Subject}. Both Principals refer to the same |
60 |
* {@code Subject} even though each has a different name. |
|
2 | 61 |
* |
18830 | 62 |
* <p> A {@code Subject} may also own security-related attributes, |
2 | 63 |
* which are referred to as credentials. |
64 |
* Sensitive credentials that require special protection, such as |
|
65 |
* private cryptographic keys, are stored within a private credential |
|
18830 | 66 |
* {@code Set}. Credentials intended to be shared, such as |
2 | 67 |
* public key certificates or Kerberos server tickets are stored |
18830 | 68 |
* within a public credential {@code Set}. Different permissions |
2 | 69 |
* are required to access and modify the different credential Sets. |
70 |
* |
|
18830 | 71 |
* <p> To retrieve all the Principals associated with a {@code Subject}, |
72 |
* invoke the {@code getPrincipals} method. To retrieve |
|
73 |
* all the public or private credentials belonging to a {@code Subject}, |
|
74 |
* invoke the {@code getPublicCredentials} method or |
|
75 |
* {@code getPrivateCredentials} method, respectively. |
|
76 |
* To modify the returned {@code Set} of Principals and credentials, |
|
77 |
* use the methods defined in the {@code Set} class. |
|
2 | 78 |
* For example: |
79 |
* <pre> |
|
80 |
* Subject subject; |
|
81 |
* Principal principal; |
|
82 |
* Object credential; |
|
83 |
* |
|
84 |
* // add a Principal and credential to the Subject |
|
85 |
* subject.getPrincipals().add(principal); |
|
86 |
* subject.getPublicCredentials().add(credential); |
|
87 |
* </pre> |
|
88 |
* |
|
18830 | 89 |
* <p> This {@code Subject} class implements {@code Serializable}. |
90 |
* While the Principals associated with the {@code Subject} are serialized, |
|
91 |
* the credentials associated with the {@code Subject} are not. |
|
92 |
* Note that the {@code java.security.Principal} class |
|
93 |
* does not implement {@code Serializable}. Therefore all concrete |
|
94 |
* {@code Principal} implementations associated with Subjects |
|
95 |
* must implement {@code Serializable}. |
|
2 | 96 |
* |
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
31061
diff
changeset
|
97 |
* @since 1.4 |
2 | 98 |
* @see java.security.Principal |
99 |
* @see java.security.DomainCombiner |
|
100 |
*/ |
|
101 |
public final class Subject implements java.io.Serializable { |
|
102 |
||
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
103 |
@java.io.Serial |
2 | 104 |
private static final long serialVersionUID = -8308522755600156056L; |
105 |
||
106 |
/** |
|
18830 | 107 |
* A {@code Set} that provides a view of all of this |
2 | 108 |
* Subject's Principals |
109 |
* |
|
110 |
* @serial Each element in this set is a |
|
18830 | 111 |
* {@code java.security.Principal}. |
112 |
* The set is a {@code Subject.SecureSet}. |
|
2 | 113 |
*/ |
58519
6e017b301287
8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents:
57950
diff
changeset
|
114 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
2 | 115 |
Set<Principal> principals; |
116 |
||
117 |
/** |
|
118 |
* Sets that provide a view of all of this |
|
119 |
* Subject's Credentials |
|
120 |
*/ |
|
121 |
transient Set<Object> pubCredentials; |
|
122 |
transient Set<Object> privCredentials; |
|
123 |
||
124 |
/** |
|
125 |
* Whether this Subject is read-only |
|
126 |
* |
|
127 |
* @serial |
|
128 |
*/ |
|
129 |
private volatile boolean readOnly = false; |
|
130 |
||
131 |
private static final int PRINCIPAL_SET = 1; |
|
132 |
private static final int PUB_CREDENTIAL_SET = 2; |
|
133 |
private static final int PRIV_CREDENTIAL_SET = 3; |
|
134 |
||
135 |
private static final ProtectionDomain[] NULL_PD_ARRAY |
|
136 |
= new ProtectionDomain[0]; |
|
137 |
||
138 |
/** |
|
18830 | 139 |
* Create an instance of a {@code Subject} |
140 |
* with an empty {@code Set} of Principals and empty |
|
2 | 141 |
* Sets of public and private credentials. |
142 |
* |
|
18830 | 143 |
* <p> The newly constructed Sets check whether this {@code Subject} |
2 | 144 |
* has been set read-only before permitting subsequent modifications. |
145 |
* The newly created Sets also prevent illegal modifications |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
146 |
* by ensuring that callers have sufficient permissions. These Sets |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
147 |
* also prohibit null elements, and attempts to add or query a null |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
148 |
* element will result in a {@code NullPointerException}. |
2 | 149 |
* |
150 |
* <p> To modify the Principals Set, the caller must have |
|
18830 | 151 |
* {@code AuthPermission("modifyPrincipals")}. |
2 | 152 |
* To modify the public credential Set, the caller must have |
18830 | 153 |
* {@code AuthPermission("modifyPublicCredentials")}. |
2 | 154 |
* To modify the private credential Set, the caller must have |
18830 | 155 |
* {@code AuthPermission("modifyPrivateCredentials")}. |
2 | 156 |
*/ |
157 |
public Subject() { |
|
158 |
||
159 |
this.principals = Collections.synchronizedSet |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
160 |
(new SecureSet<>(this, PRINCIPAL_SET)); |
2 | 161 |
this.pubCredentials = Collections.synchronizedSet |
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
162 |
(new SecureSet<>(this, PUB_CREDENTIAL_SET)); |
2 | 163 |
this.privCredentials = Collections.synchronizedSet |
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
164 |
(new SecureSet<>(this, PRIV_CREDENTIAL_SET)); |
2 | 165 |
} |
166 |
||
167 |
/** |
|
18830 | 168 |
* Create an instance of a {@code Subject} with |
2 | 169 |
* Principals and credentials. |
170 |
* |
|
171 |
* <p> The Principals and credentials from the specified Sets |
|
172 |
* are copied into newly constructed Sets. |
|
18830 | 173 |
* These newly created Sets check whether this {@code Subject} |
2 | 174 |
* has been set read-only before permitting subsequent modifications. |
175 |
* The newly created Sets also prevent illegal modifications |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
176 |
* by ensuring that callers have sufficient permissions. These Sets |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
177 |
* also prohibit null elements, and attempts to add or query a null |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
178 |
* element will result in a {@code NullPointerException}. |
2 | 179 |
* |
180 |
* <p> To modify the Principals Set, the caller must have |
|
18830 | 181 |
* {@code AuthPermission("modifyPrincipals")}. |
2 | 182 |
* To modify the public credential Set, the caller must have |
18830 | 183 |
* {@code AuthPermission("modifyPublicCredentials")}. |
2 | 184 |
* To modify the private credential Set, the caller must have |
18830 | 185 |
* {@code AuthPermission("modifyPrivateCredentials")}. |
2 | 186 |
* |
18830 | 187 |
* @param readOnly true if the {@code Subject} is to be read-only, |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
188 |
* and false otherwise. |
2 | 189 |
* |
18830 | 190 |
* @param principals the {@code Set} of Principals |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
191 |
* to be associated with this {@code Subject}. |
2 | 192 |
* |
18830 | 193 |
* @param pubCredentials the {@code Set} of public credentials |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
194 |
* to be associated with this {@code Subject}. |
2 | 195 |
* |
18830 | 196 |
* @param privCredentials the {@code Set} of private credentials |
197 |
* to be associated with this {@code Subject}. |
|
2 | 198 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
199 |
* @throws NullPointerException if the specified |
18830 | 200 |
* {@code principals}, {@code pubCredentials}, |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
201 |
* or {@code privCredentials} are {@code null}, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
202 |
* or a null value exists within any of these three |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
203 |
* Sets. |
2 | 204 |
*/ |
205 |
public Subject(boolean readOnly, Set<? extends Principal> principals, |
|
206 |
Set<?> pubCredentials, Set<?> privCredentials) |
|
207 |
{ |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
208 |
collectionNullClean(principals); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
209 |
collectionNullClean(pubCredentials); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
210 |
collectionNullClean(privCredentials); |
2 | 211 |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
212 |
this.principals = Collections.synchronizedSet(new SecureSet<> |
2 | 213 |
(this, PRINCIPAL_SET, principals)); |
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
214 |
this.pubCredentials = Collections.synchronizedSet(new SecureSet<> |
2 | 215 |
(this, PUB_CREDENTIAL_SET, pubCredentials)); |
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
216 |
this.privCredentials = Collections.synchronizedSet(new SecureSet<> |
2 | 217 |
(this, PRIV_CREDENTIAL_SET, privCredentials)); |
218 |
this.readOnly = readOnly; |
|
219 |
} |
|
220 |
||
221 |
/** |
|
18830 | 222 |
* Set this {@code Subject} to be read-only. |
2 | 223 |
* |
224 |
* <p> Modifications (additions and removals) to this Subject's |
|
18830 | 225 |
* {@code Principal} {@code Set} and |
2 | 226 |
* credential Sets will be disallowed. |
18830 | 227 |
* The {@code destroy} operation on this Subject's credentials will |
2 | 228 |
* still be permitted. |
229 |
* |
|
18830 | 230 |
* <p> Subsequent attempts to modify the Subject's {@code Principal} |
2 | 231 |
* and credential Sets will result in an |
18830 | 232 |
* {@code IllegalStateException} being thrown. |
233 |
* Also, once a {@code Subject} is read-only, |
|
2 | 234 |
* it can not be reset to being writable again. |
235 |
* |
|
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
236 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
237 |
* caller does not have an |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
238 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
239 |
* AuthPermission("setReadOnly")} permission to set this |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
240 |
* {@code Subject} to be read-only. |
2 | 241 |
*/ |
242 |
public void setReadOnly() { |
|
243 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
244 |
if (sm != null) { |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
245 |
sm.checkPermission(AuthPermissionHolder.SET_READ_ONLY_PERMISSION); |
2 | 246 |
} |
247 |
||
248 |
this.readOnly = true; |
|
249 |
} |
|
250 |
||
251 |
/** |
|
18830 | 252 |
* Query whether this {@code Subject} is read-only. |
2 | 253 |
* |
18830 | 254 |
* @return true if this {@code Subject} is read-only, false otherwise. |
2 | 255 |
*/ |
256 |
public boolean isReadOnly() { |
|
257 |
return this.readOnly; |
|
258 |
} |
|
259 |
||
260 |
/** |
|
18830 | 261 |
* Get the {@code Subject} associated with the provided |
262 |
* {@code AccessControlContext}. |
|
2 | 263 |
* |
18830 | 264 |
* <p> The {@code AccessControlContext} may contain many |
265 |
* Subjects (from nested {@code doAs} calls). |
|
266 |
* In this situation, the most recent {@code Subject} associated |
|
267 |
* with the {@code AccessControlContext} is returned. |
|
2 | 268 |
* |
18830 | 269 |
* @param acc the {@code AccessControlContext} from which to retrieve |
270 |
* the {@code Subject}. |
|
2 | 271 |
* |
18830 | 272 |
* @return the {@code Subject} associated with the provided |
273 |
* {@code AccessControlContext}, or {@code null} |
|
274 |
* if no {@code Subject} is associated |
|
275 |
* with the provided {@code AccessControlContext}. |
|
2 | 276 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
277 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
278 |
* caller does not have an |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
279 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
280 |
* AuthPermission("getSubject")} permission to get the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
281 |
* {@code Subject}. |
2 | 282 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
283 |
* @throws NullPointerException if the provided |
18830 | 284 |
* {@code AccessControlContext} is {@code null}. |
2 | 285 |
*/ |
286 |
public static Subject getSubject(final AccessControlContext acc) { |
|
287 |
||
288 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
289 |
if (sm != null) { |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
290 |
sm.checkPermission(AuthPermissionHolder.GET_SUBJECT_PERMISSION); |
2 | 291 |
} |
292 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
293 |
Objects.requireNonNull(acc, ResourcesMgr.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
294 |
("invalid.null.AccessControlContext.provided")); |
2 | 295 |
|
296 |
// return the Subject from the DomainCombiner of the provided context |
|
297 |
return AccessController.doPrivileged |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
298 |
(new java.security.PrivilegedAction<>() { |
2 | 299 |
public Subject run() { |
300 |
DomainCombiner dc = acc.getDomainCombiner(); |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
301 |
if (!(dc instanceof SubjectDomainCombiner)) { |
2 | 302 |
return null; |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
303 |
} |
2 | 304 |
SubjectDomainCombiner sdc = (SubjectDomainCombiner)dc; |
305 |
return sdc.getSubject(); |
|
306 |
} |
|
307 |
}); |
|
308 |
} |
|
309 |
||
310 |
/** |
|
18830 | 311 |
* Perform work as a particular {@code Subject}. |
2 | 312 |
* |
313 |
* <p> This method first retrieves the current Thread's |
|
18830 | 314 |
* {@code AccessControlContext} via |
315 |
* {@code AccessController.getContext}, |
|
316 |
* and then instantiates a new {@code AccessControlContext} |
|
2 | 317 |
* using the retrieved context along with a new |
18830 | 318 |
* {@code SubjectDomainCombiner} (constructed using |
319 |
* the provided {@code Subject}). |
|
320 |
* Finally, this method invokes {@code AccessController.doPrivileged}, |
|
321 |
* passing it the provided {@code PrivilegedAction}, |
|
322 |
* as well as the newly constructed {@code AccessControlContext}. |
|
2 | 323 |
* |
18830 | 324 |
* @param subject the {@code Subject} that the specified |
325 |
* {@code action} will run as. This parameter |
|
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
326 |
* may be {@code null}. |
2 | 327 |
* |
18771
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
328 |
* @param <T> the type of the value returned by the PrivilegedAction's |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
329 |
* {@code run} method. |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
330 |
* |
2 | 331 |
* @param action the code to be run as the specified |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
332 |
* {@code Subject}. |
2 | 333 |
* |
334 |
* @return the value returned by the PrivilegedAction's |
|
18830 | 335 |
* {@code run} method. |
2 | 336 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
337 |
* @throws NullPointerException if the {@code PrivilegedAction} |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
338 |
* is {@code null}. |
2 | 339 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
340 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
341 |
* caller does not have an |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
342 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
343 |
* AuthPermission("doAs")} permission to invoke this |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
344 |
* method. |
2 | 345 |
*/ |
346 |
public static <T> T doAs(final Subject subject, |
|
347 |
final java.security.PrivilegedAction<T> action) { |
|
348 |
||
349 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
350 |
if (sm != null) { |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
351 |
sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION); |
2 | 352 |
} |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
353 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
354 |
Objects.requireNonNull(action, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
355 |
ResourcesMgr.getString("invalid.null.action.provided")); |
2 | 356 |
|
357 |
// set up the new Subject-based AccessControlContext |
|
358 |
// for doPrivileged |
|
359 |
final AccessControlContext currentAcc = AccessController.getContext(); |
|
360 |
||
361 |
// call doPrivileged and push this new context on the stack |
|
362 |
return java.security.AccessController.doPrivileged |
|
363 |
(action, |
|
364 |
createContext(subject, currentAcc)); |
|
365 |
} |
|
366 |
||
367 |
/** |
|
18830 | 368 |
* Perform work as a particular {@code Subject}. |
2 | 369 |
* |
370 |
* <p> This method first retrieves the current Thread's |
|
18830 | 371 |
* {@code AccessControlContext} via |
372 |
* {@code AccessController.getContext}, |
|
373 |
* and then instantiates a new {@code AccessControlContext} |
|
2 | 374 |
* using the retrieved context along with a new |
18830 | 375 |
* {@code SubjectDomainCombiner} (constructed using |
376 |
* the provided {@code Subject}). |
|
377 |
* Finally, this method invokes {@code AccessController.doPrivileged}, |
|
378 |
* passing it the provided {@code PrivilegedExceptionAction}, |
|
379 |
* as well as the newly constructed {@code AccessControlContext}. |
|
2 | 380 |
* |
18830 | 381 |
* @param subject the {@code Subject} that the specified |
382 |
* {@code action} will run as. This parameter |
|
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
383 |
* may be {@code null}. |
2 | 384 |
* |
18771
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
385 |
* @param <T> the type of the value returned by the |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
386 |
* PrivilegedExceptionAction's {@code run} method. |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
387 |
* |
2 | 388 |
* @param action the code to be run as the specified |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
389 |
* {@code Subject}. |
2 | 390 |
* |
391 |
* @return the value returned by the |
|
18830 | 392 |
* PrivilegedExceptionAction's {@code run} method. |
2 | 393 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
394 |
* @throws PrivilegedActionException if the |
18830 | 395 |
* {@code PrivilegedExceptionAction.run} |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
396 |
* method throws a checked exception. |
2 | 397 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
398 |
* @throws NullPointerException if the specified |
18830 | 399 |
* {@code PrivilegedExceptionAction} is |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
400 |
* {@code null}. |
2 | 401 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
402 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
403 |
* caller does not have an |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
404 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
405 |
* AuthPermission("doAs")} permission to invoke this |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
406 |
* method. |
2 | 407 |
*/ |
408 |
public static <T> T doAs(final Subject subject, |
|
409 |
final java.security.PrivilegedExceptionAction<T> action) |
|
410 |
throws java.security.PrivilegedActionException { |
|
411 |
||
412 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
413 |
if (sm != null) { |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
414 |
sm.checkPermission(AuthPermissionHolder.DO_AS_PERMISSION); |
2 | 415 |
} |
416 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
417 |
Objects.requireNonNull(action, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
418 |
ResourcesMgr.getString("invalid.null.action.provided")); |
2 | 419 |
|
420 |
// set up the new Subject-based AccessControlContext for doPrivileged |
|
421 |
final AccessControlContext currentAcc = AccessController.getContext(); |
|
422 |
||
423 |
// call doPrivileged and push this new context on the stack |
|
424 |
return java.security.AccessController.doPrivileged |
|
425 |
(action, |
|
426 |
createContext(subject, currentAcc)); |
|
427 |
} |
|
428 |
||
429 |
/** |
|
18830 | 430 |
* Perform privileged work as a particular {@code Subject}. |
2 | 431 |
* |
18830 | 432 |
* <p> This method behaves exactly as {@code Subject.doAs}, |
2 | 433 |
* except that instead of retrieving the current Thread's |
18830 | 434 |
* {@code AccessControlContext}, it uses the provided |
435 |
* {@code AccessControlContext}. If the provided |
|
436 |
* {@code AccessControlContext} is {@code null}, |
|
437 |
* this method instantiates a new {@code AccessControlContext} |
|
2 | 438 |
* with an empty collection of ProtectionDomains. |
439 |
* |
|
18830 | 440 |
* @param subject the {@code Subject} that the specified |
441 |
* {@code action} will run as. This parameter |
|
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
442 |
* may be {@code null}. |
2 | 443 |
* |
18771
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
444 |
* @param <T> the type of the value returned by the PrivilegedAction's |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
445 |
* {@code run} method. |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
446 |
* |
2 | 447 |
* @param action the code to be run as the specified |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
448 |
* {@code Subject}. |
2 | 449 |
* |
18830 | 450 |
* @param acc the {@code AccessControlContext} to be tied to the |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
451 |
* specified <i>subject</i> and <i>action</i>. |
2 | 452 |
* |
453 |
* @return the value returned by the PrivilegedAction's |
|
18830 | 454 |
* {@code run} method. |
2 | 455 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
456 |
* @throws NullPointerException if the {@code PrivilegedAction} |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
457 |
* is {@code null}. |
2 | 458 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
459 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
460 |
* caller does not have a |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
461 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
462 |
* AuthPermission("doAsPrivileged")} permission to invoke |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
463 |
* this method. |
2 | 464 |
*/ |
465 |
public static <T> T doAsPrivileged(final Subject subject, |
|
466 |
final java.security.PrivilegedAction<T> action, |
|
467 |
final java.security.AccessControlContext acc) { |
|
468 |
||
469 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
470 |
if (sm != null) { |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
471 |
sm.checkPermission(AuthPermissionHolder.DO_AS_PRIVILEGED_PERMISSION); |
2 | 472 |
} |
473 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
474 |
Objects.requireNonNull(action, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
475 |
ResourcesMgr.getString("invalid.null.action.provided")); |
2 | 476 |
|
477 |
// set up the new Subject-based AccessControlContext |
|
478 |
// for doPrivileged |
|
479 |
final AccessControlContext callerAcc = |
|
480 |
(acc == null ? |
|
481 |
new AccessControlContext(NULL_PD_ARRAY) : |
|
482 |
acc); |
|
483 |
||
484 |
// call doPrivileged and push this new context on the stack |
|
485 |
return java.security.AccessController.doPrivileged |
|
486 |
(action, |
|
487 |
createContext(subject, callerAcc)); |
|
488 |
} |
|
489 |
||
490 |
/** |
|
18830 | 491 |
* Perform privileged work as a particular {@code Subject}. |
2 | 492 |
* |
18830 | 493 |
* <p> This method behaves exactly as {@code Subject.doAs}, |
2 | 494 |
* except that instead of retrieving the current Thread's |
18830 | 495 |
* {@code AccessControlContext}, it uses the provided |
496 |
* {@code AccessControlContext}. If the provided |
|
497 |
* {@code AccessControlContext} is {@code null}, |
|
498 |
* this method instantiates a new {@code AccessControlContext} |
|
2 | 499 |
* with an empty collection of ProtectionDomains. |
500 |
* |
|
18830 | 501 |
* @param subject the {@code Subject} that the specified |
502 |
* {@code action} will run as. This parameter |
|
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
503 |
* may be {@code null}. |
2 | 504 |
* |
18771
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
505 |
* @param <T> the type of the value returned by the |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
506 |
* PrivilegedExceptionAction's {@code run} method. |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
507 |
* |
2 | 508 |
* @param action the code to be run as the specified |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
509 |
* {@code Subject}. |
2 | 510 |
* |
18830 | 511 |
* @param acc the {@code AccessControlContext} to be tied to the |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
512 |
* specified <i>subject</i> and <i>action</i>. |
2 | 513 |
* |
514 |
* @return the value returned by the |
|
18830 | 515 |
* PrivilegedExceptionAction's {@code run} method. |
2 | 516 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
517 |
* @throws PrivilegedActionException if the |
18830 | 518 |
* {@code PrivilegedExceptionAction.run} |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
519 |
* method throws a checked exception. |
2 | 520 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
521 |
* @throws NullPointerException if the specified |
18830 | 522 |
* {@code PrivilegedExceptionAction} is |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
523 |
* {@code null}. |
2 | 524 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
525 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
526 |
* caller does not have a |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
527 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
528 |
* AuthPermission("doAsPrivileged")} permission to invoke |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
529 |
* this method. |
2 | 530 |
*/ |
531 |
public static <T> T doAsPrivileged(final Subject subject, |
|
532 |
final java.security.PrivilegedExceptionAction<T> action, |
|
533 |
final java.security.AccessControlContext acc) |
|
534 |
throws java.security.PrivilegedActionException { |
|
535 |
||
536 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
537 |
if (sm != null) { |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
538 |
sm.checkPermission(AuthPermissionHolder.DO_AS_PRIVILEGED_PERMISSION); |
2 | 539 |
} |
540 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
541 |
Objects.requireNonNull(action, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
542 |
ResourcesMgr.getString("invalid.null.action.provided")); |
2 | 543 |
|
544 |
// set up the new Subject-based AccessControlContext for doPrivileged |
|
545 |
final AccessControlContext callerAcc = |
|
546 |
(acc == null ? |
|
547 |
new AccessControlContext(NULL_PD_ARRAY) : |
|
548 |
acc); |
|
549 |
||
550 |
// call doPrivileged and push this new context on the stack |
|
551 |
return java.security.AccessController.doPrivileged |
|
552 |
(action, |
|
553 |
createContext(subject, callerAcc)); |
|
554 |
} |
|
555 |
||
556 |
private static AccessControlContext createContext(final Subject subject, |
|
557 |
final AccessControlContext acc) { |
|
558 |
||
559 |
||
560 |
return java.security.AccessController.doPrivileged |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
561 |
(new java.security.PrivilegedAction<>() { |
2 | 562 |
public AccessControlContext run() { |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
563 |
if (subject == null) { |
2 | 564 |
return new AccessControlContext(acc, null); |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
565 |
} else { |
2 | 566 |
return new AccessControlContext |
567 |
(acc, |
|
568 |
new SubjectDomainCombiner(subject)); |
|
569 |
} |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
570 |
} |
2 | 571 |
}); |
572 |
} |
|
573 |
||
574 |
/** |
|
18830 | 575 |
* Return the {@code Set} of Principals associated with this |
576 |
* {@code Subject}. Each {@code Principal} represents |
|
577 |
* an identity for this {@code Subject}. |
|
2 | 578 |
* |
18830 | 579 |
* <p> The returned {@code Set} is backed by this Subject's |
580 |
* internal {@code Principal} {@code Set}. Any modification |
|
581 |
* to the returned {@code Set} affects the internal |
|
582 |
* {@code Principal} {@code Set} as well. |
|
2 | 583 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
584 |
* <p> If a security manager is installed, the caller must have a |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
585 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
586 |
* AuthPermission("modifyPrincipals")} permission to modify |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
587 |
* the returned set, or a {@code SecurityException} will be thrown. |
2 | 588 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
589 |
* @return the {@code Set} of Principals associated with this |
18830 | 590 |
* {@code Subject}. |
2 | 591 |
*/ |
592 |
public Set<Principal> getPrincipals() { |
|
593 |
||
594 |
// always return an empty Set instead of null |
|
595 |
// so LoginModules can add to the Set if necessary |
|
596 |
return principals; |
|
597 |
} |
|
598 |
||
599 |
/** |
|
18830 | 600 |
* Return a {@code Set} of Principals associated with this |
601 |
* {@code Subject} that are instances or subclasses of the specified |
|
602 |
* {@code Class}. |
|
2 | 603 |
* |
18830 | 604 |
* <p> The returned {@code Set} is not backed by this Subject's |
605 |
* internal {@code Principal} {@code Set}. A new |
|
606 |
* {@code Set} is created and returned for each method invocation. |
|
607 |
* Modifications to the returned {@code Set} |
|
608 |
* will not affect the internal {@code Principal} {@code Set}. |
|
2 | 609 |
* |
18771
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
610 |
* @param <T> the type of the class modeled by {@code c} |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
611 |
* |
18830 | 612 |
* @param c the returned {@code Set} of Principals will all be |
2 | 613 |
* instances of this class. |
614 |
* |
|
18830 | 615 |
* @return a {@code Set} of Principals that are instances of the |
616 |
* specified {@code Class}. |
|
2 | 617 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
618 |
* @throws NullPointerException if the specified {@code Class} |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
619 |
* is {@code null}. |
2 | 620 |
*/ |
621 |
public <T extends Principal> Set<T> getPrincipals(Class<T> c) { |
|
622 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
623 |
Objects.requireNonNull(c, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
624 |
ResourcesMgr.getString("invalid.null.Class.provided")); |
2 | 625 |
|
626 |
// always return an empty Set instead of null |
|
627 |
// so LoginModules can add to the Set if necessary |
|
628 |
return new ClassSet<T>(PRINCIPAL_SET, c); |
|
629 |
} |
|
630 |
||
631 |
/** |
|
18830 | 632 |
* Return the {@code Set} of public credentials held by this |
633 |
* {@code Subject}. |
|
2 | 634 |
* |
18830 | 635 |
* <p> The returned {@code Set} is backed by this Subject's |
636 |
* internal public Credential {@code Set}. Any modification |
|
637 |
* to the returned {@code Set} affects the internal public |
|
638 |
* Credential {@code Set} as well. |
|
2 | 639 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
640 |
* <p> If a security manager is installed, the caller must have a |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
641 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
642 |
* AuthPermission("modifyPublicCredentials")} permission to modify |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
643 |
* the returned set, or a {@code SecurityException} will be thrown. |
2 | 644 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
645 |
* @return a {@code Set} of public credentials held by this |
18830 | 646 |
* {@code Subject}. |
2 | 647 |
*/ |
648 |
public Set<Object> getPublicCredentials() { |
|
649 |
||
650 |
// always return an empty Set instead of null |
|
651 |
// so LoginModules can add to the Set if necessary |
|
652 |
return pubCredentials; |
|
653 |
} |
|
654 |
||
655 |
/** |
|
18830 | 656 |
* Return the {@code Set} of private credentials held by this |
657 |
* {@code Subject}. |
|
2 | 658 |
* |
18830 | 659 |
* <p> The returned {@code Set} is backed by this Subject's |
660 |
* internal private Credential {@code Set}. Any modification |
|
661 |
* to the returned {@code Set} affects the internal private |
|
662 |
* Credential {@code Set} as well. |
|
2 | 663 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
664 |
* <p> If a security manager is installed, the caller must have a |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
665 |
* {@link AuthPermission#AuthPermission(String) |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
666 |
* AuthPermission("modifyPrivateCredentials")} permission to modify |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
667 |
* the returned set, or a {@code SecurityException} will be thrown. |
2 | 668 |
* |
18830 | 669 |
* <p> While iterating through the {@code Set}, |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
670 |
* a {@code SecurityException} is thrown if a security manager is installed |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
671 |
* and the caller does not have a {@link PrivateCredentialPermission} |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
672 |
* to access a particular Credential. The {@code Iterator} |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
673 |
* is nevertheless advanced to the next element in the {@code Set}. |
2 | 674 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
675 |
* @return a {@code Set} of private credentials held by this |
18830 | 676 |
* {@code Subject}. |
2 | 677 |
*/ |
678 |
public Set<Object> getPrivateCredentials() { |
|
679 |
||
680 |
// XXX |
|
681 |
// we do not need a security check for |
|
682 |
// AuthPermission(getPrivateCredentials) |
|
683 |
// because we already restrict access to private credentials |
|
684 |
// via the PrivateCredentialPermission. all the extra AuthPermission |
|
685 |
// would do is protect the set operations themselves |
|
686 |
// (like size()), which don't seem security-sensitive. |
|
687 |
||
688 |
// always return an empty Set instead of null |
|
689 |
// so LoginModules can add to the Set if necessary |
|
690 |
return privCredentials; |
|
691 |
} |
|
692 |
||
693 |
/** |
|
18830 | 694 |
* Return a {@code Set} of public credentials associated with this |
695 |
* {@code Subject} that are instances or subclasses of the specified |
|
696 |
* {@code Class}. |
|
2 | 697 |
* |
18830 | 698 |
* <p> The returned {@code Set} is not backed by this Subject's |
699 |
* internal public Credential {@code Set}. A new |
|
700 |
* {@code Set} is created and returned for each method invocation. |
|
701 |
* Modifications to the returned {@code Set} |
|
702 |
* will not affect the internal public Credential {@code Set}. |
|
2 | 703 |
* |
18771
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
704 |
* @param <T> the type of the class modeled by {@code c} |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
705 |
* |
18830 | 706 |
* @param c the returned {@code Set} of public credentials will all be |
2 | 707 |
* instances of this class. |
708 |
* |
|
18830 | 709 |
* @return a {@code Set} of public credentials that are instances |
710 |
* of the specified {@code Class}. |
|
2 | 711 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
712 |
* @throws NullPointerException if the specified {@code Class} |
18830 | 713 |
* is {@code null}. |
2 | 714 |
*/ |
715 |
public <T> Set<T> getPublicCredentials(Class<T> c) { |
|
716 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
717 |
Objects.requireNonNull(c, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
718 |
ResourcesMgr.getString("invalid.null.Class.provided")); |
2 | 719 |
|
720 |
// always return an empty Set instead of null |
|
721 |
// so LoginModules can add to the Set if necessary |
|
722 |
return new ClassSet<T>(PUB_CREDENTIAL_SET, c); |
|
723 |
} |
|
724 |
||
725 |
/** |
|
18830 | 726 |
* Return a {@code Set} of private credentials associated with this |
727 |
* {@code Subject} that are instances or subclasses of the specified |
|
728 |
* {@code Class}. |
|
2 | 729 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
730 |
* <p> If a security manager is installed, the caller must have a |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
731 |
* {@link PrivateCredentialPermission} to access all of the requested |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
732 |
* Credentials, or a {@code SecurityException} will be thrown. |
2 | 733 |
* |
18830 | 734 |
* <p> The returned {@code Set} is not backed by this Subject's |
735 |
* internal private Credential {@code Set}. A new |
|
736 |
* {@code Set} is created and returned for each method invocation. |
|
737 |
* Modifications to the returned {@code Set} |
|
738 |
* will not affect the internal private Credential {@code Set}. |
|
2 | 739 |
* |
18771
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
740 |
* @param <T> the type of the class modeled by {@code c} |
9dadb0719cea
8019772: Fix doclint issues in javax.crypto and javax.security subpackages
juh
parents:
14342
diff
changeset
|
741 |
* |
18830 | 742 |
* @param c the returned {@code Set} of private credentials will all be |
2 | 743 |
* instances of this class. |
744 |
* |
|
18830 | 745 |
* @return a {@code Set} of private credentials that are instances |
746 |
* of the specified {@code Class}. |
|
2 | 747 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
748 |
* @throws NullPointerException if the specified {@code Class} |
18830 | 749 |
* is {@code null}. |
2 | 750 |
*/ |
751 |
public <T> Set<T> getPrivateCredentials(Class<T> c) { |
|
752 |
||
753 |
// XXX |
|
754 |
// we do not need a security check for |
|
755 |
// AuthPermission(getPrivateCredentials) |
|
756 |
// because we already restrict access to private credentials |
|
757 |
// via the PrivateCredentialPermission. all the extra AuthPermission |
|
758 |
// would do is protect the set operations themselves |
|
759 |
// (like size()), which don't seem security-sensitive. |
|
760 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
761 |
Objects.requireNonNull(c, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
762 |
ResourcesMgr.getString("invalid.null.Class.provided")); |
2 | 763 |
|
764 |
// always return an empty Set instead of null |
|
765 |
// so LoginModules can add to the Set if necessary |
|
766 |
return new ClassSet<T>(PRIV_CREDENTIAL_SET, c); |
|
767 |
} |
|
768 |
||
769 |
/** |
|
18830 | 770 |
* Compares the specified Object with this {@code Subject} |
2 | 771 |
* for equality. Returns true if the given object is also a Subject |
18830 | 772 |
* and the two {@code Subject} instances are equivalent. |
773 |
* More formally, two {@code Subject} instances are |
|
774 |
* equal if their {@code Principal} and {@code Credential} |
|
2 | 775 |
* Sets are equal. |
776 |
* |
|
777 |
* @param o Object to be compared for equality with this |
|
18830 | 778 |
* {@code Subject}. |
2 | 779 |
* |
780 |
* @return true if the specified Object is equal to this |
|
18830 | 781 |
* {@code Subject}. |
2 | 782 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
783 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
784 |
* caller does not have a {@link PrivateCredentialPermission} |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
785 |
* permission to access the private credentials for this |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
786 |
* {@code Subject} or the provided {@code Subject}. |
2 | 787 |
*/ |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
788 |
@Override |
2 | 789 |
public boolean equals(Object o) { |
790 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
791 |
if (o == null) { |
2 | 792 |
return false; |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
793 |
} |
2 | 794 |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
795 |
if (this == o) { |
2 | 796 |
return true; |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
797 |
} |
2 | 798 |
|
799 |
if (o instanceof Subject) { |
|
800 |
||
801 |
final Subject that = (Subject)o; |
|
802 |
||
803 |
// check the principal and credential sets |
|
804 |
Set<Principal> thatPrincipals; |
|
805 |
synchronized(that.principals) { |
|
806 |
// avoid deadlock from dual locks |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
807 |
thatPrincipals = new HashSet<>(that.principals); |
2 | 808 |
} |
809 |
if (!principals.equals(thatPrincipals)) { |
|
810 |
return false; |
|
811 |
} |
|
812 |
||
813 |
Set<Object> thatPubCredentials; |
|
814 |
synchronized(that.pubCredentials) { |
|
815 |
// avoid deadlock from dual locks |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
816 |
thatPubCredentials = new HashSet<>(that.pubCredentials); |
2 | 817 |
} |
818 |
if (!pubCredentials.equals(thatPubCredentials)) { |
|
819 |
return false; |
|
820 |
} |
|
821 |
||
822 |
Set<Object> thatPrivCredentials; |
|
823 |
synchronized(that.privCredentials) { |
|
824 |
// avoid deadlock from dual locks |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
825 |
thatPrivCredentials = new HashSet<>(that.privCredentials); |
2 | 826 |
} |
827 |
if (!privCredentials.equals(thatPrivCredentials)) { |
|
828 |
return false; |
|
829 |
} |
|
830 |
return true; |
|
831 |
} |
|
832 |
return false; |
|
833 |
} |
|
834 |
||
835 |
/** |
|
18830 | 836 |
* Return the String representation of this {@code Subject}. |
2 | 837 |
* |
18830 | 838 |
* @return the String representation of this {@code Subject}. |
2 | 839 |
*/ |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
840 |
@Override |
2 | 841 |
public String toString() { |
842 |
return toString(true); |
|
843 |
} |
|
844 |
||
845 |
/** |
|
846 |
* package private convenience method to print out the Subject |
|
847 |
* without firing off a security check when trying to access |
|
848 |
* the Private Credentials |
|
849 |
*/ |
|
850 |
String toString(boolean includePrivateCredentials) { |
|
851 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
852 |
String s = ResourcesMgr.getString("Subject."); |
2 | 853 |
String suffix = ""; |
854 |
||
855 |
synchronized(principals) { |
|
856 |
Iterator<Principal> pI = principals.iterator(); |
|
857 |
while (pI.hasNext()) { |
|
858 |
Principal p = pI.next(); |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
859 |
suffix = suffix + ResourcesMgr.getString(".Principal.") + |
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
860 |
p.toString() + ResourcesMgr.getString("NEWLINE"); |
2 | 861 |
} |
862 |
} |
|
863 |
||
864 |
synchronized(pubCredentials) { |
|
865 |
Iterator<Object> pI = pubCredentials.iterator(); |
|
866 |
while (pI.hasNext()) { |
|
867 |
Object o = pI.next(); |
|
868 |
suffix = suffix + |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
869 |
ResourcesMgr.getString(".Public.Credential.") + |
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
870 |
o.toString() + ResourcesMgr.getString("NEWLINE"); |
2 | 871 |
} |
872 |
} |
|
873 |
||
874 |
if (includePrivateCredentials) { |
|
875 |
synchronized(privCredentials) { |
|
876 |
Iterator<Object> pI = privCredentials.iterator(); |
|
877 |
while (pI.hasNext()) { |
|
878 |
try { |
|
879 |
Object o = pI.next(); |
|
880 |
suffix += ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
881 |
(".Private.Credential.") + |
2 | 882 |
o.toString() + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
883 |
ResourcesMgr.getString("NEWLINE"); |
2 | 884 |
} catch (SecurityException se) { |
885 |
suffix += ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
886 |
(".Private.Credential.inaccessible."); |
2 | 887 |
break; |
888 |
} |
|
889 |
} |
|
890 |
} |
|
891 |
} |
|
892 |
return s + suffix; |
|
893 |
} |
|
894 |
||
895 |
/** |
|
18830 | 896 |
* Returns a hashcode for this {@code Subject}. |
2 | 897 |
* |
18830 | 898 |
* @return a hashcode for this {@code Subject}. |
2 | 899 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
900 |
* @throws SecurityException if a security manager is installed and the |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
901 |
* caller does not have a {@link PrivateCredentialPermission} |
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
902 |
* permission to access this Subject's private credentials. |
2 | 903 |
*/ |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
904 |
@Override |
2 | 905 |
public int hashCode() { |
906 |
||
907 |
/** |
|
908 |
* The hashcode is derived exclusive or-ing the |
|
909 |
* hashcodes of this Subject's Principals and credentials. |
|
910 |
* |
|
911 |
* If a particular credential was destroyed |
|
18830 | 912 |
* ({@code credential.hashCode()} throws an |
913 |
* {@code IllegalStateException}), |
|
2 | 914 |
* the hashcode for that credential is derived via: |
18830 | 915 |
* {@code credential.getClass().toString().hashCode()}. |
2 | 916 |
*/ |
917 |
||
918 |
int hashCode = 0; |
|
919 |
||
920 |
synchronized(principals) { |
|
921 |
Iterator<Principal> pIterator = principals.iterator(); |
|
922 |
while (pIterator.hasNext()) { |
|
923 |
Principal p = pIterator.next(); |
|
924 |
hashCode ^= p.hashCode(); |
|
925 |
} |
|
926 |
} |
|
927 |
||
928 |
synchronized(pubCredentials) { |
|
929 |
Iterator<Object> pubCIterator = pubCredentials.iterator(); |
|
930 |
while (pubCIterator.hasNext()) { |
|
931 |
hashCode ^= getCredHashCode(pubCIterator.next()); |
|
932 |
} |
|
933 |
} |
|
934 |
return hashCode; |
|
935 |
} |
|
936 |
||
937 |
/** |
|
938 |
* get a credential's hashcode |
|
939 |
*/ |
|
940 |
private int getCredHashCode(Object o) { |
|
941 |
try { |
|
942 |
return o.hashCode(); |
|
943 |
} catch (IllegalStateException ise) { |
|
944 |
return o.getClass().toString().hashCode(); |
|
945 |
} |
|
946 |
} |
|
947 |
||
948 |
/** |
|
949 |
* Writes this object out to a stream (i.e., serializes it). |
|
950 |
*/ |
|
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
951 |
@java.io.Serial |
2 | 952 |
private void writeObject(java.io.ObjectOutputStream oos) |
953 |
throws java.io.IOException { |
|
954 |
synchronized(principals) { |
|
955 |
oos.defaultWriteObject(); |
|
956 |
} |
|
957 |
} |
|
958 |
||
959 |
/** |
|
960 |
* Reads this object from a stream (i.e., deserializes it) |
|
961 |
*/ |
|
23913
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
962 |
@SuppressWarnings("unchecked") |
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
963 |
@java.io.Serial |
2 | 964 |
private void readObject(java.io.ObjectInputStream s) |
965 |
throws java.io.IOException, ClassNotFoundException { |
|
966 |
||
23913
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
967 |
ObjectInputStream.GetField gf = s.readFields(); |
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
968 |
|
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
969 |
readOnly = gf.get("readOnly", false); |
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
970 |
|
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
971 |
Set<Principal> inputPrincs = (Set<Principal>)gf.get("principals", null); |
2 | 972 |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
973 |
Objects.requireNonNull(inputPrincs, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
974 |
ResourcesMgr.getString("invalid.null.input.s.")); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
975 |
|
22310 | 976 |
// Rewrap the principals into a SecureSet |
23913
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
977 |
try { |
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
978 |
principals = Collections.synchronizedSet(new SecureSet<> |
23913
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
979 |
(this, PRINCIPAL_SET, inputPrincs)); |
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
980 |
} catch (NullPointerException npe) { |
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
981 |
// Sometimes people deserialize the principals set only. |
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
982 |
// Subject is not accessible, so just don't fail. |
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
983 |
principals = Collections.synchronizedSet |
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
984 |
(new SecureSet<>(this, PRINCIPAL_SET)); |
23913
049a0df69b88
8030655: Regression: 14_01 Security fix 8024306 causes test failures
weijun
parents:
22317
diff
changeset
|
985 |
} |
22310 | 986 |
|
18830 | 987 |
// The Credential {@code Set} is not serialized, but we do not |
2 | 988 |
// want the default deserialization routine to set it to null. |
989 |
this.pubCredentials = Collections.synchronizedSet |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
990 |
(new SecureSet<>(this, PUB_CREDENTIAL_SET)); |
2 | 991 |
this.privCredentials = Collections.synchronizedSet |
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
992 |
(new SecureSet<>(this, PRIV_CREDENTIAL_SET)); |
2 | 993 |
} |
994 |
||
995 |
/** |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
996 |
* Tests for null-clean collections (both non-null reference and |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
997 |
* no null elements) |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
998 |
* |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
999 |
* @param coll A {@code Collection} to be tested for null references |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1000 |
* |
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
1001 |
* @throws NullPointerException if the specified collection is either |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1002 |
* {@code null} or contains a {@code null} element |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1003 |
*/ |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1004 |
private static void collectionNullClean(Collection<?> coll) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1005 |
boolean hasNullElements = false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1006 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1007 |
Objects.requireNonNull(coll, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1008 |
ResourcesMgr.getString("invalid.null.input.s.")); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1009 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1010 |
try { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1011 |
hasNullElements = coll.contains(null); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1012 |
} catch (NullPointerException npe) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1013 |
// A null-hostile collection may choose to throw |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1014 |
// NullPointerException if contains(null) is called on it |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1015 |
// rather than returning false. |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1016 |
// If this happens we know the collection is null-clean. |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1017 |
hasNullElements = false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1018 |
} finally { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1019 |
if (hasNullElements) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1020 |
throw new NullPointerException |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1021 |
(ResourcesMgr.getString("invalid.null.input.s.")); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1022 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1023 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1024 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1025 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1026 |
/** |
2 | 1027 |
* Prevent modifications unless caller has permission. |
1028 |
* |
|
1029 |
* @serial include |
|
1030 |
*/ |
|
1031 |
private static class SecureSet<E> |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1032 |
implements Set<E>, java.io.Serializable { |
2 | 1033 |
|
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
1034 |
@java.io.Serial |
2 | 1035 |
private static final long serialVersionUID = 7911754171111800359L; |
1036 |
||
1037 |
/** |
|
1038 |
* @serialField this$0 Subject The outer Subject instance. |
|
1039 |
* @serialField elements LinkedList The elements in this set. |
|
1040 |
*/ |
|
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
1041 |
@java.io.Serial |
2 | 1042 |
private static final ObjectStreamField[] serialPersistentFields = { |
1043 |
new ObjectStreamField("this$0", Subject.class), |
|
1044 |
new ObjectStreamField("elements", LinkedList.class), |
|
1045 |
new ObjectStreamField("which", int.class) |
|
1046 |
}; |
|
1047 |
||
1048 |
Subject subject; |
|
1049 |
LinkedList<E> elements; |
|
1050 |
||
1051 |
/** |
|
1052 |
* @serial An integer identifying the type of objects contained |
|
18830 | 1053 |
* in this set. If {@code which == 1}, |
2 | 1054 |
* this is a Principal set and all the elements are |
18830 | 1055 |
* of type {@code java.security.Principal}. |
1056 |
* If {@code which == 2}, this is a public credential |
|
1057 |
* set and all the elements are of type {@code Object}. |
|
1058 |
* If {@code which == 3}, this is a private credential |
|
1059 |
* set and all the elements are of type {@code Object}. |
|
2 | 1060 |
*/ |
1061 |
private int which; |
|
1062 |
||
1063 |
SecureSet(Subject subject, int which) { |
|
1064 |
this.subject = subject; |
|
1065 |
this.which = which; |
|
1066 |
this.elements = new LinkedList<E>(); |
|
1067 |
} |
|
1068 |
||
1069 |
SecureSet(Subject subject, int which, Set<? extends E> set) { |
|
1070 |
this.subject = subject; |
|
1071 |
this.which = which; |
|
1072 |
this.elements = new LinkedList<E>(set); |
|
1073 |
} |
|
1074 |
||
1075 |
public int size() { |
|
1076 |
return elements.size(); |
|
1077 |
} |
|
1078 |
||
1079 |
public Iterator<E> iterator() { |
|
1080 |
final LinkedList<E> list = elements; |
|
1081 |
return new Iterator<E>() { |
|
1082 |
ListIterator<E> i = list.listIterator(0); |
|
1083 |
||
1084 |
public boolean hasNext() {return i.hasNext();} |
|
1085 |
||
1086 |
public E next() { |
|
1087 |
if (which != Subject.PRIV_CREDENTIAL_SET) { |
|
1088 |
return i.next(); |
|
1089 |
} |
|
1090 |
||
1091 |
SecurityManager sm = System.getSecurityManager(); |
|
1092 |
if (sm != null) { |
|
1093 |
try { |
|
1094 |
sm.checkPermission(new PrivateCredentialPermission |
|
1095 |
(list.get(i.nextIndex()).getClass().getName(), |
|
1096 |
subject.getPrincipals())); |
|
1097 |
} catch (SecurityException se) { |
|
1098 |
i.next(); |
|
1099 |
throw (se); |
|
1100 |
} |
|
1101 |
} |
|
1102 |
return i.next(); |
|
1103 |
} |
|
1104 |
||
1105 |
public void remove() { |
|
1106 |
||
1107 |
if (subject.isReadOnly()) { |
|
1108 |
throw new IllegalStateException(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
1109 |
("Subject.is.read.only")); |
2 | 1110 |
} |
1111 |
||
1112 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
1113 |
if (sm != null) { |
|
1114 |
switch (which) { |
|
1115 |
case Subject.PRINCIPAL_SET: |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1116 |
sm.checkPermission(AuthPermissionHolder.MODIFY_PRINCIPALS_PERMISSION); |
2 | 1117 |
break; |
1118 |
case Subject.PUB_CREDENTIAL_SET: |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1119 |
sm.checkPermission(AuthPermissionHolder.MODIFY_PUBLIC_CREDENTIALS_PERMISSION); |
2 | 1120 |
break; |
1121 |
default: |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1122 |
sm.checkPermission(AuthPermissionHolder.MODIFY_PRIVATE_CREDENTIALS_PERMISSION); |
2 | 1123 |
break; |
1124 |
} |
|
1125 |
} |
|
1126 |
i.remove(); |
|
1127 |
} |
|
1128 |
}; |
|
1129 |
} |
|
1130 |
||
1131 |
public boolean add(E o) { |
|
1132 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1133 |
Objects.requireNonNull(o, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1134 |
ResourcesMgr.getString("invalid.null.input.s.")); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1135 |
|
2 | 1136 |
if (subject.isReadOnly()) { |
1137 |
throw new IllegalStateException |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
1138 |
(ResourcesMgr.getString("Subject.is.read.only")); |
2 | 1139 |
} |
1140 |
||
1141 |
java.lang.SecurityManager sm = System.getSecurityManager(); |
|
1142 |
if (sm != null) { |
|
1143 |
switch (which) { |
|
1144 |
case Subject.PRINCIPAL_SET: |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1145 |
sm.checkPermission(AuthPermissionHolder.MODIFY_PRINCIPALS_PERMISSION); |
2 | 1146 |
break; |
1147 |
case Subject.PUB_CREDENTIAL_SET: |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1148 |
sm.checkPermission(AuthPermissionHolder.MODIFY_PUBLIC_CREDENTIALS_PERMISSION); |
2 | 1149 |
break; |
1150 |
default: |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1151 |
sm.checkPermission(AuthPermissionHolder.MODIFY_PRIVATE_CREDENTIALS_PERMISSION); |
2 | 1152 |
break; |
1153 |
} |
|
1154 |
} |
|
1155 |
||
1156 |
switch (which) { |
|
1157 |
case Subject.PRINCIPAL_SET: |
|
1158 |
if (!(o instanceof Principal)) { |
|
1159 |
throw new SecurityException(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
1160 |
("attempting.to.add.an.object.which.is.not.an.instance.of.java.security.Principal.to.a.Subject.s.Principal.Set")); |
2 | 1161 |
} |
1162 |
break; |
|
1163 |
default: |
|
1164 |
// ok to add Objects of any kind to credential sets |
|
1165 |
break; |
|
1166 |
} |
|
1167 |
||
1168 |
// check for duplicates |
|
1169 |
if (!elements.contains(o)) |
|
1170 |
return elements.add(o); |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1171 |
else { |
2 | 1172 |
return false; |
1173 |
} |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1174 |
} |
2 | 1175 |
|
1176 |
public boolean remove(Object o) { |
|
1177 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1178 |
Objects.requireNonNull(o, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1179 |
ResourcesMgr.getString("invalid.null.input.s.")); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1180 |
|
2 | 1181 |
final Iterator<E> e = iterator(); |
1182 |
while (e.hasNext()) { |
|
1183 |
E next; |
|
1184 |
if (which != Subject.PRIV_CREDENTIAL_SET) { |
|
1185 |
next = e.next(); |
|
1186 |
} else { |
|
1187 |
next = java.security.AccessController.doPrivileged |
|
1188 |
(new java.security.PrivilegedAction<E>() { |
|
1189 |
public E run() { |
|
1190 |
return e.next(); |
|
1191 |
} |
|
1192 |
}); |
|
1193 |
} |
|
1194 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1195 |
if (next.equals(o)) { |
2 | 1196 |
e.remove(); |
1197 |
return true; |
|
1198 |
} |
|
1199 |
} |
|
1200 |
return false; |
|
1201 |
} |
|
1202 |
||
1203 |
public boolean contains(Object o) { |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1204 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1205 |
Objects.requireNonNull(o, |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1206 |
ResourcesMgr.getString("invalid.null.input.s.")); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1207 |
|
2 | 1208 |
final Iterator<E> e = iterator(); |
1209 |
while (e.hasNext()) { |
|
1210 |
E next; |
|
1211 |
if (which != Subject.PRIV_CREDENTIAL_SET) { |
|
1212 |
next = e.next(); |
|
1213 |
} else { |
|
1214 |
||
1215 |
// For private credentials: |
|
1216 |
// If the caller does not have read permission for |
|
1217 |
// for o.getClass(), we throw a SecurityException. |
|
1218 |
// Otherwise we check the private cred set to see whether |
|
1219 |
// it contains the Object |
|
1220 |
||
1221 |
SecurityManager sm = System.getSecurityManager(); |
|
1222 |
if (sm != null) { |
|
1223 |
sm.checkPermission(new PrivateCredentialPermission |
|
1224 |
(o.getClass().getName(), |
|
1225 |
subject.getPrincipals())); |
|
1226 |
} |
|
1227 |
next = java.security.AccessController.doPrivileged |
|
1228 |
(new java.security.PrivilegedAction<E>() { |
|
1229 |
public E run() { |
|
1230 |
return e.next(); |
|
1231 |
} |
|
1232 |
}); |
|
1233 |
} |
|
1234 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1235 |
if (next.equals(o)) { |
2 | 1236 |
return true; |
1237 |
} |
|
1238 |
} |
|
1239 |
return false; |
|
1240 |
} |
|
1241 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1242 |
public boolean addAll(Collection<? extends E> c) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1243 |
boolean result = false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1244 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1245 |
collectionNullClean(c); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1246 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1247 |
for (E item : c) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1248 |
result |= this.add(item); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1249 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1250 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1251 |
return result; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1252 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1253 |
|
2 | 1254 |
public boolean removeAll(Collection<?> c) { |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1255 |
collectionNullClean(c); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1256 |
|
2 | 1257 |
boolean modified = false; |
1258 |
final Iterator<E> e = iterator(); |
|
1259 |
while (e.hasNext()) { |
|
1260 |
E next; |
|
1261 |
if (which != Subject.PRIV_CREDENTIAL_SET) { |
|
1262 |
next = e.next(); |
|
1263 |
} else { |
|
1264 |
next = java.security.AccessController.doPrivileged |
|
1265 |
(new java.security.PrivilegedAction<E>() { |
|
1266 |
public E run() { |
|
1267 |
return e.next(); |
|
1268 |
} |
|
1269 |
}); |
|
1270 |
} |
|
1271 |
||
1272 |
Iterator<?> ce = c.iterator(); |
|
1273 |
while (ce.hasNext()) { |
|
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1274 |
if (next.equals(ce.next())) { |
2 | 1275 |
e.remove(); |
1276 |
modified = true; |
|
1277 |
break; |
|
1278 |
} |
|
1279 |
} |
|
1280 |
} |
|
1281 |
return modified; |
|
1282 |
} |
|
1283 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1284 |
public boolean containsAll(Collection<?> c) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1285 |
collectionNullClean(c); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1286 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1287 |
for (Object item : c) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1288 |
if (this.contains(item) == false) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1289 |
return false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1290 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1291 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1292 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1293 |
return true; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1294 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1295 |
|
2 | 1296 |
public boolean retainAll(Collection<?> c) { |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1297 |
collectionNullClean(c); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1298 |
|
2 | 1299 |
boolean modified = false; |
1300 |
final Iterator<E> e = iterator(); |
|
1301 |
while (e.hasNext()) { |
|
1302 |
E next; |
|
1303 |
if (which != Subject.PRIV_CREDENTIAL_SET) { |
|
1304 |
next = e.next(); |
|
1305 |
} else { |
|
1306 |
next = java.security.AccessController.doPrivileged |
|
1307 |
(new java.security.PrivilegedAction<E>() { |
|
1308 |
public E run() { |
|
1309 |
return e.next(); |
|
1310 |
} |
|
1311 |
}); |
|
1312 |
} |
|
1313 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1314 |
if (c.contains(next) == false) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1315 |
e.remove(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1316 |
modified = true; |
2 | 1317 |
} |
1318 |
} |
|
1319 |
||
1320 |
return modified; |
|
1321 |
} |
|
1322 |
||
1323 |
public void clear() { |
|
1324 |
final Iterator<E> e = iterator(); |
|
1325 |
while (e.hasNext()) { |
|
1326 |
E next; |
|
1327 |
if (which != Subject.PRIV_CREDENTIAL_SET) { |
|
1328 |
next = e.next(); |
|
1329 |
} else { |
|
1330 |
next = java.security.AccessController.doPrivileged |
|
1331 |
(new java.security.PrivilegedAction<E>() { |
|
1332 |
public E run() { |
|
1333 |
return e.next(); |
|
1334 |
} |
|
1335 |
}); |
|
1336 |
} |
|
1337 |
e.remove(); |
|
1338 |
} |
|
1339 |
} |
|
1340 |
||
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1341 |
public boolean isEmpty() { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1342 |
return elements.isEmpty(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1343 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1344 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1345 |
public Object[] toArray() { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1346 |
final Iterator<E> e = iterator(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1347 |
while (e.hasNext()) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1348 |
// The next() method performs a security manager check |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1349 |
// on each element in the SecureSet. If we make it all |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1350 |
// the way through we should be able to simply return |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1351 |
// element's toArray results. Otherwise we'll let |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1352 |
// the SecurityException pass up the call stack. |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1353 |
e.next(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1354 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1355 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1356 |
return elements.toArray(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1357 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1358 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1359 |
public <T> T[] toArray(T[] a) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1360 |
final Iterator<E> e = iterator(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1361 |
while (e.hasNext()) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1362 |
// The next() method performs a security manager check |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1363 |
// on each element in the SecureSet. If we make it all |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1364 |
// the way through we should be able to simply return |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1365 |
// element's toArray results. Otherwise we'll let |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1366 |
// the SecurityException pass up the call stack. |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1367 |
e.next(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1368 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1369 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1370 |
return elements.toArray(a); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1371 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1372 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1373 |
public boolean equals(Object o) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1374 |
if (o == this) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1375 |
return true; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1376 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1377 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1378 |
if (!(o instanceof Set)) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1379 |
return false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1380 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1381 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1382 |
Collection<?> c = (Collection<?>) o; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1383 |
if (c.size() != size()) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1384 |
return false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1385 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1386 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1387 |
try { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1388 |
return containsAll(c); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1389 |
} catch (ClassCastException unused) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1390 |
return false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1391 |
} catch (NullPointerException unused) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1392 |
return false; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1393 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1394 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1395 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1396 |
public int hashCode() { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1397 |
int h = 0; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1398 |
Iterator<E> i = iterator(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1399 |
while (i.hasNext()) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1400 |
E obj = i.next(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1401 |
if (obj != null) { |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1402 |
h += obj.hashCode(); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1403 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1404 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1405 |
return h; |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1406 |
} |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1407 |
|
2 | 1408 |
/** |
1409 |
* Writes this object out to a stream (i.e., serializes it). |
|
1410 |
* |
|
1411 |
* @serialData If this is a private credential set, |
|
1412 |
* a security check is performed to ensure that |
|
1413 |
* the caller has permission to access each credential |
|
1414 |
* in the set. If the security check passes, |
|
1415 |
* the set is serialized. |
|
1416 |
*/ |
|
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
1417 |
@java.io.Serial |
2 | 1418 |
private void writeObject(java.io.ObjectOutputStream oos) |
1419 |
throws java.io.IOException { |
|
1420 |
||
1421 |
if (which == Subject.PRIV_CREDENTIAL_SET) { |
|
1422 |
// check permissions before serializing |
|
1423 |
Iterator<E> i = iterator(); |
|
1424 |
while (i.hasNext()) { |
|
1425 |
i.next(); |
|
1426 |
} |
|
1427 |
} |
|
1428 |
ObjectOutputStream.PutField fields = oos.putFields(); |
|
1429 |
fields.put("this$0", subject); |
|
1430 |
fields.put("elements", elements); |
|
1431 |
fields.put("which", which); |
|
1432 |
oos.writeFields(); |
|
1433 |
} |
|
1434 |
||
10709
d865c9f21240
7092375: Security Libraries don't build with javac -Werror
xuelei
parents:
7179
diff
changeset
|
1435 |
@SuppressWarnings("unchecked") |
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
47216
diff
changeset
|
1436 |
@java.io.Serial |
2 | 1437 |
private void readObject(ObjectInputStream ois) |
1438 |
throws IOException, ClassNotFoundException |
|
1439 |
{ |
|
1440 |
ObjectInputStream.GetField fields = ois.readFields(); |
|
1441 |
subject = (Subject) fields.get("this$0", null); |
|
1442 |
which = fields.get("which", 0); |
|
20806
d94588b7854d
8015731: Subject java.security.auth.subject to improvements
weijun
parents:
14342
diff
changeset
|
1443 |
|
d94588b7854d
8015731: Subject java.security.auth.subject to improvements
weijun
parents:
14342
diff
changeset
|
1444 |
LinkedList<E> tmp = (LinkedList<E>) fields.get("elements", null); |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1445 |
|
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1446 |
Subject.collectionNullClean(tmp); |
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1447 |
|
20806
d94588b7854d
8015731: Subject java.security.auth.subject to improvements
weijun
parents:
14342
diff
changeset
|
1448 |
if (tmp.getClass() != LinkedList.class) { |
d94588b7854d
8015731: Subject java.security.auth.subject to improvements
weijun
parents:
14342
diff
changeset
|
1449 |
elements = new LinkedList<E>(tmp); |
d94588b7854d
8015731: Subject java.security.auth.subject to improvements
weijun
parents:
14342
diff
changeset
|
1450 |
} else { |
d94588b7854d
8015731: Subject java.security.auth.subject to improvements
weijun
parents:
14342
diff
changeset
|
1451 |
elements = tmp; |
d94588b7854d
8015731: Subject java.security.auth.subject to improvements
weijun
parents:
14342
diff
changeset
|
1452 |
} |
2 | 1453 |
} |
25188
e680ab7f208e
8015081: javax.security.auth.Subject.toString() throws NPE
ascarpino
parents:
23913
diff
changeset
|
1454 |
|
2 | 1455 |
} |
1456 |
||
1457 |
/** |
|
18830 | 1458 |
* This class implements a {@code Set} which returns only |
2 | 1459 |
* members that are an instance of a specified Class. |
1460 |
*/ |
|
1461 |
private class ClassSet<T> extends AbstractSet<T> { |
|
1462 |
||
1463 |
private int which; |
|
1464 |
private Class<T> c; |
|
1465 |
private Set<T> set; |
|
1466 |
||
1467 |
ClassSet(int which, Class<T> c) { |
|
1468 |
this.which = which; |
|
1469 |
this.c = c; |
|
1470 |
set = new HashSet<T>(); |
|
1471 |
||
1472 |
switch (which) { |
|
1473 |
case Subject.PRINCIPAL_SET: |
|
1474 |
synchronized(principals) { populateSet(); } |
|
1475 |
break; |
|
1476 |
case Subject.PUB_CREDENTIAL_SET: |
|
1477 |
synchronized(pubCredentials) { populateSet(); } |
|
1478 |
break; |
|
1479 |
default: |
|
1480 |
synchronized(privCredentials) { populateSet(); } |
|
1481 |
break; |
|
1482 |
} |
|
1483 |
} |
|
1484 |
||
10709
d865c9f21240
7092375: Security Libraries don't build with javac -Werror
xuelei
parents:
7179
diff
changeset
|
1485 |
@SuppressWarnings("unchecked") /*To suppress warning from line 1374*/ |
2 | 1486 |
private void populateSet() { |
1487 |
final Iterator<?> iterator; |
|
1488 |
switch(which) { |
|
1489 |
case Subject.PRINCIPAL_SET: |
|
1490 |
iterator = Subject.this.principals.iterator(); |
|
1491 |
break; |
|
1492 |
case Subject.PUB_CREDENTIAL_SET: |
|
1493 |
iterator = Subject.this.pubCredentials.iterator(); |
|
1494 |
break; |
|
1495 |
default: |
|
1496 |
iterator = Subject.this.privCredentials.iterator(); |
|
1497 |
break; |
|
1498 |
} |
|
1499 |
||
1500 |
// Check whether the caller has permisson to get |
|
1501 |
// credentials of Class c |
|
1502 |
||
1503 |
while (iterator.hasNext()) { |
|
1504 |
Object next; |
|
1505 |
if (which == Subject.PRIV_CREDENTIAL_SET) { |
|
1506 |
next = java.security.AccessController.doPrivileged |
|
30033
b9c86c17164a
8078468: Update security libraries to use diamond with anonymous classes
darcy
parents:
29492
diff
changeset
|
1507 |
(new java.security.PrivilegedAction<>() { |
2 | 1508 |
public Object run() { |
1509 |
return iterator.next(); |
|
1510 |
} |
|
1511 |
}); |
|
1512 |
} else { |
|
1513 |
next = iterator.next(); |
|
1514 |
} |
|
1515 |
if (c.isAssignableFrom(next.getClass())) { |
|
1516 |
if (which != Subject.PRIV_CREDENTIAL_SET) { |
|
1517 |
set.add((T)next); |
|
1518 |
} else { |
|
1519 |
// Check permission for private creds |
|
1520 |
SecurityManager sm = System.getSecurityManager(); |
|
1521 |
if (sm != null) { |
|
1522 |
sm.checkPermission(new PrivateCredentialPermission |
|
1523 |
(next.getClass().getName(), |
|
1524 |
Subject.this.getPrincipals())); |
|
1525 |
} |
|
1526 |
set.add((T)next); |
|
1527 |
} |
|
1528 |
} |
|
1529 |
} |
|
1530 |
} |
|
1531 |
||
30438
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
30033
diff
changeset
|
1532 |
@Override |
2 | 1533 |
public int size() { |
1534 |
return set.size(); |
|
1535 |
} |
|
1536 |
||
30438
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
30033
diff
changeset
|
1537 |
@Override |
2 | 1538 |
public Iterator<T> iterator() { |
1539 |
return set.iterator(); |
|
1540 |
} |
|
1541 |
||
30438
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
30033
diff
changeset
|
1542 |
@Override |
2 | 1543 |
public boolean add(T o) { |
1544 |
||
30438
c261149b9fff
8034820: Wrong isAssignableFrom test when adding Principal to Subject
mullan
parents:
30033
diff
changeset
|
1545 |
if (!c.isAssignableFrom(o.getClass())) { |
2 | 1546 |
MessageFormat form = new MessageFormat(ResourcesMgr.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
1547 |
("attempting.to.add.an.object.which.is.not.an.instance.of.class")); |
2 | 1548 |
Object[] source = {c.toString()}; |
1549 |
throw new SecurityException(form.format(source)); |
|
1550 |
} |
|
1551 |
||
1552 |
return set.add(o); |
|
1553 |
} |
|
1554 |
} |
|
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1555 |
|
25989
6a57ce3f21f1
7026255: Methods of Subject that throw SecurityException do not specify what permissions are required
mullan
parents:
25188
diff
changeset
|
1556 |
static final class AuthPermissionHolder { |
4331
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1557 |
static final AuthPermission DO_AS_PERMISSION = |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1558 |
new AuthPermission("doAs"); |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1559 |
|
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1560 |
static final AuthPermission DO_AS_PRIVILEGED_PERMISSION = |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1561 |
new AuthPermission("doAsPrivileged"); |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1562 |
|
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1563 |
static final AuthPermission SET_READ_ONLY_PERMISSION = |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1564 |
new AuthPermission("setReadOnly"); |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1565 |
|
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1566 |
static final AuthPermission GET_SUBJECT_PERMISSION = |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1567 |
new AuthPermission("getSubject"); |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1568 |
|
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1569 |
static final AuthPermission MODIFY_PRINCIPALS_PERMISSION = |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1570 |
new AuthPermission("modifyPrincipals"); |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1571 |
|
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1572 |
static final AuthPermission MODIFY_PUBLIC_CREDENTIALS_PERMISSION = |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1573 |
new AuthPermission("modifyPublicCredentials"); |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1574 |
|
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1575 |
static final AuthPermission MODIFY_PRIVATE_CREDENTIALS_PERMISSION = |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1576 |
new AuthPermission("modifyPrivateCredentials"); |
ba7050c934f2
6903638: Remove dependency on AuthPermission from SecurityConstants
mchung
parents:
2
diff
changeset
|
1577 |
} |
2 | 1578 |
} |