author | martin |
Thu, 30 Oct 2014 07:31:41 -0700 | |
changeset 28059 | e576535359cc |
parent 25859 | 3317bb8137f4 |
child 30044 | bab15bbe2ca3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20742
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.security.auth; |
|
27 |
||
28 |
import java.security.Principal; |
|
29 |
||
30 |
/** |
|
31 |
* <p> This class implements the <code>Principal</code> interface |
|
32 |
* and represents a user's Solaris group identification number (GID). |
|
33 |
* |
|
34 |
* <p> Principals such as this <code>SolarisNumericGroupPrincipal</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 |
||
41 |
* @deprecated As of JDK 1.4, replaced by |
|
42 |
* {@link UnixNumericGroupPrincipal}. |
|
43 |
* This class is entirely deprecated. |
|
44 |
* |
|
45 |
* @see java.security.Principal |
|
46 |
* @see javax.security.auth.Subject |
|
47 |
*/ |
|
20742
4ae78e8060d6
8008662: Add @jdk.Exported to JDK-specific/exported APIs
alanb
parents:
7179
diff
changeset
|
48 |
@jdk.Exported(false) |
2 | 49 |
@Deprecated |
50 |
public class SolarisNumericGroupPrincipal implements |
|
51 |
Principal, |
|
52 |
java.io.Serializable { |
|
53 |
||
54 |
private static final long serialVersionUID = 2345199581042573224L; |
|
55 |
||
56 |
private static final java.util.ResourceBundle rb = |
|
57 |
java.security.AccessController.doPrivileged |
|
58 |
(new java.security.PrivilegedAction<java.util.ResourceBundle>() { |
|
59 |
public java.util.ResourceBundle run() { |
|
60 |
return (java.util.ResourceBundle.getBundle |
|
61 |
("sun.security.util.AuthResources")); |
|
62 |
} |
|
63 |
}); |
|
64 |
||
65 |
/** |
|
66 |
* @serial |
|
67 |
*/ |
|
68 |
private String name; |
|
69 |
||
70 |
/** |
|
71 |
* @serial |
|
72 |
*/ |
|
73 |
private boolean primaryGroup; |
|
74 |
||
75 |
/** |
|
76 |
* Create a <code>SolarisNumericGroupPrincipal</code> using a |
|
77 |
* <code>String</code> representation of the user's |
|
78 |
* group identification number (GID). |
|
79 |
* |
|
80 |
* <p> |
|
81 |
* |
|
82 |
* @param name the user's group identification number (GID) |
|
83 |
* for this user. <p> |
|
84 |
* |
|
85 |
* @param primaryGroup true if the specified GID represents the |
|
86 |
* primary group to which this user belongs. |
|
87 |
* |
|
88 |
* @exception NullPointerException if the <code>name</code> |
|
89 |
* is <code>null</code>. |
|
90 |
*/ |
|
91 |
public SolarisNumericGroupPrincipal(String name, boolean primaryGroup) { |
|
92 |
if (name == null) |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
93 |
throw new NullPointerException(rb.getString("provided.null.name")); |
2 | 94 |
|
95 |
this.name = name; |
|
96 |
this.primaryGroup = primaryGroup; |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Create a <code>SolarisNumericGroupPrincipal</code> using a |
|
101 |
* long representation of the user's group identification number (GID). |
|
102 |
* |
|
103 |
* <p> |
|
104 |
* |
|
105 |
* @param name the user's group identification number (GID) for this user |
|
106 |
* represented as a long. <p> |
|
107 |
* |
|
108 |
* @param primaryGroup true if the specified GID represents the |
|
109 |
* primary group to which this user belongs. |
|
110 |
* |
|
111 |
*/ |
|
112 |
public SolarisNumericGroupPrincipal(long name, boolean primaryGroup) { |
|
25186
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
23010
diff
changeset
|
113 |
this.name = Long.toString(name); |
2 | 114 |
this.primaryGroup = primaryGroup; |
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* Return the user's group identification number (GID) for this |
|
119 |
* <code>SolarisNumericGroupPrincipal</code>. |
|
120 |
* |
|
121 |
* <p> |
|
122 |
* |
|
123 |
* @return the user's group identification number (GID) for this |
|
124 |
* <code>SolarisNumericGroupPrincipal</code> |
|
125 |
*/ |
|
126 |
public String getName() { |
|
127 |
return name; |
|
128 |
} |
|
129 |
||
130 |
/** |
|
131 |
* Return the user's group identification number (GID) for this |
|
132 |
* <code>SolarisNumericGroupPrincipal</code> as a long. |
|
133 |
* |
|
134 |
* <p> |
|
135 |
* |
|
136 |
* @return the user's group identification number (GID) for this |
|
137 |
* <code>SolarisNumericGroupPrincipal</code> as a long. |
|
138 |
*/ |
|
139 |
public long longValue() { |
|
25186
63e1a2ec30f5
8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents:
23010
diff
changeset
|
140 |
return Long.parseLong(name); |
2 | 141 |
} |
142 |
||
143 |
/** |
|
144 |
* Return whether this group identification number (GID) represents |
|
145 |
* the primary group to which this user belongs. |
|
146 |
* |
|
147 |
* <p> |
|
148 |
* |
|
149 |
* @return true if this group identification number (GID) represents |
|
150 |
* the primary group to which this user belongs, |
|
151 |
* or false otherwise. |
|
152 |
*/ |
|
153 |
public boolean isPrimaryGroup() { |
|
154 |
return primaryGroup; |
|
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Return a string representation of this |
|
159 |
* <code>SolarisNumericGroupPrincipal</code>. |
|
160 |
* |
|
161 |
* <p> |
|
162 |
* |
|
163 |
* @return a string representation of this |
|
164 |
* <code>SolarisNumericGroupPrincipal</code>. |
|
165 |
*/ |
|
166 |
public String toString() { |
|
167 |
return((primaryGroup ? |
|
168 |
rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
169 |
("SolarisNumericGroupPrincipal.Primary.Group.") + name : |
2 | 170 |
rb.getString |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
5506
diff
changeset
|
171 |
("SolarisNumericGroupPrincipal.Supplementary.Group.") + name)); |
2 | 172 |
} |
173 |
||
174 |
/** |
|
175 |
* Compares the specified Object with this |
|
176 |
* <code>SolarisNumericGroupPrincipal</code> |
|
177 |
* for equality. Returns true if the given object is also a |
|
178 |
* <code>SolarisNumericGroupPrincipal</code> and the two |
|
179 |
* SolarisNumericGroupPrincipals |
|
180 |
* have the same group identification number (GID). |
|
181 |
* |
|
182 |
* <p> |
|
183 |
* |
|
184 |
* @param o Object to be compared for equality with this |
|
185 |
* <code>SolarisNumericGroupPrincipal</code>. |
|
186 |
* |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
25859
diff
changeset
|
187 |
* @return true if the specified Object is equal to this |
2 | 188 |
* <code>SolarisNumericGroupPrincipal</code>. |
189 |
*/ |
|
190 |
public boolean equals(Object o) { |
|
191 |
if (o == null) |
|
192 |
return false; |
|
193 |
||
194 |
if (this == o) |
|
195 |
return true; |
|
196 |
||
197 |
if (!(o instanceof SolarisNumericGroupPrincipal)) |
|
198 |
return false; |
|
199 |
SolarisNumericGroupPrincipal that = (SolarisNumericGroupPrincipal)o; |
|
200 |
||
201 |
if (this.getName().equals(that.getName()) && |
|
202 |
this.isPrimaryGroup() == that.isPrimaryGroup()) |
|
203 |
return true; |
|
204 |
return false; |
|
205 |
} |
|
206 |
||
207 |
/** |
|
208 |
* Return a hash code for this <code>SolarisNumericGroupPrincipal</code>. |
|
209 |
* |
|
210 |
* <p> |
|
211 |
* |
|
212 |
* @return a hash code for this <code>SolarisNumericGroupPrincipal</code>. |
|
213 |
*/ |
|
214 |
public int hashCode() { |
|
215 |
return toString().hashCode(); |
|
216 |
} |
|
217 |
} |