001: /*
002: * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.security.auth;
027:
028: import java.security.Principal;
029:
030: /**
031: * <p> This class implements the <code>Principal</code> interface
032: * and represents a Windows NT user.
033: *
034: * <p> Principals such as this <code>NTUserPrincipal</code>
035: * may be associated with a particular <code>Subject</code>
036: * to augment that <code>Subject</code> with an additional
037: * identity. Refer to the <code>Subject</code> class for more information
038: * on how to achieve this. Authorization decisions can then be based upon
039: * the Principals associated with a <code>Subject</code>.
040: *
041: * @version 1.21, 05/05/07
042: * @see java.security.Principal
043: * @see javax.security.auth.Subject
044: */
045: public class NTUserPrincipal implements Principal, java.io.Serializable {
046:
047: private static final long serialVersionUID = -8737649811939033735L;
048:
049: /**
050: * @serial
051: */
052: private String name;
053:
054: /**
055: * Create an <code>NTUserPrincipal</code> with a Windows NT username.
056: *
057: * <p>
058: *
059: * @param name the Windows NT username for this user. <p>
060: *
061: * @exception NullPointerException if the <code>name</code>
062: * is <code>null</code>.
063: */
064: public NTUserPrincipal(String name) {
065: if (name == null) {
066: java.text.MessageFormat form = new java.text.MessageFormat(
067: sun.security.util.ResourcesMgr.getString(
068: "invalid null input: value",
069: "sun.security.util.AuthResources"));
070: Object[] source = { "name" };
071: throw new NullPointerException(form.format(source));
072: }
073: this .name = name;
074: }
075:
076: /**
077: * Return the Windows NT username for this <code>NTPrincipal</code>.
078: *
079: * <p>
080: *
081: * @return the Windows NT username for this <code>NTPrincipal</code>
082: */
083: public String getName() {
084: return name;
085: }
086:
087: /**
088: * Return a string representation of this <code>NTPrincipal</code>.
089: *
090: * <p>
091: *
092: * @return a string representation of this <code>NTPrincipal</code>.
093: */
094: public String toString() {
095: java.text.MessageFormat form = new java.text.MessageFormat(
096: sun.security.util.ResourcesMgr.getString(
097: "NTUserPrincipal: name",
098: "sun.security.util.AuthResources"));
099: Object[] source = { name };
100: return form.format(source);
101: }
102:
103: /**
104: * Compares the specified Object with this <code>NTUserPrincipal</code>
105: * for equality. Returns true if the given object is also a
106: * <code>NTUserPrincipal</code> and the two NTUserPrincipals
107: * have the same name.
108: *
109: * <p>
110: *
111: * @param o Object to be compared for equality with this
112: * <code>NTPrincipal</code>.
113: *
114: * @return true if the specified Object is equal equal to this
115: * <code>NTPrincipal</code>.
116: */
117: public boolean equals(Object o) {
118: if (o == null)
119: return false;
120:
121: if (this == o)
122: return true;
123:
124: if (!(o instanceof NTUserPrincipal))
125: return false;
126: NTUserPrincipal that = (NTUserPrincipal) o;
127:
128: if (name.equals(that.getName()))
129: return true;
130: return false;
131: }
132:
133: /**
134: * Return a hash code for this <code>NTUserPrincipal</code>.
135: *
136: * <p>
137: *
138: * @return a hash code for this <code>NTUserPrincipal</code>.
139: */
140: public int hashCode() {
141: return this.getName().hashCode();
142: }
143: }
|