Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/NTDomainPrincipal.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 the name of the Windows NT domain into which the32* user authenticated. This will be a domain name if the user logged33* into a Windows NT domain, a workgroup name if the user logged into34* a workgroup, or a machine name if the user logged into a standalone35* configuration.36*37* <p> Principals such as this <code>NTDomainPrincipal</code>38* may be associated with a particular <code>Subject</code>39* to augment that <code>Subject</code> with an additional40* identity. Refer to the <code>Subject</code> class for more information41* on how to achieve this. Authorization decisions can then be based upon42* the Principals associated with a <code>Subject</code>.43*44* @see java.security.Principal45* @see javax.security.auth.Subject46*/47@jdk.Exported48public class NTDomainPrincipal implements Principal, java.io.Serializable {4950private static final long serialVersionUID = -4408637351440771220L;5152/**53* @serial54*/55private String name;5657/**58* Create an <code>NTDomainPrincipal</code> with a Windows NT domain name.59*60* <p>61*62* @param name the Windows NT domain name for this user. <p>63*64* @exception NullPointerException if the <code>name</code>65* is <code>null</code>.66*/67public NTDomainPrincipal(String name) {68if (name == null) {69java.text.MessageFormat form = new java.text.MessageFormat70(sun.security.util.ResourcesMgr.getString71("invalid.null.input.value",72"sun.security.util.AuthResources"));73Object[] source = {"name"};74throw new NullPointerException(form.format(source));75}76this.name = name;77}7879/**80* Return the Windows NT domain name for this81* <code>NTDomainPrincipal</code>.82*83* <p>84*85* @return the Windows NT domain name for this86* <code>NTDomainPrincipal</code>87*/88public String getName() {89return name;90}9192/**93* Return a string representation of this <code>NTDomainPrincipal</code>.94*95* <p>96*97* @return a string representation of this <code>NTDomainPrincipal</code>.98*/99public String toString() {100java.text.MessageFormat form = new java.text.MessageFormat101(sun.security.util.ResourcesMgr.getString102("NTDomainPrincipal.name",103"sun.security.util.AuthResources"));104Object[] source = {name};105return form.format(source);106}107108/**109* Compares the specified Object with this <code>NTDomainPrincipal</code>110* for equality. Returns true if the given object is also a111* <code>NTDomainPrincipal</code> and the two NTDomainPrincipals112* have the same name.113*114* <p>115*116* @param o Object to be compared for equality with this117* <code>NTDomainPrincipal</code>.118*119* @return true if the specified Object is equal equal to this120* <code>NTDomainPrincipal</code>.121*/122public boolean equals(Object o) {123if (o == null)124return false;125126if (this == o)127return true;128129if (!(o instanceof NTDomainPrincipal))130return false;131NTDomainPrincipal that = (NTDomainPrincipal)o;132133if (name.equals(that.getName()))134return true;135return false;136}137138/**139* Return a hash code for this <code>NTDomainPrincipal</code>.140*141* <p>142*143* @return a hash code for this <code>NTDomainPrincipal</code>.144*/145public int hashCode() {146return this.getName().hashCode();147}148}149150151