author | darcy |
Thu, 29 Aug 2019 10:52:21 -0700 | |
changeset 57950 | 4612a3cfb927 |
parent 53018 | 8bf9268df0e2 |
child 58519 | 6e017b301287 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
53018
diff
changeset
|
2 |
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.security.auth; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
import java.text.MessageFormat; |
|
30 |
import java.security.Permission; |
|
31 |
import java.security.PermissionCollection; |
|
32 |
import java.security.Principal; |
|
33 |
import sun.security.util.ResourcesMgr; |
|
34 |
||
35 |
/** |
|
36 |
* This class is used to protect access to private Credentials |
|
18830 | 37 |
* belonging to a particular {@code Subject}. The {@code Subject} |
2 | 38 |
* is represented by a Set of Principals. |
39 |
* |
|
18830 | 40 |
* <p> The target name of this {@code Permission} specifies |
2 | 41 |
* a Credential class name, and a Set of Principals. |
42 |
* The only valid value for this Permission's actions is, "read". |
|
43 |
* The target name must abide by the following syntax: |
|
44 |
* |
|
45 |
* <pre> |
|
46 |
* CredentialClass {PrincipalClass "PrincipalName"}* |
|
47 |
* </pre> |
|
48 |
* |
|
49 |
* For example, the following permission grants access to the |
|
50 |
* com.sun.PrivateCredential owned by Subjects which have |
|
51 |
* a com.sun.Principal with the name, "duke". Note that although |
|
52 |
* this example, as well as all the examples below, do not contain |
|
53 |
* Codebase, SignedBy, or Principal information in the grant statement |
|
54 |
* (for simplicity reasons), actual policy configurations should |
|
55 |
* specify that information when appropriate. |
|
56 |
* |
|
57 |
* <pre> |
|
58 |
* |
|
59 |
* grant { |
|
60 |
* permission javax.security.auth.PrivateCredentialPermission |
|
61 |
* "com.sun.PrivateCredential com.sun.Principal \"duke\"", |
|
62 |
* "read"; |
|
63 |
* }; |
|
64 |
* </pre> |
|
65 |
* |
|
66 |
* If CredentialClass is "*", then access is granted to |
|
67 |
* all private Credentials belonging to the specified |
|
18830 | 68 |
* {@code Subject}. |
2 | 69 |
* If "PrincipalName" is "*", then access is granted to the |
18830 | 70 |
* specified Credential owned by any {@code Subject} that has the |
71 |
* specified {@code Principal} (the actual PrincipalName doesn't matter). |
|
2 | 72 |
* For example, the following grants access to the |
18830 | 73 |
* a.b.Credential owned by any {@code Subject} that has |
2 | 74 |
* an a.b.Principal. |
75 |
* |
|
76 |
* <pre> |
|
77 |
* grant { |
|
78 |
* permission javax.security.auth.PrivateCredentialPermission |
|
79 |
* "a.b.Credential a.b.Principal "*"", |
|
80 |
* "read"; |
|
81 |
* }; |
|
82 |
* </pre> |
|
83 |
* |
|
84 |
* If both the PrincipalClass and "PrincipalName" are "*", |
|
85 |
* then access is granted to the specified Credential owned by |
|
18830 | 86 |
* any {@code Subject}. |
2 | 87 |
* |
88 |
* <p> In addition, the PrincipalClass/PrincipalName pairing may be repeated: |
|
89 |
* |
|
90 |
* <pre> |
|
91 |
* grant { |
|
92 |
* permission javax.security.auth.PrivateCredentialPermission |
|
93 |
* "a.b.Credential a.b.Principal "duke" c.d.Principal "dukette"", |
|
94 |
* "read"; |
|
95 |
* }; |
|
96 |
* </pre> |
|
97 |
* |
|
98 |
* The above grants access to the private Credential, "a.b.Credential", |
|
18830 | 99 |
* belonging to a {@code Subject} with at least two associated Principals: |
2 | 100 |
* "a.b.Principal" with the name, "duke", and "c.d.Principal", with the name, |
101 |
* "dukette". |
|
102 |
* |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
29492
diff
changeset
|
103 |
* @since 1.4 |
2 | 104 |
*/ |
105 |
public final class PrivateCredentialPermission extends Permission { |
|
106 |
||
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
53018
diff
changeset
|
107 |
@java.io.Serial |
2 | 108 |
private static final long serialVersionUID = 5284372143517237068L; |
109 |
||
110 |
private static final CredOwner[] EMPTY_PRINCIPALS = new CredOwner[0]; |
|
111 |
||
112 |
/** |
|
113 |
* @serial |
|
114 |
*/ |
|
115 |
private String credentialClass; |
|
116 |
||
117 |
/** |
|
118 |
* @serial The Principals associated with this permission. |
|
119 |
* The set contains elements of type, |
|
18830 | 120 |
* {@code PrivateCredentialPermission.CredOwner}. |
2 | 121 |
*/ |
10709
d865c9f21240
7092375: Security Libraries don't build with javac -Werror
xuelei
parents:
9035
diff
changeset
|
122 |
private Set<Principal> principals; // ignored - kept around for compatibility |
2 | 123 |
private transient CredOwner[] credOwners; |
124 |
||
125 |
/** |
|
126 |
* @serial |
|
127 |
*/ |
|
128 |
private boolean testing = false; |
|
129 |
||
130 |
/** |
|
18830 | 131 |
* Create a new {@code PrivateCredentialPermission} |
132 |
* with the specified {@code credentialClass} and Principals. |
|
2 | 133 |
*/ |
134 |
PrivateCredentialPermission(String credentialClass, |
|
135 |
Set<Principal> principals) { |
|
136 |
||
137 |
super(credentialClass); |
|
138 |
this.credentialClass = credentialClass; |
|
139 |
||
140 |
synchronized(principals) { |
|
141 |
if (principals.size() == 0) { |
|
142 |
this.credOwners = EMPTY_PRINCIPALS; |
|
143 |
} else { |
|
144 |
this.credOwners = new CredOwner[principals.size()]; |
|
145 |
int index = 0; |
|
146 |
Iterator<Principal> i = principals.iterator(); |
|
147 |
while (i.hasNext()) { |
|
148 |
Principal p = i.next(); |
|
149 |
this.credOwners[index++] = new CredOwner |
|
150 |
(p.getClass().getName(), |
|
151 |
p.getName()); |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
/** |
|
18830 | 158 |
* Creates a new {@code PrivateCredentialPermission} |
159 |
* with the specified {@code name}. The {@code name} |
|
160 |
* specifies both a Credential class and a {@code Principal} Set. |
|
2 | 161 |
* |
162 |
* @param name the name specifying the Credential class and |
|
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
163 |
* {@code Principal} Set. |
2 | 164 |
* |
165 |
* @param actions the actions specifying that the Credential can be read. |
|
166 |
* |
|
18830 | 167 |
* @throws IllegalArgumentException if {@code name} does not conform |
168 |
* to the correct syntax or if {@code actions} is not "read". |
|
2 | 169 |
*/ |
170 |
public PrivateCredentialPermission(String name, String actions) { |
|
171 |
super(name); |
|
172 |
||
173 |
if (!"read".equalsIgnoreCase(actions)) |
|
174 |
throw new IllegalArgumentException |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
175 |
(ResourcesMgr.getString("actions.can.only.be.read.")); |
2 | 176 |
init(name); |
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* Returns the Class name of the Credential associated with this |
|
18830 | 181 |
* {@code PrivateCredentialPermission}. |
2 | 182 |
* |
183 |
* @return the Class name of the Credential associated with this |
|
18830 | 184 |
* {@code PrivateCredentialPermission}. |
2 | 185 |
*/ |
186 |
public String getCredentialClass() { |
|
187 |
return credentialClass; |
|
188 |
} |
|
189 |
||
190 |
/** |
|
18830 | 191 |
* Returns the {@code Principal} classes and names |
192 |
* associated with this {@code PrivateCredentialPermission}. |
|
2 | 193 |
* The information is returned as a two-dimensional array (array[x][y]). |
18830 | 194 |
* The 'x' value corresponds to the number of {@code Principal} |
2 | 195 |
* class and name pairs. When (y==0), it corresponds to |
18830 | 196 |
* the {@code Principal} class value, and when (y==1), |
197 |
* it corresponds to the {@code Principal} name value. |
|
2 | 198 |
* For example, array[0][0] corresponds to the class name of |
18830 | 199 |
* the first {@code Principal} in the array. array[0][1] |
200 |
* corresponds to the {@code Principal} name of the |
|
201 |
* first {@code Principal} in the array. |
|
2 | 202 |
* |
18830 | 203 |
* @return the {@code Principal} class and names associated |
204 |
* with this {@code PrivateCredentialPermission}. |
|
2 | 205 |
*/ |
206 |
public String[][] getPrincipals() { |
|
207 |
||
208 |
if (credOwners == null || credOwners.length == 0) { |
|
209 |
return new String[0][0]; |
|
210 |
} |
|
211 |
||
212 |
String[][] pArray = new String[credOwners.length][2]; |
|
213 |
for (int i = 0; i < credOwners.length; i++) { |
|
214 |
pArray[i][0] = credOwners[i].principalClass; |
|
215 |
pArray[i][1] = credOwners[i].principalName; |
|
216 |
} |
|
217 |
return pArray; |
|
218 |
} |
|
219 |
||
220 |
/** |
|
18830 | 221 |
* Checks if this {@code PrivateCredentialPermission} implies |
222 |
* the specified {@code Permission}. |
|
2 | 223 |
* |
224 |
* <p> |
|
225 |
* |
|
226 |
* This method returns true if: |
|
21955 | 227 |
* <ul> |
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
228 |
* <li> {@code p} is an instanceof PrivateCredentialPermission and |
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
229 |
* <li> the target name for {@code p} is implied by this object's |
2 | 230 |
* target name. For example: |
231 |
* <pre> |
|
232 |
* [* P1 "duke"] implies [a.b.Credential P1 "duke"]. |
|
233 |
* [C1 P1 "duke"] implies [C1 P1 "duke" P2 "dukette"]. |
|
234 |
* [C1 P2 "dukette"] implies [C1 P1 "duke" P2 "dukette"]. |
|
235 |
* </pre> |
|
236 |
* </ul> |
|
237 |
* |
|
18830 | 238 |
* @param p the {@code Permission} to check against. |
2 | 239 |
* |
18830 | 240 |
* @return true if this {@code PrivateCredentialPermission} implies |
241 |
* the specified {@code Permission}, false if not. |
|
2 | 242 |
*/ |
243 |
public boolean implies(Permission p) { |
|
244 |
||
245 |
if (p == null || !(p instanceof PrivateCredentialPermission)) |
|
246 |
return false; |
|
247 |
||
248 |
PrivateCredentialPermission that = (PrivateCredentialPermission)p; |
|
249 |
||
250 |
if (!impliesCredentialClass(credentialClass, that.credentialClass)) |
|
251 |
return false; |
|
252 |
||
253 |
return impliesPrincipalSet(credOwners, that.credOwners); |
|
254 |
} |
|
255 |
||
256 |
/** |
|
18830 | 257 |
* Checks two {@code PrivateCredentialPermission} objects for |
29492
a4bf9a570035
8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents:
25859
diff
changeset
|
258 |
* equality. Checks that {@code obj} is a |
18830 | 259 |
* {@code PrivateCredentialPermission}, |
2 | 260 |
* and has the same credential class as this object, |
261 |
* as well as the same Principals as this object. |
|
262 |
* The order of the Principals in the respective Permission's |
|
263 |
* target names is not relevant. |
|
264 |
* |
|
265 |
* @param obj the object we are testing for equality with this object. |
|
266 |
* |
|
18830 | 267 |
* @return true if obj is a {@code PrivateCredentialPermission}, |
2 | 268 |
* has the same credential class as this object, |
269 |
* and has the same Principals as this object. |
|
270 |
*/ |
|
271 |
public boolean equals(Object obj) { |
|
272 |
if (obj == this) |
|
273 |
return true; |
|
274 |
||
275 |
if (! (obj instanceof PrivateCredentialPermission)) |
|
276 |
return false; |
|
277 |
||
278 |
PrivateCredentialPermission that = (PrivateCredentialPermission)obj; |
|
279 |
||
280 |
return (this.implies(that) && that.implies(this)); |
|
281 |
} |
|
282 |
||
283 |
/** |
|
284 |
* Returns the hash code value for this object. |
|
285 |
* |
|
286 |
* @return a hash code value for this object. |
|
287 |
*/ |
|
288 |
public int hashCode() { |
|
289 |
return this.credentialClass.hashCode(); |
|
290 |
} |
|
291 |
||
292 |
/** |
|
293 |
* Returns the "canonical string representation" of the actions. |
|
294 |
* This method always returns the String, "read". |
|
295 |
* |
|
296 |
* @return the actions (always returns "read"). |
|
297 |
*/ |
|
298 |
public String getActions() { |
|
299 |
return "read"; |
|
300 |
} |
|
301 |
||
302 |
/** |
|
303 |
* Return a homogeneous collection of PrivateCredentialPermissions |
|
18830 | 304 |
* in a {@code PermissionCollection}. |
305 |
* No such {@code PermissionCollection} is defined, |
|
306 |
* so this method always returns {@code null}. |
|
2 | 307 |
* |
308 |
* @return null in all cases. |
|
309 |
*/ |
|
310 |
public PermissionCollection newPermissionCollection() { |
|
311 |
return null; |
|
312 |
} |
|
313 |
||
314 |
private void init(String name) { |
|
315 |
||
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
47216
diff
changeset
|
316 |
if (name == null || name.trim().isEmpty()) { |
2 | 317 |
throw new IllegalArgumentException("invalid empty name"); |
318 |
} |
|
319 |
||
7970
af1579474d16
7008728: diamond conversion of basic security, permissions, authentication
smarks
parents:
7179
diff
changeset
|
320 |
ArrayList<CredOwner> pList = new ArrayList<>(); |
2 | 321 |
StringTokenizer tokenizer = new StringTokenizer(name, " ", true); |
322 |
String principalClass = null; |
|
323 |
String principalName = null; |
|
324 |
||
325 |
if (testing) |
|
326 |
System.out.println("whole name = " + name); |
|
327 |
||
328 |
// get the Credential Class |
|
329 |
credentialClass = tokenizer.nextToken(); |
|
330 |
if (testing) |
|
331 |
System.out.println("Credential Class = " + credentialClass); |
|
332 |
||
333 |
if (tokenizer.hasMoreTokens() == false) { |
|
334 |
MessageFormat form = new MessageFormat(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
335 |
("permission.name.name.syntax.invalid.")); |
2 | 336 |
Object[] source = {name}; |
337 |
throw new IllegalArgumentException |
|
338 |
(form.format(source) + ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
339 |
("Credential.Class.not.followed.by.a.Principal.Class.and.Name")); |
2 | 340 |
} |
341 |
||
342 |
while (tokenizer.hasMoreTokens()) { |
|
343 |
||
344 |
// skip delimiter |
|
345 |
tokenizer.nextToken(); |
|
346 |
||
347 |
// get the Principal Class |
|
348 |
principalClass = tokenizer.nextToken(); |
|
349 |
if (testing) |
|
350 |
System.out.println(" Principal Class = " + principalClass); |
|
351 |
||
352 |
if (tokenizer.hasMoreTokens() == false) { |
|
353 |
MessageFormat form = new MessageFormat(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
354 |
("permission.name.name.syntax.invalid.")); |
2 | 355 |
Object[] source = {name}; |
356 |
throw new IllegalArgumentException |
|
357 |
(form.format(source) + ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
358 |
("Principal.Class.not.followed.by.a.Principal.Name")); |
2 | 359 |
} |
360 |
||
361 |
// skip delimiter |
|
362 |
tokenizer.nextToken(); |
|
363 |
||
364 |
// get the Principal Name |
|
365 |
principalName = tokenizer.nextToken(); |
|
366 |
||
367 |
if (!principalName.startsWith("\"")) { |
|
368 |
MessageFormat form = new MessageFormat(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
369 |
("permission.name.name.syntax.invalid.")); |
2 | 370 |
Object[] source = {name}; |
371 |
throw new IllegalArgumentException |
|
372 |
(form.format(source) + ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
373 |
("Principal.Name.must.be.surrounded.by.quotes")); |
2 | 374 |
} |
375 |
||
376 |
if (!principalName.endsWith("\"")) { |
|
377 |
||
378 |
// we have a name with spaces in it -- |
|
379 |
// keep parsing until we find the end quote, |
|
380 |
// and keep the spaces in the name |
|
381 |
||
382 |
while (tokenizer.hasMoreTokens()) { |
|
383 |
principalName = principalName + tokenizer.nextToken(); |
|
384 |
if (principalName.endsWith("\"")) |
|
385 |
break; |
|
386 |
} |
|
387 |
||
388 |
if (!principalName.endsWith("\"")) { |
|
389 |
MessageFormat form = new MessageFormat |
|
390 |
(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
391 |
("permission.name.name.syntax.invalid.")); |
2 | 392 |
Object[] source = {name}; |
393 |
throw new IllegalArgumentException |
|
394 |
(form.format(source) + ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
395 |
("Principal.Name.missing.end.quote")); |
2 | 396 |
} |
397 |
} |
|
398 |
||
399 |
if (testing) |
|
400 |
System.out.println("\tprincipalName = '" + principalName + "'"); |
|
401 |
||
402 |
principalName = principalName.substring |
|
403 |
(1, principalName.length() - 1); |
|
404 |
||
405 |
if (principalClass.equals("*") && |
|
406 |
!principalName.equals("*")) { |
|
407 |
throw new IllegalArgumentException(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
408 |
("PrivateCredentialPermission.Principal.Class.can.not.be.a.wildcard.value.if.Principal.Name.is.not.a.wildcard.value")); |
2 | 409 |
} |
410 |
||
411 |
if (testing) |
|
412 |
System.out.println("\tprincipalName = '" + principalName + "'"); |
|
413 |
||
414 |
pList.add(new CredOwner(principalClass, principalName)); |
|
415 |
} |
|
416 |
||
417 |
this.credOwners = new CredOwner[pList.size()]; |
|
418 |
pList.toArray(this.credOwners); |
|
419 |
} |
|
420 |
||
421 |
private boolean impliesCredentialClass(String thisC, String thatC) { |
|
422 |
||
423 |
// this should never happen |
|
424 |
if (thisC == null || thatC == null) |
|
425 |
return false; |
|
426 |
||
427 |
if (testing) |
|
428 |
System.out.println("credential class comparison: " + |
|
429 |
thisC + "/" + thatC); |
|
430 |
||
431 |
if (thisC.equals("*")) |
|
432 |
return true; |
|
433 |
||
434 |
/** |
|
435 |
* XXX let's not enable this for now -- |
|
436 |
* if people want it, we'll enable it later |
|
437 |
*/ |
|
438 |
/* |
|
439 |
if (thisC.endsWith("*")) { |
|
440 |
String cClass = thisC.substring(0, thisC.length() - 2); |
|
441 |
return thatC.startsWith(cClass); |
|
442 |
} |
|
443 |
*/ |
|
444 |
||
445 |
return thisC.equals(thatC); |
|
446 |
} |
|
447 |
||
448 |
private boolean impliesPrincipalSet(CredOwner[] thisP, CredOwner[] thatP) { |
|
449 |
||
450 |
// this should never happen |
|
451 |
if (thisP == null || thatP == null) |
|
452 |
return false; |
|
453 |
||
454 |
if (thatP.length == 0) |
|
455 |
return true; |
|
456 |
||
457 |
if (thisP.length == 0) |
|
458 |
return false; |
|
459 |
||
460 |
for (int i = 0; i < thisP.length; i++) { |
|
461 |
boolean foundMatch = false; |
|
462 |
for (int j = 0; j < thatP.length; j++) { |
|
463 |
if (thisP[i].implies(thatP[j])) { |
|
464 |
foundMatch = true; |
|
465 |
break; |
|
466 |
} |
|
467 |
} |
|
468 |
if (!foundMatch) { |
|
469 |
return false; |
|
470 |
} |
|
471 |
} |
|
472 |
return true; |
|
473 |
} |
|
474 |
||
475 |
/** |
|
476 |
* Reads this object from a stream (i.e., deserializes it) |
|
477 |
*/ |
|
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
53018
diff
changeset
|
478 |
@java.io.Serial |
2 | 479 |
private void readObject(java.io.ObjectInputStream s) throws |
480 |
java.io.IOException, |
|
481 |
ClassNotFoundException { |
|
482 |
||
483 |
s.defaultReadObject(); |
|
484 |
||
485 |
// perform new initialization from the permission name |
|
486 |
||
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
21955
diff
changeset
|
487 |
if (getName().indexOf(' ') == -1 && getName().indexOf('"') == -1) { |
2 | 488 |
|
489 |
// name only has a credential class specified |
|
490 |
credentialClass = getName(); |
|
491 |
credOwners = EMPTY_PRINCIPALS; |
|
492 |
||
493 |
} else { |
|
494 |
||
495 |
// perform regular initialization |
|
496 |
init(getName()); |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
/** |
|
501 |
* @serial include |
|
502 |
*/ |
|
503 |
static class CredOwner implements java.io.Serializable { |
|
504 |
||
57950
4612a3cfb927
8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents:
53018
diff
changeset
|
505 |
@java.io.Serial |
2 | 506 |
private static final long serialVersionUID = -5607449830436408266L; |
507 |
||
508 |
/** |
|
509 |
* @serial |
|
510 |
*/ |
|
511 |
String principalClass; |
|
512 |
/** |
|
513 |
* @serial |
|
514 |
*/ |
|
515 |
String principalName; |
|
516 |
||
517 |
CredOwner(String principalClass, String principalName) { |
|
518 |
this.principalClass = principalClass; |
|
519 |
this.principalName = principalName; |
|
520 |
} |
|
521 |
||
522 |
public boolean implies(Object obj) { |
|
523 |
if (obj == null || !(obj instanceof CredOwner)) |
|
524 |
return false; |
|
525 |
||
526 |
CredOwner that = (CredOwner)obj; |
|
527 |
||
528 |
if (principalClass.equals("*") || |
|
529 |
principalClass.equals(that.principalClass)) { |
|
530 |
||
531 |
if (principalName.equals("*") || |
|
532 |
principalName.equals(that.principalName)) { |
|
533 |
return true; |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
/** |
|
538 |
* XXX no code yet to support a.b.* |
|
539 |
*/ |
|
540 |
||
541 |
return false; |
|
542 |
} |
|
543 |
||
544 |
public String toString() { |
|
545 |
MessageFormat form = new MessageFormat(ResourcesMgr.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
546 |
("CredOwner.Principal.Class.class.Principal.Name.name")); |
2 | 547 |
Object[] source = {principalClass, principalName}; |
548 |
return (form.format(source)); |
|
549 |
} |
|
550 |
} |
|
551 |
} |