1 package org.appfuse.model; 2 3 import java.io.Serializable ; 4 import java.util.HashSet ; 5 import java.util.Set ; 6 7 import org.acegisecurity.GrantedAuthority; 8 import org.acegisecurity.userdetails.UserDetails; 9 import org.apache.commons.lang.builder.ToStringBuilder; 10 import org.apache.commons.lang.builder.ToStringStyle; 11 12 27 public class User extends BaseObject implements Serializable , UserDetails { 28 private static final long serialVersionUID = 3832626162173359411L; 29 30 protected Long id; 31 protected String username; protected String password; protected String confirmPassword; 34 protected String passwordHint; 35 protected String firstName; protected String lastName; protected String email; protected String phoneNumber; 39 protected String website; 40 protected Address address = new Address(); 41 protected Integer version; 42 protected Set roles = new HashSet (); 43 protected boolean enabled; 44 protected boolean accountExpired; 45 protected boolean accountLocked; 46 protected boolean credentialsExpired; 47 48 public User() {} 49 50 public User(String username) { 51 this.username = username; 52 } 53 54 57 public Long getId() { 58 return id; 59 } 60 61 65 public String getUsername() { 66 return username; 67 } 68 69 77 public String getPassword() { 78 return password; 79 } 80 81 84 public String getConfirmPassword() { 85 return confirmPassword; 86 } 87 88 92 public String getPasswordHint() { 93 return passwordHint; 94 } 95 96 100 public String getFirstName() { 101 return firstName; 102 } 103 104 108 public String getLastName() { 109 return lastName; 110 } 111 112 117 public String getEmail() { 118 return email; 119 } 120 121 126 public String getPhoneNumber() { 127 return phoneNumber; 128 } 129 130 134 public String getWebsite() { 135 return website; 136 } 137 138 141 public String getFullName() { 142 return firstName + ' ' + lastName; 143 } 144 145 148 public Address getAddress() { 149 return address; 150 } 151 152 157 public Set getRoles() { 158 return roles; 159 } 160 161 165 public void addRole(Role role) { 166 getRoles().add(role); 167 } 168 169 172 public GrantedAuthority[] getAuthorities() { 173 return (GrantedAuthority[]) roles.toArray(new GrantedAuthority[0]); 174 } 175 176 179 public Integer getVersion() { 180 return version; 181 } 182 183 186 public boolean isEnabled() { 187 return enabled; 188 } 189 190 193 public boolean isAccountExpired() { 194 return accountExpired; 195 } 196 197 200 public boolean isAccountNonExpired() { 201 return !isAccountExpired(); 202 } 203 204 207 public boolean isAccountLocked() { 208 return accountLocked; 209 } 210 211 214 public boolean isAccountNonLocked() { 215 return !isAccountLocked(); 216 } 217 218 221 public boolean isCredentialsExpired() { 222 return credentialsExpired; 223 } 224 225 228 public boolean isCredentialsNonExpired() { 229 return !credentialsExpired; 230 } 231 232 public void setId(Long id) { 233 this.id = id; 234 } 235 236 public void setUsername(String username) { 237 this.username = username; 238 } 239 240 public void setPassword(String password) { 241 this.password = password; 242 } 243 244 public void setConfirmPassword(String confirmPassword) { 245 this.confirmPassword = confirmPassword; 246 } 247 248 public void setPasswordHint(String passwordHint) { 249 this.passwordHint = passwordHint; 250 } 251 252 public void setFirstName(String firstName) { 253 this.firstName = firstName; 254 } 255 256 public void setLastName(String lastName) { 257 this.lastName = lastName; 258 } 259 260 public void setEmail(String email) { 261 this.email = email; 262 } 263 264 public void setPhoneNumber(String phoneNumber) { 265 this.phoneNumber = phoneNumber; 266 } 267 268 public void setWebsite(String website) { 269 this.website = website; 270 } 271 272 public void setAddress(Address address) { 273 this.address = address; 274 } 275 276 public void setRoles(Set roles) { 277 this.roles = roles; 278 } 279 280 public void setVersion(Integer version) { 281 this.version = version; 282 } 283 284 public void setEnabled(boolean enabled) { 285 this.enabled = enabled; 286 } 287 288 public void setAccountExpired(boolean accountExpired) { 289 this.accountExpired = accountExpired; 290 } 291 292 public void setAccountLocked(boolean accountLocked) { 293 this.accountLocked = accountLocked; 294 } 295 296 public void setCredentialsExpired(boolean credentialsExpired) { 297 this.credentialsExpired = credentialsExpired; 298 } 299 300 public boolean equals(Object o) { 301 if (this == o) return true; 302 if (!(o instanceof User)) return false; 303 304 final User user = (User) o; 305 306 if (username != null ? !username.equals(user.getUsername()) : user.getUsername() != null) return false; 307 308 return true; 309 } 310 311 public int hashCode() { 312 return (username != null ? username.hashCode() : 0); 313 } 314 315 public String toString() { 316 ToStringBuilder sb = new ToStringBuilder(this, 317 ToStringStyle.DEFAULT_STYLE).append("username", this.username) 318 .append("enabled", this.enabled) 319 .append("accountExpired",this.accountExpired) 320 .append("credentialsExpired",this.credentialsExpired) 321 .append("accountLocked",this.accountLocked); 322 323 GrantedAuthority[] auths = this.getAuthorities(); 324 if (auths != null) { 325 sb.append("Granted Authorities: "); 326 327 for (int i = 0; i < auths.length; i++) { 328 if (i > 0) { 329 sb.append(", "); 330 } 331 sb.append(auths[i].toString()); 332 } 333 } else { 334 sb.append("No Granted Authorities"); 335 } 336 return sb.toString(); 337 } 338 } 339 | Popular Tags |