Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/NTUserPrincipal.java
38924 views
/*1* Copyright (c) 1999, 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 Windows NT user.32*33* <p> Principals such as this <code>NTUserPrincipal</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 NTUserPrincipal implements Principal, java.io.Serializable {4546private static final long serialVersionUID = -8737649811939033735L;4748/**49* @serial50*/51private String name;5253/**54* Create an <code>NTUserPrincipal</code> with a Windows NT username.55*56* <p>57*58* @param name the Windows NT username for this user. <p>59*60* @exception NullPointerException if the <code>name</code>61* is <code>null</code>.62*/63public NTUserPrincipal(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}72this.name = name;73}7475/**76* Return the Windows NT username for this <code>NTPrincipal</code>.77*78* <p>79*80* @return the Windows NT username for this <code>NTPrincipal</code>81*/82public String getName() {83return name;84}8586/**87* Return a string representation of this <code>NTPrincipal</code>.88*89* <p>90*91* @return a string representation of this <code>NTPrincipal</code>.92*/93public String toString() {94java.text.MessageFormat form = new java.text.MessageFormat95(sun.security.util.ResourcesMgr.getString96("NTUserPrincipal.name",97"sun.security.util.AuthResources"));98Object[] source = {name};99return form.format(source);100}101102/**103* Compares the specified Object with this <code>NTUserPrincipal</code>104* for equality. Returns true if the given object is also a105* <code>NTUserPrincipal</code> and the two NTUserPrincipals106* have the same name.107*108* <p>109*110* @param o Object to be compared for equality with this111* <code>NTPrincipal</code>.112*113* @return true if the specified Object is equal equal to this114* <code>NTPrincipal</code>.115*/116public boolean equals(Object o) {117if (o == null)118return false;119120if (this == o)121return true;122123if (!(o instanceof NTUserPrincipal))124return false;125NTUserPrincipal that = (NTUserPrincipal)o;126127if (name.equals(that.getName()))128return true;129return false;130}131132/**133* Return a hash code for this <code>NTUserPrincipal</code>.134*135* <p>136*137* @return a hash code for this <code>NTUserPrincipal</code>.138*/139public int hashCode() {140return this.getName().hashCode();141}142}143144145