author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 23010 | jdk/src/share/classes/com/sun/security/auth/UserPrincipal.java@6dadb192ad81 |
child 34894 | 3248b89d1921 |
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) 2005, 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 |
* A user principal identified by a username or account name. |
|
32 |
* |
|
33 |
* <p> |
|
34 |
* After successful authentication, a user {@link java.security.Principal} |
|
35 |
* can be associated with a particular {@link javax.security.auth.Subject} |
|
36 |
* to augment that <code>Subject</code> with an additional identity. |
|
37 |
* Authorization decisions can then be based upon the |
|
38 |
* <code>Principal</code>s that are associated with a <code>Subject</code>. |
|
39 |
* |
|
40 |
* <p> |
|
41 |
* This class is immutable. |
|
42 |
* |
|
43 |
* @since 1.6 |
|
44 |
*/ |
|
20742
4ae78e8060d6
8008662: Add @jdk.Exported to JDK-specific/exported APIs
alanb
parents:
5506
diff
changeset
|
45 |
@jdk.Exported |
2 | 46 |
public final class UserPrincipal implements Principal, java.io.Serializable { |
47 |
||
48 |
private static final long serialVersionUID = 892106070870210969L; |
|
49 |
||
50 |
/** |
|
51 |
* The principal's name |
|
52 |
* |
|
53 |
* @serial |
|
54 |
*/ |
|
55 |
private final String name; |
|
56 |
||
57 |
/** |
|
58 |
* Creates a principal. |
|
59 |
* |
|
60 |
* @param name The principal's string name. |
|
61 |
* @exception NullPointerException If the <code>name</code> is |
|
62 |
* <code>null</code>. |
|
63 |
*/ |
|
64 |
public UserPrincipal(String name) { |
|
65 |
if (name == null) { |
|
66 |
throw new NullPointerException("null name is illegal"); |
|
67 |
} |
|
68 |
this.name = name; |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Compares this principal to the specified object. |
|
73 |
* |
|
74 |
* @param object The object to compare this principal against. |
|
75 |
* @return true if they are equal; false otherwise. |
|
76 |
*/ |
|
77 |
public boolean equals(Object object) { |
|
78 |
if (this == object) { |
|
79 |
return true; |
|
80 |
} |
|
81 |
if (object instanceof UserPrincipal) { |
|
82 |
return name.equals(((UserPrincipal)object).getName()); |
|
83 |
} |
|
84 |
return false; |
|
85 |
} |
|
86 |
||
87 |
/** |
|
88 |
* Returns a hash code for this principal. |
|
89 |
* |
|
90 |
* @return The principal's hash code. |
|
91 |
*/ |
|
92 |
public int hashCode() { |
|
93 |
return name.hashCode(); |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Returns the name of this principal. |
|
98 |
* |
|
99 |
* @return The principal's name. |
|
100 |
*/ |
|
101 |
public String getName() { |
|
102 |
return name; |
|
103 |
} |
|
104 |
||
105 |
/** |
|
106 |
* Returns a string representation of this principal. |
|
107 |
* |
|
108 |
* @return The principal's name. |
|
109 |
*/ |
|
110 |
public String toString() { |
|
111 |
return name; |
|
112 |
} |
|
113 |
} |