KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)NTSid.java 1.17 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 information about a Windows NT user, group or realm.
15  *
16  * <p> Windows NT chooses to represent users, groups and realms (or domains)
17  * with not only common names, but also relatively unique numbers. These
18  * numbers are called Security IDentifiers, or SIDs. Windows NT
19  * also provides services that render these SIDs into string forms.
20  * This class represents these string forms.
21  *
22  * <p> Principals such as this <code>NTSid</code>
23  * may be associated with a particular <code>Subject</code>
24  * to augment that <code>Subject</code> with an additional
25  * identity. Refer to the <code>Subject</code> class for more information
26  * on how to achieve this. Authorization decisions can then be based upon
27  * the Principals associated with a <code>Subject</code>.
28  *
29  * @version 1.17, 12/19/03
30  * @see java.security.Principal
31  * @see javax.security.auth.Subject
32  */

33 public class NTSid implements Principal JavaDoc, java.io.Serializable JavaDoc {
34
35     private static final long serialVersionUID = 4412290580770249885L;
36
37     /**
38      * @serial
39      */

40     private String JavaDoc sid;
41     
42     /**
43      * Create an <code>NTSid</code> with a Windows NT SID.
44      *
45      * <p>
46      *
47      * @param stringSid the Windows NT SID. <p>
48      *
49      * @exception NullPointerException if the <code>String</code>
50      * is <code>null</code>.
51      *
52      * @exception IllegalArgumentException if the <code>String</code>
53      * has zero length.
54      */

55     public NTSid (String JavaDoc stringSid) {
56         if (stringSid == null) {
57         java.text.MessageFormat JavaDoc form = new java.text.MessageFormat JavaDoc
58         (sun.security.util.ResourcesMgr.getString
59             ("invalid null input: value",
60             "sun.security.util.AuthResources"));
61         Object JavaDoc[] source = {"stringSid"};
62             throw new NullPointerException JavaDoc(form.format(source));
63     }
64         if (stringSid.length() == 0) {
65             throw new IllegalArgumentException JavaDoc
66         (sun.security.util.ResourcesMgr.getString
67             ("Invalid NTSid value",
68             "sun.security.util.AuthResources"));
69     }
70         sid = new String JavaDoc(stringSid);
71     }
72     
73     /**
74      * Return a string version of this <code>NTSid</code>.
75      *
76      * <p>
77      *
78      * @return a string version of this <code>NTSid</code>
79      */

80     public String JavaDoc getName() {
81         return sid;
82     }
83     
84     /**
85      * Return a string representation of this <code>NTSid</code>.
86      *
87      * <p>
88      *
89      * @return a string representation of this <code>NTSid</code>.
90      */

91     public String JavaDoc toString() {
92     java.text.MessageFormat JavaDoc form = new java.text.MessageFormat JavaDoc
93         (sun.security.util.ResourcesMgr.getString
94             ("NTSid: name",
95             "sun.security.util.AuthResources"));
96     Object JavaDoc[] source = {sid};
97     return form.format(source);
98     }
99     
100     /**
101      * Compares the specified Object with this <code>NTSid</code>
102      * for equality. Returns true if the given object is also a
103      * <code>NTSid</code> and the two NTSids have the same String
104      * representation.
105      *
106      * <p>
107      *
108      * @param o Object to be compared for equality with this
109      * <code>NTSid</code>.
110      *
111      * @return true if the specified Object is equal to this
112      * <code>NTSid</code>.
113      */

114     public boolean equals(Object JavaDoc o) {
115     if (o == null)
116         return false;
117
118         if (this == o)
119             return true;
120  
121         if (!(o instanceof NTSid))
122             return false;
123         NTSid that = (NTSid)o;
124
125     if (sid.equals(that.sid)) {
126         return true;
127     }
128     return false;
129     }
130     
131     /**
132      * Return a hash code for this <code>NTSid</code>.
133      *
134      * <p>
135      *
136      * @return a hash code for this <code>NTSid</code>.
137      */

138     public int hashCode() {
139         return sid.hashCode();
140     }
141 }
142
Popular Tags