Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/security/auth/UserPrincipal.java
38924 views
1
/*
2
* Copyright (c) 2005, 2013, 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
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
*/
45
@jdk.Exported
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
}
114
115