1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.security;
24
25 import java.io.Serializable;
26 import java.util.Collections;
27 import java.util.HashSet;
28 import java.util.Set;
29
30 /**
31 * Implementatio of <code>User</code> interface.
32 *
33 * @author Jose M. Palomar
34 * @version $Revision: 124 $
35 */
36 public class UserImpl implements User, Serializable {
37
38
39 /**
40 * Login name of user.
41 */
42 private final String login;
43
44 /**
45 * Real name of user.
46 */
47 private final String name;
48
49 /**
50 * Roles of user.
51 */
52 private final Set roles;
53
54
55 /**
56 * Creates a new <code>UserImpl</code> instance.
57 *
58 * @param login String login name of user.
59 * @param name String real name of user.
60 * @param roles Set roles of user.
61 */
62 public UserImpl(String login, String name, Set roles) {
63 this.login = login;
64 this.name = name;
65 this.roles = Collections.unmodifiableSet(new HashSet(roles));
66 }
67
68
69 /**
70 * Returns login name of user.
71 *
72 * @return String login name of user.
73 * @see org.talika.tarsis.security.User#getLogin()
74 */
75 public final String getLogin() {
76 return login;
77 }
78
79 /**
80 * Returns real name of user.
81 *
82 * @return String real name of user.
83 * @see org.talika.tarsis.security.User#getRealName()
84 */
85 public final String getRealName() {
86 return name;
87 }
88
89 /**
90 * Returns roles of user.
91 *
92 * @return Set roles of user.
93 * @see org.talika.tarsis.security.User#getRoles()
94 */
95 public final Set getRoles() {
96 return roles;
97 }
98
99 /**
100 * Indicates whether some other object is "equal to" this one.
101 *
102 * @param obj Object the reference object with which to compare.
103 * @return boolean <code>true</code> if this object is the same as the obj
104 * argument; <code>false</code> otherwise.
105 */
106 public final boolean equals(Object obj) {
107 return ((obj instanceof User) && ((User) obj).getLogin().equals(this.login));
108 }
109
110 /**
111 * Returns a hash code value for the object.
112 *
113 * @return int a hash code value for this object.
114 */
115 public final int hashCode() {
116 return this.login.hashCode();
117 }
118
119 /**
120 * Returns a string representation of the object.
121 *
122 * @return String a string representation of the object.
123 */
124 public String toString() {
125
126 StringBuffer str = new StringBuffer();
127 str.append("{");
128 str.append(this.login);
129 str.append(";");
130 str.append(this.name);
131 str.append(";");
132 str.append(roles);
133 str.append("}");
134
135 return str.toString();
136 }
137
138 }