jdk/src/java.base/share/classes/java/security/Principal.java
author coleenp
Wed, 30 Aug 2017 19:18:22 -0400
changeset 47098 e704f55561c3
parent 45434 4582657c7260
permissions -rw-r--r--
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp Summary: Use load_acquire for accessing DictionaryEntry::_pd_set since it's accessed outside the SystemDictionary_lock Reviewed-by: zgu, twisti, dholmes, adinn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19828
b4f91bc595fe 8024432: Fix doclint issues in java.security
juh
parents: 15013
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This interface represents the abstract notion of a principal, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * can be used to represent any entity, such as an individual, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * corporation, and a login id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @see java.security.cert.X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public interface Principal {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Compares this principal to the specified object.  Returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * if the object passed in matches the principal represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * the implementation of this interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * @param another principal to compare with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * @return true if the principal passed in is the same as that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * encapsulated by this principal, and false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public boolean equals(Object another);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Returns a string representation of this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @return a string representation of this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Returns a hashcode for this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @return a hashcode for this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns the name of this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @return the name of this principal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
b4f91bc595fe 8024432: Fix doclint issues in java.security
juh
parents: 15013
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}