author | coleenp |
Wed, 30 Aug 2017 19:18:22 -0400 | |
changeset 47098 | e704f55561c3 |
parent 45434 | 4582657c7260 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
19828 | 2 |
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.security; |
|
27 |
||
15013
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
28 |
import javax.security.auth.Subject; |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
29 |
|
2 | 30 |
/** |
31 |
* This interface represents the abstract notion of a principal, which |
|
32 |
* can be used to represent any entity, such as an individual, a |
|
33 |
* corporation, and a login id. |
|
34 |
* |
|
35 |
* @see java.security.cert.X509Certificate |
|
36 |
* |
|
37 |
* @author Li Gong |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
27771
diff
changeset
|
38 |
* @since 1.1 |
2 | 39 |
*/ |
40 |
public interface Principal { |
|
41 |
||
42 |
/** |
|
43 |
* Compares this principal to the specified object. Returns true |
|
44 |
* if the object passed in matches the principal represented by |
|
45 |
* the implementation of this interface. |
|
46 |
* |
|
47 |
* @param another principal to compare with. |
|
48 |
* |
|
49 |
* @return true if the principal passed in is the same as that |
|
50 |
* encapsulated by this principal, and false otherwise. |
|
51 |
*/ |
|
52 |
public boolean equals(Object another); |
|
53 |
||
54 |
/** |
|
55 |
* Returns a string representation of this principal. |
|
56 |
* |
|
57 |
* @return a string representation of this principal. |
|
58 |
*/ |
|
59 |
public String toString(); |
|
60 |
||
61 |
/** |
|
62 |
* Returns a hashcode for this principal. |
|
63 |
* |
|
64 |
* @return a hashcode for this principal. |
|
65 |
*/ |
|
66 |
public int hashCode(); |
|
67 |
||
68 |
/** |
|
69 |
* Returns the name of this principal. |
|
70 |
* |
|
71 |
* @return the name of this principal. |
|
72 |
*/ |
|
73 |
public String getName(); |
|
15013
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
74 |
|
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
75 |
/** |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
76 |
* Returns true if the specified subject is implied by this principal. |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
77 |
* |
27771
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
78 |
* @implSpec |
360714d431ab
8061253: Spec cleanup for some security-related classes
weijun
parents:
25859
diff
changeset
|
79 |
* The default implementation of this method returns true if |
15013
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
80 |
* {@code subject} is non-null and contains at least one principal that |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
81 |
* is equal to this principal. |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
82 |
* |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
83 |
* <p>Subclasses may override this with a different implementation, if |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
84 |
* necessary. |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
85 |
* |
19828 | 86 |
* @param subject the {@code Subject} |
15013
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
87 |
* @return true if {@code subject} is non-null and is |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
88 |
* implied by this principal, or false otherwise. |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
89 |
* @since 1.8 |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
90 |
*/ |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
91 |
public default boolean implies(Subject subject) { |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
92 |
if (subject == null) |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
93 |
return false; |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
94 |
return subject.getPrincipals().contains(this); |
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
5506
diff
changeset
|
95 |
} |
2 | 96 |
} |