KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > security > auth > NTUserPrincipal


1 /*
2  * @(#)NTUserPrincipal.java 1.14 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.security.auth;
9
10 import java.security.Principal JavaDoc;
11
12 /**
13  * <p> This class implements the <code>Principal</code> interface
14  * and represents a Windows NT user.
15  *
16  * <p> Principals such as this <code>NTUserPrincipal</code>
17  * may be associated with a particular <code>Subject</code>
18  * to augment that <code>Subject</code> with an additional
19  * identity. Refer to the <code>Subject</code> class for more information
20  * on how to achieve this. Authorization decisions can then be based upon
21  * the Principals associated with a <code>Subject</code>.
22  *
23  * @version 1.14, 12/19/03
24  * @see java.security.Principal
25  * @see javax.security.auth.Subject
26  */

27 public class NTUserPrincipal implements Principal JavaDoc, java.io.Serializable JavaDoc {
28
29     private static final long serialVersionUID = -8737649811939033735L;
30
31     /**
32      * @serial
33      */

34     private String JavaDoc name;
35     
36     /**
37      * Create an <code>NTUserPrincipal</code> with a Windows NT username.
38      *
39      * <p>
40      *
41      * @param name the Windows NT username for this user. <p>
42      *
43      * @exception NullPointerException if the <code>name</code>
44      * is <code>null</code>.
45      */

46     public NTUserPrincipal(String JavaDoc name) {
47     if (name == null) {
48         java.text.MessageFormat JavaDoc form = new java.text.MessageFormat JavaDoc
49         (sun.security.util.ResourcesMgr.getString
50             ("invalid null input: value",
51             "sun.security.util.AuthResources"));
52         Object JavaDoc[] source = {"name"};
53         throw new NullPointerException JavaDoc(form.format(source));
54     }
55     this.name = name;
56     }
57     
58     /**
59      * Return the Windows NT username for this <code>NTPrincipal</code>.
60      *
61      * <p>
62      *
63      * @return the Windows NT username for this <code>NTPrincipal</code>
64      */

65     public String JavaDoc getName() {
66     return name;
67     }
68
69     /**
70      * Return a string representation of this <code>NTPrincipal</code>.
71      *
72      * <p>
73      *
74      * @return a string representation of this <code>NTPrincipal</code>.
75      */

76     public String JavaDoc toString() {
77     java.text.MessageFormat JavaDoc form = new java.text.MessageFormat JavaDoc
78         (sun.security.util.ResourcesMgr.getString
79             ("NTUserPrincipal: name",
80             "sun.security.util.AuthResources"));
81     Object JavaDoc[] source = {name};
82     return form.format(source);
83     }
84     
85     /**
86      * Compares the specified Object with this <code>NTUserPrincipal</code>
87      * for equality. Returns true if the given object is also a
88      * <code>NTUserPrincipal</code> and the two NTUserPrincipals
89      * have the same name.
90      *
91      * <p>
92      *
93      * @param o Object to be compared for equality with this
94      * <code>NTPrincipal</code>.
95      *
96      * @return true if the specified Object is equal equal to this
97      * <code>NTPrincipal</code>.
98      */

99     public boolean equals(Object JavaDoc o) {
100         if (o == null)
101             return false;
102
103         if (this == o)
104             return true;
105  
106         if (!(o instanceof NTUserPrincipal))
107             return false;
108         NTUserPrincipal that = (NTUserPrincipal)o;
109
110         if (name.equals(that.getName()))
111             return true;
112         return false;
113     }
114  
115     /**
116      * Return a hash code for this <code>NTUserPrincipal</code>.
117      *
118      * <p>
119      *
120      * @return a hash code for this <code>NTUserPrincipal</code>.
121      */

122     public int hashCode() {
123         return this.getName().hashCode();
124     }
125 }
126
Popular Tags