Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/UnixPrincipal.java
38924 views
/*1* Copyright (c) 2000, 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* <p> This class implements the <code>Principal</code> interface31* and represents a Unix user.32*33* <p> Principals such as this <code>UnixPrincipal</code>34* may be associated with a particular <code>Subject</code>35* to augment that <code>Subject</code> with an additional36* identity. Refer to the <code>Subject</code> class for more information37* on how to achieve this. Authorization decisions can then be based upon38* the Principals associated with a <code>Subject</code>.39*40* @see java.security.Principal41* @see javax.security.auth.Subject42*/43@jdk.Exported44public class UnixPrincipal implements Principal, java.io.Serializable {4546private static final long serialVersionUID = -2951667807323493631L;4748/**49* @serial50*/51private String name;5253/**54* Create a UnixPrincipal with a Unix username.55*56* <p>57*58* @param name the Unix username for this user.59*60* @exception NullPointerException if the <code>name</code>61* is <code>null</code>.62*/63public UnixPrincipal(String name) {64if (name == null) {65java.text.MessageFormat form = new java.text.MessageFormat66(sun.security.util.ResourcesMgr.getString67("invalid.null.input.value",68"sun.security.util.AuthResources"));69Object[] source = {"name"};70throw new NullPointerException(form.format(source));71}7273this.name = name;74}7576/**77* Return the Unix username for this <code>UnixPrincipal</code>.78*79* <p>80*81* @return the Unix username for this <code>UnixPrincipal</code>82*/83public String getName() {84return name;85}8687/**88* Return a string representation of this <code>UnixPrincipal</code>.89*90* <p>91*92* @return a string representation of this <code>UnixPrincipal</code>.93*/94public String toString() {95java.text.MessageFormat form = new java.text.MessageFormat96(sun.security.util.ResourcesMgr.getString97("UnixPrincipal.name",98"sun.security.util.AuthResources"));99Object[] source = {name};100return form.format(source);101}102103/**104* Compares the specified Object with this <code>UnixPrincipal</code>105* for equality. Returns true if the given object is also a106* <code>UnixPrincipal</code> and the two UnixPrincipals107* have the same username.108*109* <p>110*111* @param o Object to be compared for equality with this112* <code>UnixPrincipal</code>.113*114* @return true if the specified Object is equal equal to this115* <code>UnixPrincipal</code>.116*/117public boolean equals(Object o) {118if (o == null)119return false;120121if (this == o)122return true;123124if (!(o instanceof UnixPrincipal))125return false;126UnixPrincipal that = (UnixPrincipal)o;127128if (this.getName().equals(that.getName()))129return true;130return false;131}132133/**134* Return a hash code for this <code>UnixPrincipal</code>.135*136* <p>137*138* @return a hash code for this <code>UnixPrincipal</code>.139*/140public int hashCode() {141return name.hashCode();142}143}144145146