1/*2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.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 it6 * under the terms of the GNU General Public License version 2 only, as7 * published by the Free Software Foundation. Oracle designates this8 * particular file as subject to the "Classpath" exception as provided9 * by Oracle in the LICENSE file that accompanied this code.10 *11 * This code is distributed in the hope that it will be useful, but WITHOUT12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License14 * version 2 for more details (a copy is included in the LICENSE file that15 * accompanied this code).16 *17 * You should have received a copy of the GNU General Public License version18 * 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 *21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA22 * or visit www.oracle.com if you need additional information or have any23 * questions.24 */2526package java.security;
2728import javax.security.auth.Subject;
2930/**31 * This interface represents the abstract notion of a principal, which32 * can be used to represent any entity, such as an individual, a33 * corporation, and a login id.34 *35 * @see java.security.cert.X509Certificate36 *37 * @author Li Gong38 */39publicinterfacePrincipal {
4041/**42 * Compares this principal to the specified object. Returns true43 * if the object passed in matches the principal represented by44 * the implementation of this interface.45 *46 * @param another principal to compare with.47 *48 * @return true if the principal passed in is the same as that49 * encapsulated by this principal, and false otherwise.50 */51publicboolean equals(Object another);
5253/**54 * Returns a string representation of this principal.55 *56 * @return a string representation of this principal.57 */58publicString toString();
5960/**61 * Returns a hashcode for this principal.62 *63 * @return a hashcode for this principal.64 */65publicint hashCode();
6667/**68 * Returns the name of this principal.69 *70 * @return the name of this principal.71 */72publicString getName();
7374/**75 * Returns true if the specified subject is implied by this principal.76 *77 * <p>The default implementation of this method returns true if78 * {@code subject} is non-null and contains at least one principal that79 * is equal to this principal.80 *81 * <p>Subclasses may override this with a different implementation, if82 * necessary.83 *84 * @param subject the {@code Subject}85 * @return true if {@code subject} is non-null and is86 * implied by this principal, or false otherwise.87 * @since 1.888 */89publicdefaultboolean implies(Subject subject) {
90if (subject == null)
91return false;
92return subject.getPrincipals().contains(this);
93 }
94 }