KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)X500Principal.java 1.12 04/05/18
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 import sun.security.x509.X500Name;
12
13 /**
14  * <p> This class represents an X.500 <code>Principal</code>.
15  * X500Principals have names such as,
16  * "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"
17  * (RFC 1779 style).
18  *
19  * <p> Principals such as this <code>X500Principal</code>
20  * may be associated with a particular <code>Subject</code>
21  * to augment that <code>Subject</code> with an additional
22  * identity. Refer to the <code>Subject</code> class for more information
23  * on how to achieve this. Authorization decisions can then be based upon
24  * the Principals associated with a <code>Subject</code>.
25  *
26  * @version 1.12, 05/18/04
27  * @see java.security.Principal
28  * @see javax.security.auth.Subject
29  * @deprecated A new X500Principal class is available in the Java 2 platform.
30  * This X500Principal classs is entirely deprecated and
31  * is here to allow for a smooth transition to the new
32  * class.
33  * @see javax.security.auth.x500.X500Principal
34 */

35 @Deprecated JavaDoc
36 public class X500Principal implements Principal JavaDoc, java.io.Serializable JavaDoc {
37
38     private static final long serialVersionUID = -8222422609431628648L;
39
40     private static final java.util.ResourceBundle JavaDoc rb =
41           (java.util.ResourceBundle JavaDoc)java.security.AccessController.doPrivileged
42           (new java.security.PrivilegedAction JavaDoc() {
43               public Object JavaDoc run() {
44                   return (java.util.ResourceBundle.getBundle
45                                 ("sun.security.util.AuthResources"));
46               }
47       });
48
49     /**
50      * @serial
51      */

52     private String JavaDoc name;
53
54     transient private X500Name thisX500Name;
55
56     /**
57      * Create a X500Principal with an X.500 Name,
58      * such as "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"
59      * (RFC 1779 style).
60      *
61      * <p>
62      *
63      * @param name the X.500 name
64      *
65      * @exception NullPointerException if the <code>name</code>
66      * is <code>null</code>. <p>
67      *
68      * @exception IllegalArgumentException if the <code>name</code>
69      * is improperly specified.
70      */

71     public X500Principal(String JavaDoc name) {
72     if (name == null)
73         throw new NullPointerException JavaDoc(rb.getString("provided null name"));
74
75     try {
76         thisX500Name = new X500Name(name);
77     } catch (Exception JavaDoc e) {
78         throw new IllegalArgumentException JavaDoc(e.toString());
79     }
80
81     this.name = name;
82     }
83
84     /**
85      * Return the Unix username for this <code>X500Principal</code>.
86      *
87      * <p>
88      *
89      * @return the Unix username for this <code>X500Principal</code>
90      */

91     public String JavaDoc getName() {
92     return thisX500Name.getName();
93     }
94
95     /**
96      * Return a string representation of this <code>X500Principal</code>.
97      *
98      * <p>
99      *
100      * @return a string representation of this <code>X500Principal</code>.
101      */

102     public String JavaDoc toString() {
103     return thisX500Name.toString();
104     }
105
106     /**
107      * Compares the specified Object with this <code>X500Principal</code>
108      * for equality.
109      *
110      * <p>
111      *
112      * @param o Object to be compared for equality with this
113      * <code>X500Principal</code>.
114      *
115      * @return true if the specified Object is equal equal to this
116      * <code>X500Principal</code>.
117      */

118     public boolean equals(Object JavaDoc o) {
119     if (o == null)
120         return false;
121
122         if (this == o)
123             return true;
124
125     if (o instanceof X500Principal) {
126         X500Principal that = (X500Principal)o;
127         try {
128         X500Name thatX500Name = new X500Name(that.getName());
129         return thisX500Name.equals(thatX500Name);
130         } catch (Exception JavaDoc e) {
131         // any parsing exceptions, return false
132
return false;
133         }
134     } else if (o instanceof Principal JavaDoc) {
135         // this will return 'true' if 'o' is a sun.security.x509.X500Name
136
// and the X500Names are equal
137
return o.equals(thisX500Name);
138     }
139  
140     return false;
141     }
142  
143     /**
144      * Return a hash code for this <code>X500Principal</code>.
145      *
146      * <p>
147      *
148      * @return a hash code for this <code>X500Principal</code>.
149      */

150     public int hashCode() {
151     return thisX500Name.hashCode();
152     }
153
154     /**
155      * Reads this object from a stream (i.e., deserializes it)
156      */

157     private void readObject(java.io.ObjectInputStream JavaDoc s) throws
158                     java.io.IOException JavaDoc,
159                     java.io.NotActiveException JavaDoc,
160                     ClassNotFoundException JavaDoc {
161
162     s.defaultReadObject();
163
164     // re-create thisX500Name
165
thisX500Name = new X500Name(name);
166     }
167 }
168
Popular Tags