Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/UnixNumericUserPrincipal.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 user's Unix identification number (UID).32*33* <p> Principals such as this <code>UnixNumericUserPrincipal</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 UnixNumericUserPrincipal implements45Principal,46java.io.Serializable {47private static final long serialVersionUID = -4329764253802397821L;4849/**50* @serial51*/52private String name;5354/**55* Create a <code>UnixNumericUserPrincipal</code> using a56* <code>String</code> representation of the57* user's identification number (UID).58*59* <p>60*61* @param name the user identification number (UID) for this user.62*63* @exception NullPointerException if the <code>name</code>64* is <code>null</code>.65*/66public UnixNumericUserPrincipal(String name) {67if (name == null) {68java.text.MessageFormat form = new java.text.MessageFormat69(sun.security.util.ResourcesMgr.getString70("invalid.null.input.value",71"sun.security.util.AuthResources"));72Object[] source = {"name"};73throw new NullPointerException(form.format(source));74}7576this.name = name;77}7879/**80* Create a <code>UnixNumericUserPrincipal</code> using a81* long representation of the user's identification number (UID).82*83* <p>84*85* @param name the user identification number (UID) for this user86* represented as a long.87*/88public UnixNumericUserPrincipal(long name) {89this.name = (new Long(name)).toString();90}9192/**93* Return the user identification number (UID) for this94* <code>UnixNumericUserPrincipal</code>.95*96* <p>97*98* @return the user identification number (UID) for this99* <code>UnixNumericUserPrincipal</code>100*/101public String getName() {102return name;103}104105/**106* Return the user identification number (UID) for this107* <code>UnixNumericUserPrincipal</code> as a long.108*109* <p>110*111* @return the user identification number (UID) for this112* <code>UnixNumericUserPrincipal</code> as a long.113*/114public long longValue() {115return ((new Long(name)).longValue());116}117118/**119* Return a string representation of this120* <code>UnixNumericUserPrincipal</code>.121*122* <p>123*124* @return a string representation of this125* <code>UnixNumericUserPrincipal</code>.126*/127public String toString() {128java.text.MessageFormat form = new java.text.MessageFormat129(sun.security.util.ResourcesMgr.getString130("UnixNumericUserPrincipal.name",131"sun.security.util.AuthResources"));132Object[] source = {name};133return form.format(source);134}135136/**137* Compares the specified Object with this138* <code>UnixNumericUserPrincipal</code>139* for equality. Returns true if the given object is also a140* <code>UnixNumericUserPrincipal</code> and the two141* UnixNumericUserPrincipals142* have the same user identification number (UID).143*144* <p>145*146* @param o Object to be compared for equality with this147* <code>UnixNumericUserPrincipal</code>.148*149* @return true if the specified Object is equal equal to this150* <code>UnixNumericUserPrincipal</code>.151*/152public boolean equals(Object o) {153if (o == null)154return false;155156if (this == o)157return true;158159if (!(o instanceof UnixNumericUserPrincipal))160return false;161UnixNumericUserPrincipal that = (UnixNumericUserPrincipal)o;162163if (this.getName().equals(that.getName()))164return true;165return false;166}167168/**169* Return a hash code for this <code>UnixNumericUserPrincipal</code>.170*171* <p>172*173* @return a hash code for this <code>UnixNumericUserPrincipal</code>.174*/175public int hashCode() {176return name.hashCode();177}178}179180181