KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SolarisNumericGroupPrincipal.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 group identification number (GID).
15  *
16  * <p> Principals such as this <code>SolarisNumericGroupPrincipal</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  
23  * @deprecated As of JDK&nbsp;1.4, replaced by
24  * {@link UnixNumericGroupPrincipal}.
25  * This class is entirely deprecated.
26  *
27  * @version 1.17, 05/18/04
28  * @see java.security.Principal
29  * @see javax.security.auth.Subject
30  */

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

50     private String JavaDoc name;
51
52     /**
53      * @serial
54      */

55     private boolean primaryGroup;
56
57     /**
58      * Create a <code>SolarisNumericGroupPrincipal</code> using a
59      * <code>String</code> representation of the user's
60      * group identification number (GID).
61      *
62      * <p>
63      *
64      * @param name the user's group identification number (GID)
65      * for this user. <p>
66      *
67      * @param primaryGroup true if the specified GID represents the
68      * primary group to which this user belongs.
69      *
70      * @exception NullPointerException if the <code>name</code>
71      * is <code>null</code>.
72      */

73     public SolarisNumericGroupPrincipal(String JavaDoc name, boolean primaryGroup) {
74     if (name == null)
75         throw new NullPointerException JavaDoc(rb.getString("provided null name"));
76
77     this.name = name;
78     this.primaryGroup = primaryGroup;
79     }
80
81     /**
82      * Create a <code>SolarisNumericGroupPrincipal</code> using a
83      * long representation of the user's group identification number (GID).
84      *
85      * <p>
86      *
87      * @param name the user's group identification number (GID) for this user
88      * represented as a long. <p>
89      *
90      * @param primaryGroup true if the specified GID represents the
91      * primary group to which this user belongs.
92      *
93      */

94     public SolarisNumericGroupPrincipal(long name, boolean primaryGroup) {
95     this.name = (new Long JavaDoc(name)).toString();
96     this.primaryGroup = primaryGroup;
97     }
98
99     /**
100      * Return the user's group identification number (GID) for this
101      * <code>SolarisNumericGroupPrincipal</code>.
102      *
103      * <p>
104      *
105      * @return the user's group identification number (GID) for this
106      * <code>SolarisNumericGroupPrincipal</code>
107      */

108     public String JavaDoc getName() {
109     return name;
110     }
111
112     /**
113      * Return the user's group identification number (GID) for this
114      * <code>SolarisNumericGroupPrincipal</code> as a long.
115      *
116      * <p>
117      *
118      * @return the user's group identification number (GID) for this
119      * <code>SolarisNumericGroupPrincipal</code> as a long.
120      */

121     public long longValue() {
122     return ((new Long JavaDoc(name)).longValue());
123     }
124
125     /**
126      * Return whether this group identification number (GID) represents
127      * the primary group to which this user belongs.
128      *
129      * <p>
130      *
131      * @return true if this group identification number (GID) represents
132      * the primary group to which this user belongs,
133      * or false otherwise.
134      */

135     public boolean isPrimaryGroup() {
136     return primaryGroup;
137     }
138
139     /**
140      * Return a string representation of this
141      * <code>SolarisNumericGroupPrincipal</code>.
142      *
143      * <p>
144      *
145      * @return a string representation of this
146      * <code>SolarisNumericGroupPrincipal</code>.
147      */

148     public String JavaDoc toString() {
149     return((primaryGroup ?
150         rb.getString
151         ("SolarisNumericGroupPrincipal [Primary Group]: ") + name :
152         rb.getString
153         ("SolarisNumericGroupPrincipal [Supplementary Group]: ") + name));
154     }
155
156     /**
157      * Compares the specified Object with this
158      * <code>SolarisNumericGroupPrincipal</code>
159      * for equality. Returns true if the given object is also a
160      * <code>SolarisNumericGroupPrincipal</code> and the two
161      * SolarisNumericGroupPrincipals
162      * have the same group identification number (GID).
163      *
164      * <p>
165      *
166      * @param o Object to be compared for equality with this
167      * <code>SolarisNumericGroupPrincipal</code>.
168      *
169      * @return true if the specified Object is equal equal to this
170      * <code>SolarisNumericGroupPrincipal</code>.
171      */

172     public boolean equals(Object JavaDoc o) {
173     if (o == null)
174         return false;
175
176         if (this == o)
177             return true;
178  
179         if (!(o instanceof SolarisNumericGroupPrincipal))
180             return false;
181         SolarisNumericGroupPrincipal that = (SolarisNumericGroupPrincipal)o;
182
183     if (this.getName().equals(that.getName()) &&
184         this.isPrimaryGroup() == that.isPrimaryGroup())
185         return true;
186     return false;
187     }
188  
189     /**
190      * Return a hash code for this <code>SolarisNumericGroupPrincipal</code>.
191      *
192      * <p>
193      *
194      * @return a hash code for this <code>SolarisNumericGroupPrincipal</code>.
195      */

196     public int hashCode() {
197     return toString().hashCode();
198     }
199 }
200
Popular Tags