001: package org.contineo.core.security;
002:
003: import java.io.Serializable;
004: import java.util.HashSet;
005: import java.util.Iterator;
006: import java.util.Set;
007:
008: import org.apache.commons.lang.builder.ReflectionToStringBuilder;
009: import org.contineo.core.CryptBean;
010:
011: /**
012: * This class represents a user.
013: *
014: * @author Michael Scholz
015: * @author Marco Meschieri
016: * @version 1.0
017: */
018: public class User implements Serializable {
019:
020: private static final long serialVersionUID = 8093874904302301982L;
021:
022: private String userName = "";
023:
024: private String password = "";
025:
026: private String name = "";
027:
028: private String firstName = "";
029:
030: private String street = "";
031:
032: private String postalcode = "";
033:
034: private String city = "";
035:
036: private String country = "";
037:
038: private String language = "";
039:
040: private String email = "";
041:
042: private String telephone = "";
043:
044: private Set<Group> groups = new HashSet<Group>();
045:
046: private String[] groupNames;
047:
048: // Only for GUI
049: private String repass;
050:
051: public User() {
052: }
053:
054: public String getRepass() {
055: return repass;
056: }
057:
058: public void setRepass(String repass) {
059: this .repass = repass;
060: }
061:
062: public String getUserName() {
063: return userName;
064: }
065:
066: public String getPassword() {
067: return password;
068: }
069:
070: public String getName() {
071: return name;
072: }
073:
074: public String getFirstName() {
075: return firstName;
076: }
077:
078: public String getStreet() {
079: return street;
080: }
081:
082: public String getPostalcode() {
083: return postalcode;
084: }
085:
086: public String getCity() {
087: return city;
088: }
089:
090: public String getCountry() {
091: return country;
092: }
093:
094: public String getLanguage() {
095: return language;
096: }
097:
098: public String getEmail() {
099: return email;
100: }
101:
102: public String getTelephone() {
103: return telephone;
104: }
105:
106: public String[] getGroupNames() {
107: return groupNames;
108: }
109:
110: public void setUserName(String uname) {
111: userName = uname;
112: }
113:
114: public void setPassword(String pwd) {
115: password = pwd;
116: }
117:
118: /**
119: * Sets the password and encode it
120: *
121: * @param pwd The password in readable format
122: */
123: public void setDecodedPassword(String pwd) {
124: if ((pwd != null) && !pwd.trim().equals("")) {
125: password = CryptBean.cryptString(pwd);
126: }
127: }
128:
129: public String getDecodedPassword() {
130: return password;
131: }
132:
133: public void setName(String nm) {
134: name = nm;
135: }
136:
137: public void setFirstName(String fname) {
138: firstName = fname;
139: }
140:
141: public void setStreet(String str) {
142: street = str;
143: }
144:
145: public void setPostalcode(String pc) {
146: postalcode = pc;
147: }
148:
149: public void setCity(String ct) {
150: city = ct;
151: }
152:
153: public void setCountry(String cnt) {
154: country = cnt;
155: }
156:
157: public void setLanguage(String lang) {
158: language = lang;
159: }
160:
161: public void setEmail(String mail) {
162: email = mail;
163: }
164:
165: public void setTelephone(String phone) {
166: telephone = phone;
167: }
168:
169: public void setGroupNames(String[] grp) {
170: groupNames = grp;
171: }
172:
173: public void initGroupNames() {
174: try {
175: groupNames = new String[groups.size()];
176:
177: Iterator iter = groups.iterator();
178: int i = 0;
179:
180: while (iter.hasNext()) {
181: Group ug = (Group) iter.next();
182: groupNames[i] = ug.getGroupName();
183: i++;
184: }
185: } catch (Exception e) {
186: ;
187: }
188: }
189:
190: public void reset() {
191: userName = "";
192: password = "";
193: name = "";
194: firstName = "";
195: street = "";
196: postalcode = "";
197: city = "";
198: country = "";
199: language = "";
200: email = "";
201: telephone = "";
202: groups = new HashSet<Group>();
203: groupNames = null;
204: }
205:
206: public String toString() {
207: // return ReflectionToStringBuilder.toString(this);
208: return (new ReflectionToStringBuilder(this ) {
209: protected boolean accept(java.lang.reflect.Field f) {
210: return super .accept(f);
211: } // end method accept
212: }).toString();
213: }
214:
215: @Override
216: public boolean equals(Object obj) {
217: if (!(obj instanceof User))
218: return false;
219:
220: User other = (User) obj;
221: return other.getUserName().equals(this .getUserName());
222: }
223:
224: @Override
225: public int hashCode() {
226: return userName.hashCode();
227: }
228:
229: public Set<Group> getGroups() {
230: return groups;
231: }
232:
233: public void setGroups(Set<Group> groups) {
234: this.groups = groups;
235: }
236: }
|