KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)NTDomainPrincipal.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 the name of the Windows NT domain into which the
15  * user authenticated. This will be a domain name if the user logged
16  * into a Windows NT domain, a workgroup name if the user logged into
17  * a workgroup, or a machine name if the user logged into a standalone
18  * configuration.
19  *
20  * <p> Principals such as this <code>NTDomainPrincipal</code>
21  * may be associated with a particular <code>Subject</code>
22  * to augment that <code>Subject</code> with an additional
23  * identity. Refer to the <code>Subject</code> class for more information
24  * on how to achieve this. Authorization decisions can then be based upon
25  * the Principals associated with a <code>Subject</code>.
26  *
27  * @version 1.14, 12/19/03
28  * @see java.security.Principal
29  * @see javax.security.auth.Subject
30  */

31 public class NTDomainPrincipal implements Principal JavaDoc, java.io.Serializable JavaDoc {
32
33     private static final long serialVersionUID = -4408637351440771220L;
34
35     /**
36      * @serial
37      */

38     private String JavaDoc name;
39     
40     /**
41      * Create an <code>NTDomainPrincipal</code> with a Windows NT domain name.
42      *
43      * <p>
44      *
45      * @param name the Windows NT domain name for this user. <p>
46      *
47      * @exception NullPointerException if the <code>name</code>
48      * is <code>null</code>.
49      */

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

71     public String JavaDoc getName() {
72         return name;
73     }
74
75     /**
76      * Return a string representation of this <code>NTDomainPrincipal</code>.
77      *
78      * <p>
79      *
80      * @return a string representation of this <code>NTDomainPrincipal</code>.
81      */

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

105     public boolean equals(Object JavaDoc o) {
106         if (o == null)
107             return false;
108
109         if (this == o)
110             return true;
111  
112         if (!(o instanceof NTDomainPrincipal))
113             return false;
114         NTDomainPrincipal that = (NTDomainPrincipal)o;
115
116         if (name.equals(that.getName()))
117             return true;
118         return false;
119     }
120  
121     /**
122      * Return a hash code for this <code>NTDomainPrincipal</code>.
123      *
124      * <p>
125      *
126      * @return a hash code for this <code>NTDomainPrincipal</code>.
127      */

128     public int hashCode() {
129     return this.getName().hashCode();
130     }
131 }
132
Popular Tags