42 * class for more information on how to achieve this.
43 * Authorization decisions can then be based upon
44 * the Principals associated with a <code>Subject</code>.
45 *
46 * @see java.security.Principal
47 * @see javax.security.auth.Subject
48 * @since 1.5
49 */
50 public class JMXPrincipal implements Principal, Serializable {
51
52 private static final long serialVersionUID = -4184480100214577411L;
53
54 /**
55 * @serial The JMX Remote API name for the identity represented by
56 * this <code>JMXPrincipal</code> object.
57 * @see #getName()
58 */
59 private String name;
60
61 /**
62 * <p>Creates a JMXPrincipal for a given identity.</p>
63 *
64 * @param name the JMX Remote API name for this identity.
65 *
66 * @exception NullPointerException if the <code>name</code> is
67 * <code>null</code>.
68 */
69 public JMXPrincipal(String name) {
70 validate(name);
71 this.name = name;
72 }
73
74 /**
75 * Returns the name of this principal.
76 *
77 * <p>
78 *
79 * @return the name of this <code>JMXPrincipal</code>.
80 */
81 public String getName() {
82 return name;
83 }
84
85 /**
86 * Returns a string representation of this <code>JMXPrincipal</code>.
87 *
88 * <p>
89 *
90 * @return a string representation of this <code>JMXPrincipal</code>.
91 */
92 public String toString() {
93 return("JMXPrincipal: " + name);
94 }
95
96 /**
97 * Compares the specified Object with this <code>JMXPrincipal</code>
98 * for equality. Returns true if the given object is also a
99 * <code>JMXPrincipal</code> and the two JMXPrincipals
100 * have the same name.
101 *
102 * <p>
103 *
104 * @param o Object to be compared for equality with this
105 * <code>JMXPrincipal</code>.
106 *
107 * @return true if the specified Object is equal to this
108 * <code>JMXPrincipal</code>.
109 */
110 public boolean equals(Object o) {
111 if (o == null)
112 return false;
113
114 if (this == o)
115 return true;
116
117 if (!(o instanceof JMXPrincipal))
118 return false;
119 JMXPrincipal that = (JMXPrincipal)o;
120
121 return (this.getName().equals(that.getName()));
122 }
123
124 /**
125 * Returns a hash code for this <code>JMXPrincipal</code>.
126 *
127 * <p>
128 *
129 * @return a hash code for this <code>JMXPrincipal</code>.
130 */
131 public int hashCode() {
132 return name.hashCode();
133 }
134
135 private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
136 ObjectInputStream.GetField gf = ois.readFields();
137 String principalName = (String)gf.get("name", null);
138 try {
139 validate(principalName);
140 this.name = principalName;
141 } catch (NullPointerException e) {
142 throw new InvalidObjectException(e.getMessage());
143 }
144 }
145
146 private static void validate(String name) throws NullPointerException {
147 if (name == null)
148 throw new NullPointerException("illegal null input");
|
42 * class for more information on how to achieve this.
43 * Authorization decisions can then be based upon
44 * the Principals associated with a <code>Subject</code>.
45 *
46 * @see java.security.Principal
47 * @see javax.security.auth.Subject
48 * @since 1.5
49 */
50 public class JMXPrincipal implements Principal, Serializable {
51
52 private static final long serialVersionUID = -4184480100214577411L;
53
54 /**
55 * @serial The JMX Remote API name for the identity represented by
56 * this <code>JMXPrincipal</code> object.
57 * @see #getName()
58 */
59 private String name;
60
61 /**
62 * Creates a JMXPrincipal for a given identity.
63 *
64 * @param name the JMX Remote API name for this identity.
65 *
66 * @exception NullPointerException if the <code>name</code> is
67 * <code>null</code>.
68 */
69 public JMXPrincipal(String name) {
70 validate(name);
71 this.name = name;
72 }
73
74 /**
75 * Returns the name of this principal.
76 *
77 * @return the name of this <code>JMXPrincipal</code>.
78 */
79 public String getName() {
80 return name;
81 }
82
83 /**
84 * Returns a string representation of this <code>JMXPrincipal</code>.
85 *
86 * @return a string representation of this <code>JMXPrincipal</code>.
87 */
88 public String toString() {
89 return("JMXPrincipal: " + name);
90 }
91
92 /**
93 * Compares the specified Object with this <code>JMXPrincipal</code>
94 * for equality. Returns true if the given object is also a
95 * <code>JMXPrincipal</code> and the two JMXPrincipals
96 * have the same name.
97 *
98 * @param o Object to be compared for equality with this
99 * <code>JMXPrincipal</code>.
100 *
101 * @return true if the specified Object is equal to this
102 * <code>JMXPrincipal</code>.
103 */
104 public boolean equals(Object o) {
105 if (o == null)
106 return false;
107
108 if (this == o)
109 return true;
110
111 if (!(o instanceof JMXPrincipal))
112 return false;
113 JMXPrincipal that = (JMXPrincipal)o;
114
115 return (this.getName().equals(that.getName()));
116 }
117
118 /**
119 * Returns a hash code for this <code>JMXPrincipal</code>.
120 *
121 * @return a hash code for this <code>JMXPrincipal</code>.
122 */
123 public int hashCode() {
124 return name.hashCode();
125 }
126
127 private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
128 ObjectInputStream.GetField gf = ois.readFields();
129 String principalName = (String)gf.get("name", null);
130 try {
131 validate(principalName);
132 this.name = principalName;
133 } catch (NullPointerException e) {
134 throw new InvalidObjectException(e.getMessage());
135 }
136 }
137
138 private static void validate(String name) throws NullPointerException {
139 if (name == null)
140 throw new NullPointerException("illegal null input");
|