KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > remote > JMXPrincipal


1 /*
2  * @(#)JMXPrincipal.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
9 package javax.management.remote;
10
11 import java.io.Serializable JavaDoc;
12 import java.security.Principal JavaDoc;
13
14 /**
15  * <p>The identity of a remote client of the JMX Remote API.</p>
16  *
17  * <p>Principals such as this <code>JMXPrincipal</code>
18  * may be associated with a particular <code>Subject</code>
19  * to augment that <code>Subject</code> with an additional
20  * identity. Refer to the {@link javax.security.auth.Subject}
21  * class for more information on how to achieve this.
22  * Authorization decisions can then be based upon
23  * the Principals associated with a <code>Subject</code>.
24  *
25  * @see java.security.Principal
26  * @see javax.security.auth.Subject
27  * @since 1.5
28  * @since.unbundled 1.0
29  */

30 public class JMXPrincipal implements Principal JavaDoc, Serializable JavaDoc {
31
32     private static final long serialVersionUID = -4184480100214577411L;
33
34     /**
35      * @serial The JMX Remote API name for the identity represented by
36      * this <code>JMXPrincipal</code> object.
37      * @see #getName()
38      */

39     private String JavaDoc name;
40
41     /**
42      * <p>Creates a JMXPrincipal for a given identity.</p>
43      *
44      * @param name the JMX Remote API name for this identity.
45      *
46      * @exception NullPointerException if the <code>name</code> is
47      * <code>null</code>.
48      */

49     public JMXPrincipal(String JavaDoc name) {
50         if (name == null)
51             throw new NullPointerException JavaDoc("illegal null input");
52
53         this.name = name;
54     }
55
56     /**
57      * Returns the name of this principal.
58      *
59      * <p>
60      *
61      * @return the name of this <code>JMXPrincipal</code>.
62      */

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

74     public String JavaDoc toString() {
75         return("JMXPrincipal: " + name);
76     }
77
78     /**
79      * Compares the specified Object with this <code>JMXPrincipal</code>
80      * for equality. Returns true if the given object is also a
81      * <code>JMXPrincipal</code> and the two JMXPrincipals
82      * have the same name.
83      *
84      * <p>
85      *
86      * @param o Object to be compared for equality with this
87      * <code>JMXPrincipal</code>.
88      *
89      * @return true if the specified Object is equal to this
90      * <code>JMXPrincipal</code>.
91      */

92     public boolean equals(Object JavaDoc o) {
93         if (o == null)
94             return false;
95
96         if (this == o)
97             return true;
98  
99         if (!(o instanceof JMXPrincipal JavaDoc))
100             return false;
101         JMXPrincipal JavaDoc that = (JMXPrincipal JavaDoc)o;
102
103         return (this.getName().equals(that.getName()));
104     }
105  
106     /**
107      * Returns a hash code for this <code>JMXPrincipal</code>.
108      *
109      * <p>
110      *
111      * @return a hash code for this <code>JMXPrincipal</code>.
112      */

113     public int hashCode() {
114         return name.hashCode();
115     }
116 }
117
Popular Tags