KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > security > auth > SolarisNumericUserPrincipal


1 /*
2  * @(#)SolarisNumericUserPrincipal.java 1.17 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.security.auth;
9
10 import java.security.Principal JavaDoc;
11
12 /**
13  * <p> This class implements the <code>Principal</code> interface
14  * and represents a user's Solaris identification number (UID).
15  *
16  * <p> Principals such as this <code>SolarisNumericUserPrincipal</code>
17  * may be associated with a particular <code>Subject</code>
18  * to augment that <code>Subject</code> with an additional
19  * identity. Refer to the <code>Subject</code> class for more information
20  * on how to achieve this. Authorization decisions can then be based upon
21  * the Principals associated with a <code>Subject</code>.
22  * @deprecated As of JDK&nbsp;1.4, replaced by
23  * {@link UnixNumericUserPrincipal}.
24  * This class is entirely deprecated.
25  *
26  * @version 1.17, 05/18/04
27  * @see java.security.Principal
28  * @see javax.security.auth.Subject
29  */

30 @Deprecated JavaDoc
31 public class SolarisNumericUserPrincipal implements
32                     Principal JavaDoc,
33                     java.io.Serializable JavaDoc {
34
35     private static final long serialVersionUID = -3178578484679887104L;
36
37     private static final java.util.ResourceBundle JavaDoc rb =
38           (java.util.ResourceBundle JavaDoc)java.security.AccessController.doPrivileged
39           (new java.security.PrivilegedAction JavaDoc() {
40               public Object JavaDoc run() {
41                   return (java.util.ResourceBundle.getBundle
42                                 ("sun.security.util.AuthResources"));
43               }
44        });
45
46
47     /**
48      * @serial
49      */

50     private String JavaDoc name;
51
52     /**
53      * Create a <code>SolarisNumericUserPrincipal</code> using a
54      * <code>String</code> representation of the
55      * user's identification number (UID).
56      *
57      * <p>
58      *
59      * @param name the user identification number (UID) for this user.
60      *
61      * @exception NullPointerException if the <code>name</code>
62      * is <code>null</code>.
63      */

64     public SolarisNumericUserPrincipal(String JavaDoc name) {
65     if (name == null)
66         throw new NullPointerException JavaDoc(rb.getString("provided null name"));
67
68     this.name = name;
69     }
70
71     /**
72      * Create a <code>SolarisNumericUserPrincipal</code> using a
73      * long representation of the user's identification number (UID).
74      *
75      * <p>
76      *
77      * @param name the user identification number (UID) for this user
78      * represented as a long.
79      */

80     public SolarisNumericUserPrincipal(long name) {
81     this.name = (new Long JavaDoc(name)).toString();
82     }
83
84     /**
85      * Return the user identification number (UID) for this
86      * <code>SolarisNumericUserPrincipal</code>.
87      *
88      * <p>
89      *
90      * @return the user identification number (UID) for this
91      * <code>SolarisNumericUserPrincipal</code>
92      */

93     public String JavaDoc getName() {
94     return name;
95     }
96
97     /**
98      * Return the user identification number (UID) for this
99      * <code>SolarisNumericUserPrincipal</code> as a long.
100      *
101      * <p>
102      *
103      * @return the user identification number (UID) for this
104      * <code>SolarisNumericUserPrincipal</code> as a long.
105      */

106     public long longValue() {
107     return ((new Long JavaDoc(name)).longValue());
108     }
109
110     /**
111      * Return a string representation of this
112      * <code>SolarisNumericUserPrincipal</code>.
113      *
114      * <p>
115      *
116      * @return a string representation of this
117      * <code>SolarisNumericUserPrincipal</code>.
118      */

119     public String JavaDoc toString() {
120     return(rb.getString("SolarisNumericUserPrincipal: ") + name);
121     }
122
123     /**
124      * Compares the specified Object with this
125      * <code>SolarisNumericUserPrincipal</code>
126      * for equality. Returns true if the given object is also a
127      * <code>SolarisNumericUserPrincipal</code> and the two
128      * SolarisNumericUserPrincipals
129      * have the same user identification number (UID).
130      *
131      * <p>
132      *
133      * @param o Object to be compared for equality with this
134      * <code>SolarisNumericUserPrincipal</code>.
135      *
136      * @return true if the specified Object is equal equal to this
137      * <code>SolarisNumericUserPrincipal</code>.
138      */

139     public boolean equals(Object JavaDoc o) {
140     if (o == null)
141         return false;
142
143         if (this == o)
144             return true;
145  
146         if (!(o instanceof SolarisNumericUserPrincipal))
147             return false;
148         SolarisNumericUserPrincipal that = (SolarisNumericUserPrincipal)o;
149
150     if (this.getName().equals(that.getName()))
151         return true;
152     return false;
153     }
154  
155     /**
156      * Return a hash code for this <code>SolarisNumericUserPrincipal</code>.
157      *
158      * <p>
159      *
160      * @return a hash code for this <code>SolarisNumericUserPrincipal</code>.
161      */

162     public int hashCode() {
163     return name.hashCode();
164     }
165 }
166
Popular Tags