History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/com/sun/security/auth/SolarisNumericGroupPrincipal.java (1 of 18352 files). Show all

Unified · Split

java/pkg/com/sun/security/auth/SolarisNumericGroupPrincipal.java+216−0
@@ -0,0 +1,216 @@
1/*
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 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.
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 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&nbsp;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 */
48@Deprecated
49public class SolarisNumericGroupPrincipal implements
50 Principal,
51 java.io.Serializable {
52
53 private static final long serialVersionUID = 2345199581042573224L;
54
55 private static final java.util.ResourceBundle rb =
56 java.security.AccessController.doPrivileged
57 (new java.security.PrivilegedAction<java.util.ResourceBundle>() {
58 public java.util.ResourceBundle run() {
59 return (java.util.ResourceBundle.getBundle
60 ("sun.security.util.AuthResources"));
61 }
62 });
63
64 /**
65 * @serial
66 */
67 private String name;
68
69 /**
70 * @serial
71 */
72 private boolean primaryGroup;
73
74 /**
75 * Create a <code>SolarisNumericGroupPrincipal</code> using a
76 * <code>String</code> representation of the user's
77 * group identification number (GID).
78 *
79 * <p>
80 *
81 * @param name the user's group identification number (GID)
82 * for this user. <p>
83 *
84 * @param primaryGroup true if the specified GID represents the
85 * primary group to which this user belongs.
86 *
87 * @exception NullPointerException if the <code>name</code>
88 * is <code>null</code>.
89 */
90 public SolarisNumericGroupPrincipal(String name, boolean primaryGroup) {
91 if (name == null)
92 throw new NullPointerException(rb.getString("provided.null.name"));
93
94 this.name = name;
95 this.primaryGroup = primaryGroup;
96 }
97
98 /**
99 * Create a <code>SolarisNumericGroupPrincipal</code> using a
100 * long representation of the user's group identification number (GID).
101 *
102 * <p>
103 *
104 * @param name the user's group identification number (GID) for this user
105 * represented as a long. <p>
106 *
107 * @param primaryGroup true if the specified GID represents the
108 * primary group to which this user belongs.
109 *
110 */
111 public SolarisNumericGroupPrincipal(long name, boolean primaryGroup) {
112 this.name = (new Long(name)).toString();
113 this.primaryGroup = primaryGroup;
114 }
115
116 /**
117 * Return the user's group identification number (GID) for this
118 * <code>SolarisNumericGroupPrincipal</code>.
119 *
120 * <p>
121 *
122 * @return the user's group identification number (GID) for this
123 * <code>SolarisNumericGroupPrincipal</code>
124 */
125 public String getName() {
126 return name;
127 }
128
129 /**
130 * Return the user's group identification number (GID) for this
131 * <code>SolarisNumericGroupPrincipal</code> as a long.
132 *
133 * <p>
134 *
135 * @return the user's group identification number (GID) for this
136 * <code>SolarisNumericGroupPrincipal</code> as a long.
137 */
138 public long longValue() {
139 return ((new Long(name)).longValue());
140 }
141
142 /**
143 * Return whether this group identification number (GID) represents
144 * the primary group to which this user belongs.
145 *
146 * <p>
147 *
148 * @return true if this group identification number (GID) represents
149 * the primary group to which this user belongs,
150 * or false otherwise.
151 */
152 public boolean isPrimaryGroup() {
153 return primaryGroup;
154 }
155
156 /**
157 * Return a string representation of this
158 * <code>SolarisNumericGroupPrincipal</code>.
159 *
160 * <p>
161 *
162 * @return a string representation of this
163 * <code>SolarisNumericGroupPrincipal</code>.
164 */
165 public String toString() {
166 return((primaryGroup ?
167 rb.getString
168 ("SolarisNumericGroupPrincipal.Primary.Group.") + name :
169 rb.getString
170 ("SolarisNumericGroupPrincipal.Supplementary.Group.") + name));
171 }
172
173 /**
174 * Compares the specified Object with this
175 * <code>SolarisNumericGroupPrincipal</code>
176 * for equality. Returns true if the given object is also a
177 * <code>SolarisNumericGroupPrincipal</code> and the two
178 * SolarisNumericGroupPrincipals
179 * have the same group identification number (GID).
180 *
181 * <p>
182 *
183 * @param o Object to be compared for equality with this
184 * <code>SolarisNumericGroupPrincipal</code>.
185 *
186 * @return true if the specified Object is equal equal to this
187 * <code>SolarisNumericGroupPrincipal</code>.
188 */
189 public boolean equals(Object o) {
190 if (o == null)
191 return false;
192
193 if (this == o)
194 return true;
195
196 if (!(o instanceof SolarisNumericGroupPrincipal))
197 return false;
198 SolarisNumericGroupPrincipal that = (SolarisNumericGroupPrincipal)o;
199
200 if (this.getName().equals(that.getName()) &&
201 this.isPrimaryGroup() == that.isPrimaryGroup())
202 return true;
203 return false;
204 }
205
206 /**
207 * Return a hash code for this <code>SolarisNumericGroupPrincipal</code>.
208 *
209 * <p>
210 *
211 * @return a hash code for this <code>SolarisNumericGroupPrincipal</code>.
212 */
213 public int hashCode() {
214 return toString().hashCode();
215 }
216}