blob: 266cbf68b1982e2eed896dbe57f8577851049b3f [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 Solaris user.
33 *
34 * <p> Principals such as this <code>SolarisPrincipal</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 UnixPrincipal}.
43 * This class is entirely deprecated.
44 * @see java.security.Principal
45 * @see javax.security.auth.Subject
46 */
47@Deprecated
48public class SolarisPrincipal implements Principal, java.io.Serializable {
49
50 private static final long serialVersionUID = -7840670002439379038L;
51
52 private static final java.util.ResourceBundle rb =
53 java.security.AccessController.doPrivileged
54 (new java.security.PrivilegedAction<java.util.ResourceBundle>() {
55 public java.util.ResourceBundle run() {
56 return (java.util.ResourceBundle.getBundle
57 ("sun.security.util.AuthResources"));
58 }
59 });
60
61
62 /**
63 * @serial
64 */
65 private String name;
66
67 /**
68 * Create a SolarisPrincipal with a Solaris username.
69 *
70 * <p>
71 *
72 * @param name the Unix username for this user.
73 *
74 * @exception NullPointerException if the <code>name</code>
75 * is <code>null</code>.
76 */
77 public SolarisPrincipal(String name) {
78 if (name == null)
79 throw new NullPointerException(rb.getString("provided null name"));
80
81 this.name = name;
82 }
83
84 /**
85 * Return the Unix username for this <code>SolarisPrincipal</code>.
86 *
87 * <p>
88 *
89 * @return the Unix username for this <code>SolarisPrincipal</code>
90 */
91 public String getName() {
92 return name;
93 }
94
95 /**
96 * Return a string representation of this <code>SolarisPrincipal</code>.
97 *
98 * <p>
99 *
100 * @return a string representation of this <code>SolarisPrincipal</code>.
101 */
102 public String toString() {
103 return(rb.getString("SolarisPrincipal: ") + name);
104 }
105
106 /**
107 * Compares the specified Object with this <code>SolarisPrincipal</code>
108 * for equality. Returns true if the given object is also a
109 * <code>SolarisPrincipal</code> and the two SolarisPrincipals
110 * have the same username.
111 *
112 * <p>
113 *
114 * @param o Object to be compared for equality with this
115 * <code>SolarisPrincipal</code>.
116 *
117 * @return true if the specified Object is equal equal to this
118 * <code>SolarisPrincipal</code>.
119 */
120 public boolean equals(Object o) {
121 if (o == null)
122 return false;
123
124 if (this == o)
125 return true;
126
127 if (!(o instanceof SolarisPrincipal))
128 return false;
129 SolarisPrincipal that = (SolarisPrincipal)o;
130
131 if (this.getName().equals(that.getName()))
132 return true;
133 return false;
134 }
135
136 /**
137 * Return a hash code for this <code>SolarisPrincipal</code>.
138 *
139 * <p>
140 *
141 * @return a hash code for this <code>SolarisPrincipal</code>.
142 */
143 public int hashCode() {
144 return name.hashCode();
145 }
146}