blob: cc8e0e5b66994c5a56a9bd7c793dcfbb9ed41b5f [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.security.auth;
27
28import java.security.Principal;
29
30/**
31 * <p> This class implements the <code>Principal</code> interface
32 * and represents a user's Solaris identification number (UID).
33 *
34 * <p> Principals such as this <code>SolarisNumericUserPrincipal</code>
35 * may be associated with a particular <code>Subject</code>
36 * to augment that <code>Subject</code> with an additional
37 * identity. Refer to the <code>Subject</code> class for more information
38 * on how to achieve this. Authorization decisions can then be based upon
39 * the Principals associated with a <code>Subject</code>.
40 * @deprecated As of JDK&nbsp;1.4, replaced by
41 * {@link UnixNumericUserPrincipal}.
42 * This class is entirely deprecated.
43 *
44 * @see java.security.Principal
45 * @see javax.security.auth.Subject
46 */
47@Deprecated
48public class SolarisNumericUserPrincipal implements
49 Principal,
50 java.io.Serializable {
51
52 private static final long serialVersionUID = -3178578484679887104L;
53
54 private static final java.util.ResourceBundle rb =
55 java.security.AccessController.doPrivileged
56 (new java.security.PrivilegedAction<java.util.ResourceBundle>() {
57 public java.util.ResourceBundle run() {
58 return (java.util.ResourceBundle.getBundle
59 ("sun.security.util.AuthResources"));
60 }
61 });
62
63
64 /**
65 * @serial
66 */
67 private String name;
68
69 /**
70 * Create a <code>SolarisNumericUserPrincipal</code> using a
71 * <code>String</code> representation of the
72 * user's identification number (UID).
73 *
74 * <p>
75 *
76 * @param name the user identification number (UID) for this user.
77 *
78 * @exception NullPointerException if the <code>name</code>
79 * is <code>null</code>.
80 */
81 public SolarisNumericUserPrincipal(String name) {
82 if (name == null)
83 throw new NullPointerException(rb.getString("provided null name"));
84
85 this.name = name;
86 }
87
88 /**
89 * Create a <code>SolarisNumericUserPrincipal</code> using a
90 * long representation of the user's identification number (UID).
91 *
92 * <p>
93 *
94 * @param name the user identification number (UID) for this user
95 * represented as a long.
96 */
97 public SolarisNumericUserPrincipal(long name) {
98 this.name = (new Long(name)).toString();
99 }
100
101 /**
102 * Return the user identification number (UID) for this
103 * <code>SolarisNumericUserPrincipal</code>.
104 *
105 * <p>
106 *
107 * @return the user identification number (UID) for this
108 * <code>SolarisNumericUserPrincipal</code>
109 */
110 public String getName() {
111 return name;
112 }
113
114 /**
115 * Return the user identification number (UID) for this
116 * <code>SolarisNumericUserPrincipal</code> as a long.
117 *
118 * <p>
119 *
120 * @return the user identification number (UID) for this
121 * <code>SolarisNumericUserPrincipal</code> as a long.
122 */
123 public long longValue() {
124 return ((new Long(name)).longValue());
125 }
126
127 /**
128 * Return a string representation of this
129 * <code>SolarisNumericUserPrincipal</code>.
130 *
131 * <p>
132 *
133 * @return a string representation of this
134 * <code>SolarisNumericUserPrincipal</code>.
135 */
136 public String toString() {
137 return(rb.getString("SolarisNumericUserPrincipal: ") + name);
138 }
139
140 /**
141 * Compares the specified Object with this
142 * <code>SolarisNumericUserPrincipal</code>
143 * for equality. Returns true if the given object is also a
144 * <code>SolarisNumericUserPrincipal</code> and the two
145 * SolarisNumericUserPrincipals
146 * have the same user identification number (UID).
147 *
148 * <p>
149 *
150 * @param o Object to be compared for equality with this
151 * <code>SolarisNumericUserPrincipal</code>.
152 *
153 * @return true if the specified Object is equal equal to this
154 * <code>SolarisNumericUserPrincipal</code>.
155 */
156 public boolean equals(Object o) {
157 if (o == null)
158 return false;
159
160 if (this == o)
161 return true;
162
163 if (!(o instanceof SolarisNumericUserPrincipal))
164 return false;
165 SolarisNumericUserPrincipal that = (SolarisNumericUserPrincipal)o;
166
167 if (this.getName().equals(that.getName()))
168 return true;
169 return false;
170 }
171
172 /**
173 * Return a hash code for this <code>SolarisNumericUserPrincipal</code>.
174 *
175 * <p>
176 *
177 * @return a hash code for this <code>SolarisNumericUserPrincipal</code>.
178 */
179 public int hashCode() {
180 return name.hashCode();
181 }
182}