01: /*
02: * Created by Dmitry Gavrilov 05.04.2005
03: */
04: package org.gridsphere.services.core.user;
05:
06: import java.io.Serializable;
07: import java.security.Principal;
08:
09: /**
10: * This class represents a very simple implementation of the
11: * <code>java.security.Principal</code> interface.
12: *
13: * @author Dmitry Gavrilov
14: */
15: public class UserPrincipal implements Principal, Serializable {
16:
17: /* A <code> serialVersionUID </code> value. */
18: private static final long serialVersionUID = 3546647607158846512L;
19:
20: /* A name of this principal. */
21: private String principalName = null;
22:
23: /**
24: * Constructs a <code>UserPrincipal</code> object with the given name.
25: *
26: * @param userName the user name
27: * a name of this principal.
28: * @throws IllegalArgumentException
29: * if the name of principal is null.
30: */
31: public UserPrincipal(String userName) {
32: principalName = userName;
33: }
34:
35: /**
36: * Returns a principal's name.
37: *
38: * @return a principal's name.
39: */
40: public String getName() {
41: return principalName;
42: }
43:
44: /*
45: * (non-Javadoc)
46: *
47: * @see java.lang.Object#equals(java.lang.Object)
48: */
49: public boolean equals(Object obj) {
50: if (!(obj instanceof UserPrincipal))
51: return false;
52: UserPrincipal other = (UserPrincipal) obj;
53: return principalName.equals(other.principalName);
54: }
55:
56: /*
57: * (non-Javadoc)
58: *
59: * @see java.lang.Object#hashCode()
60: */
61: public int hashCode() {
62: return principalName.hashCode();
63: }
64:
65: /*
66: * (non-Javadoc)
67: *
68: * @see java.lang.Object#toString()
69: */
70: public String toString() {
71: return principalName;
72: }
73:
74: }
|