Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/NTSid.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 information about a Windows NT user, group or realm.32*33* <p> Windows NT chooses to represent users, groups and realms (or domains)34* with not only common names, but also relatively unique numbers. These35* numbers are called Security IDentifiers, or SIDs. Windows NT36* also provides services that render these SIDs into string forms.37* This class represents these string forms.38*39* <p> Principals such as this <code>NTSid</code>40* may be associated with a particular <code>Subject</code>41* to augment that <code>Subject</code> with an additional42* identity. Refer to the <code>Subject</code> class for more information43* on how to achieve this. Authorization decisions can then be based upon44* the Principals associated with a <code>Subject</code>.45*46* @see java.security.Principal47* @see javax.security.auth.Subject48*/49@jdk.Exported50public class NTSid implements Principal, java.io.Serializable {5152private static final long serialVersionUID = 4412290580770249885L;5354/**55* @serial56*/57private String sid;5859/**60* Create an <code>NTSid</code> with a Windows NT SID.61*62* <p>63*64* @param stringSid the Windows NT SID. <p>65*66* @exception NullPointerException if the <code>String</code>67* is <code>null</code>.68*69* @exception IllegalArgumentException if the <code>String</code>70* has zero length.71*/72public NTSid (String stringSid) {73if (stringSid == null) {74java.text.MessageFormat form = new java.text.MessageFormat75(sun.security.util.ResourcesMgr.getString76("invalid.null.input.value",77"sun.security.util.AuthResources"));78Object[] source = {"stringSid"};79throw new NullPointerException(form.format(source));80}81if (stringSid.length() == 0) {82throw new IllegalArgumentException83(sun.security.util.ResourcesMgr.getString84("Invalid.NTSid.value",85"sun.security.util.AuthResources"));86}87sid = new String(stringSid);88}8990/**91* Return a string version of this <code>NTSid</code>.92*93* <p>94*95* @return a string version of this <code>NTSid</code>96*/97public String getName() {98return sid;99}100101/**102* Return a string representation of this <code>NTSid</code>.103*104* <p>105*106* @return a string representation of this <code>NTSid</code>.107*/108public String toString() {109java.text.MessageFormat form = new java.text.MessageFormat110(sun.security.util.ResourcesMgr.getString111("NTSid.name",112"sun.security.util.AuthResources"));113Object[] source = {sid};114return form.format(source);115}116117/**118* Compares the specified Object with this <code>NTSid</code>119* for equality. Returns true if the given object is also a120* <code>NTSid</code> and the two NTSids have the same String121* representation.122*123* <p>124*125* @param o Object to be compared for equality with this126* <code>NTSid</code>.127*128* @return true if the specified Object is equal to this129* <code>NTSid</code>.130*/131public boolean equals(Object o) {132if (o == null)133return false;134135if (this == o)136return true;137138if (!(o instanceof NTSid))139return false;140NTSid that = (NTSid)o;141142if (sid.equals(that.sid)) {143return true;144}145return false;146}147148/**149* Return a hash code for this <code>NTSid</code>.150*151* <p>152*153* @return a hash code for this <code>NTSid</code>.154*/155public int hashCode() {156return sid.hashCode();157}158}159160161