001: /*
002: * Copyright 1999-2006 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 user's Solaris identification number (UID).
033: *
034: * <p> Principals such as this <code>SolarisNumericUserPrincipal</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: * @deprecated As of JDK 1.4, replaced by
041: * {@link UnixNumericUserPrincipal}.
042: * This class is entirely deprecated.
043: *
044: * @version 1.25, 05/05/07
045: * @see java.security.Principal
046: * @see javax.security.auth.Subject
047: */
048: @Deprecated
049: public class SolarisNumericUserPrincipal implements Principal,
050: java.io.Serializable {
051:
052: private static final long serialVersionUID = -3178578484679887104L;
053:
054: private static final java.util.ResourceBundle rb = java.security.AccessController
055: .doPrivileged(new java.security.PrivilegedAction<java.util.ResourceBundle>() {
056: public java.util.ResourceBundle run() {
057: return (java.util.ResourceBundle
058: .getBundle("sun.security.util.AuthResources"));
059: }
060: });
061:
062: /**
063: * @serial
064: */
065: private String name;
066:
067: /**
068: * Create a <code>SolarisNumericUserPrincipal</code> using a
069: * <code>String</code> representation of the
070: * user's identification number (UID).
071: *
072: * <p>
073: *
074: * @param name the user identification number (UID) for this user.
075: *
076: * @exception NullPointerException if the <code>name</code>
077: * is <code>null</code>.
078: */
079: public SolarisNumericUserPrincipal(String name) {
080: if (name == null)
081: throw new NullPointerException(rb
082: .getString("provided null name"));
083:
084: this .name = name;
085: }
086:
087: /**
088: * Create a <code>SolarisNumericUserPrincipal</code> using a
089: * long representation of the user's identification number (UID).
090: *
091: * <p>
092: *
093: * @param name the user identification number (UID) for this user
094: * represented as a long.
095: */
096: public SolarisNumericUserPrincipal(long name) {
097: this .name = (new Long(name)).toString();
098: }
099:
100: /**
101: * Return the user identification number (UID) for this
102: * <code>SolarisNumericUserPrincipal</code>.
103: *
104: * <p>
105: *
106: * @return the user identification number (UID) for this
107: * <code>SolarisNumericUserPrincipal</code>
108: */
109: public String getName() {
110: return name;
111: }
112:
113: /**
114: * Return the user identification number (UID) for this
115: * <code>SolarisNumericUserPrincipal</code> as a long.
116: *
117: * <p>
118: *
119: * @return the user identification number (UID) for this
120: * <code>SolarisNumericUserPrincipal</code> as a long.
121: */
122: public long longValue() {
123: return ((new Long(name)).longValue());
124: }
125:
126: /**
127: * Return a string representation of this
128: * <code>SolarisNumericUserPrincipal</code>.
129: *
130: * <p>
131: *
132: * @return a string representation of this
133: * <code>SolarisNumericUserPrincipal</code>.
134: */
135: public String toString() {
136: return (rb.getString("SolarisNumericUserPrincipal: ") + name);
137: }
138:
139: /**
140: * Compares the specified Object with this
141: * <code>SolarisNumericUserPrincipal</code>
142: * for equality. Returns true if the given object is also a
143: * <code>SolarisNumericUserPrincipal</code> and the two
144: * SolarisNumericUserPrincipals
145: * have the same user identification number (UID).
146: *
147: * <p>
148: *
149: * @param o Object to be compared for equality with this
150: * <code>SolarisNumericUserPrincipal</code>.
151: *
152: * @return true if the specified Object is equal equal to this
153: * <code>SolarisNumericUserPrincipal</code>.
154: */
155: public boolean equals(Object o) {
156: if (o == null)
157: return false;
158:
159: if (this == o)
160: return true;
161:
162: if (!(o instanceof SolarisNumericUserPrincipal))
163: return false;
164: SolarisNumericUserPrincipal that = (SolarisNumericUserPrincipal) o;
165:
166: if (this .getName().equals(that.getName()))
167: return true;
168: return false;
169: }
170:
171: /**
172: * Return a hash code for this <code>SolarisNumericUserPrincipal</code>.
173: *
174: * <p>
175: *
176: * @return a hash code for this <code>SolarisNumericUserPrincipal</code>.
177: */
178: public int hashCode() {
179: return name.hashCode();
180: }
181: }
|