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