Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/UserPrincipal.java
38924 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.security.auth;2627import java.security.Principal;2829/**30* A user principal identified by a username or account name.31*32* <p>33* After successful authentication, a user {@link java.security.Principal}34* can be associated with a particular {@link javax.security.auth.Subject}35* to augment that <code>Subject</code> with an additional identity.36* Authorization decisions can then be based upon the37* <code>Principal</code>s that are associated with a <code>Subject</code>.38*39* <p>40* This class is immutable.41*42* @since 1.643*/44@jdk.Exported45public final class UserPrincipal implements Principal, java.io.Serializable {4647private static final long serialVersionUID = 892106070870210969L;4849/**50* The principal's name51*52* @serial53*/54private final String name;5556/**57* Creates a principal.58*59* @param name The principal's string name.60* @exception NullPointerException If the <code>name</code> is61* <code>null</code>.62*/63public UserPrincipal(String name) {64if (name == null) {65throw new NullPointerException("null name is illegal");66}67this.name = name;68}6970/**71* Compares this principal to the specified object.72*73* @param object The object to compare this principal against.74* @return true if they are equal; false otherwise.75*/76public boolean equals(Object object) {77if (this == object) {78return true;79}80if (object instanceof UserPrincipal) {81return name.equals(((UserPrincipal)object).getName());82}83return false;84}8586/**87* Returns a hash code for this principal.88*89* @return The principal's hash code.90*/91public int hashCode() {92return name.hashCode();93}9495/**96* Returns the name of this principal.97*98* @return The principal's name.99*/100public String getName() {101return name;102}103104/**105* Returns a string representation of this principal.106*107* @return The principal's name.108*/109public String toString() {110return name;111}112}113114115