1 18 19 package org.apache.roller.pojos; 20 21 import java.io.Serializable ; 22 import java.util.ArrayList ; 23 import java.util.Date ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Set ; 28 29 import org.apache.roller.RollerException; 30 import org.apache.roller.config.RollerConfig; 31 import org.apache.roller.model.Roller; 32 import org.apache.roller.util.PojoUtil; 33 import org.apache.roller.util.Utilities; 34 35 36 45 public class UserData 46 extends org.apache.roller.pojos.PersistentObject 47 implements Serializable { 48 public static final UserData SYSTEM_USER = new UserData( 49 "n/a","systemuser","n/a","systemuser","n/a", 50 "en_US_WIN", "America/Los_Angeles", new Date (), Boolean.TRUE); 51 52 public static final UserData ANONYMOUS_USER = new UserData( 53 "n/a","anonymoususer","n/a","anonymoususer","n/a", 54 "en_US_WIN", "America/Los_Angeles", new Date (), Boolean.TRUE); 55 56 static final long serialVersionUID = -6354583200913127874L; 57 58 private String id; 59 private String userName; 60 private String password; 61 private String fullName; 62 private String emailAddress; 63 private Date dateCreated; 64 private String locale; 65 private String timeZone; 66 private Boolean enabled = Boolean.TRUE; 67 68 private Set roles = new HashSet (); 69 private List permissions = new ArrayList (); 70 71 public UserData() { 72 } 73 74 public UserData( String id, String userName, 75 String password, String fullName, 76 String emailAddress, 77 String locale, String timeZone, 78 Date dateCreated, 79 Boolean isEnabled) { 80 this.id = id; 81 this.userName = userName; 82 this.password = password; 83 this.fullName = fullName; 84 this.emailAddress = emailAddress; 85 this.dateCreated = (Date )dateCreated.clone(); 86 this.locale = locale; 87 this.timeZone = timeZone; 88 this.enabled = enabled; 89 } 90 91 public UserData( UserData otherData ) { 92 setData(otherData); 93 } 94 95 101 public List getPermissions() { 102 return permissions; 103 } 104 public void setPermissions(List perms) { 105 permissions = perms; 106 } 107 108 112 public Boolean getEnabled() { 113 return this.enabled; 114 } 115 116 117 public void setEnabled(Boolean enabled) { 118 this.enabled = enabled; 119 } 120 121 129 public String getId() { 130 return this.id; 131 } 132 133 134 public void setId( String id ) { 135 this.id = id; 136 } 137 138 143 public String getUserName() { 144 return this.userName; 145 } 146 147 public void setUserName( String userName ) { 148 this.userName = userName; 149 } 150 151 158 public String getPassword() { 159 return this.password; 160 } 161 166 public void setPassword( String password ) { 167 this.password = password; 168 } 169 170 177 public String getFullName() { 178 return this.fullName; 179 } 180 181 public void setFullName( String fullName ) { 182 this.fullName = fullName; 183 } 184 185 192 public String getEmailAddress() { 193 return this.emailAddress; 194 } 195 196 public void setEmailAddress( String emailAddress ) { 197 this.emailAddress = emailAddress; 198 } 199 200 205 public Date getDateCreated() { 206 if (dateCreated == null) { 207 return null; 208 } else { 209 return (Date )dateCreated.clone(); 210 } 211 } 212 213 public void setDateCreated(final Date date) { 214 if (date != null) { 215 dateCreated = (Date )date.clone(); 216 } else { 217 dateCreated = null; 218 } 219 } 220 221 227 public String getLocale() { 228 return this.locale; 229 } 230 231 232 public void setLocale(String locale) { 233 this.locale = locale; 234 } 235 236 242 public String getTimeZone() { 243 return this.timeZone; 244 } 245 246 247 public void setTimeZone(String timeZone) { 248 this.timeZone = timeZone; 249 } 250 251 public String toString() { 253 StringBuffer str = new StringBuffer ("{"); 254 255 str.append("id=" + id + " "); 256 str.append("userName=" + userName + " "); 257 str.append("password=" + password + " "); 258 str.append("fullName=" + fullName + " "); 259 str.append("emailAddress=" + emailAddress + " "); 260 str.append("dateCreated=" + dateCreated + " "); 261 str.append('}'); 262 263 return(str.toString()); 264 } 265 266 public boolean equals( Object pOther ) { 267 if (pOther instanceof UserData) { 268 UserData lTest = (UserData) pOther; 269 boolean lEquals = true; 270 lEquals = PojoUtil.equals(lEquals, this.getId(), lTest.getId()); 271 lEquals = PojoUtil.equals(lEquals, this.getUserName(), lTest.getUserName()); 272 lEquals = PojoUtil.equals(lEquals, this.getPassword(), lTest.getPassword()); 273 lEquals = PojoUtil.equals(lEquals, this.getFullName(), lTest.getFullName()); 274 lEquals = PojoUtil.equals(lEquals, this.getEmailAddress(), lTest.getEmailAddress()); 275 return lEquals; 276 } else { 277 return false; 278 } 279 } 280 281 345 346 private boolean datesEquivalent(Date d1, Date d2) { 347 boolean equiv = true; 348 equiv = equiv && d1.getHours() == d1.getHours(); 349 equiv = equiv && d1.getMinutes() == d1.getMinutes(); 350 equiv = equiv && d1.getSeconds() == d1.getSeconds(); 351 equiv = equiv && d1.getMonth() == d1.getMonth(); 352 equiv = equiv && d1.getDay() == d1.getDay(); 353 equiv = equiv && d1.getYear() == d1.getYear(); 354 return equiv; 355 } 356 357 public int hashCode() { 358 int result = 17; 359 result = 37*result + ((this.id != null) ? this.id.hashCode() : 0); 360 result = 37*result + ((this.userName != null) ? this.userName.hashCode() : 0); 361 result = 37*result + ((this.password != null) ? this.password.hashCode() : 0); 362 result = 37*result + ((this.fullName != null) ? this.fullName.hashCode() : 0); 363 result = 37*result + ((this.emailAddress != null) ? this.emailAddress.hashCode() : 0); 364 result = 37*result + ((this.dateCreated != null) ? this.dateCreated.hashCode() : 0); 365 return result; 366 } 367 368 371 public void setData( org.apache.roller.pojos.PersistentObject otherData ) { 372 UserData other = (UserData)otherData; 373 this.id = other.getId(); 374 this.userName = other.getUserName(); 375 this.password = other.getPassword(); 376 this.fullName = other.getFullName(); 377 this.emailAddress = other.getEmailAddress(); 378 this.locale = other.getLocale(); 379 this.timeZone = other.getTimeZone(); 380 this.dateCreated = other.getDateCreated()!=null ? (Date )other.getDateCreated().clone() : null; 381 } 382 383 384 391 public void resetPassword(Roller roller, String new1, String new2) throws RollerException { 392 if (!new1.equals(new2)) { 393 throw new RollerException("newUser.error.mismatchedPasswords"); 394 } 395 396 String encrypt = RollerConfig.getProperty("passwds.encryption.enabled"); 397 String algorithm = RollerConfig.getProperty("passwds.encryption.algorithm"); 398 if (new Boolean (encrypt).booleanValue()) { 399 password = Utilities.encodePassword(new1, algorithm); 400 } else { 401 password = new1; 402 } 403 } 404 405 406 411 public Set getRoles() { 412 return roles; 413 } 414 415 418 private void setRoles(Set roles) { 419 this.roles = roles; 420 } 421 422 423 426 public boolean hasRole(String roleName) { 427 Iterator iter = roles.iterator(); 428 while (iter.hasNext()) { 429 RoleData role = (RoleData) iter.next(); 430 if (role.getRole().equals(roleName)) { 431 return true; 432 } 433 } 434 return false; 435 } 436 437 438 441 public void revokeRole(String roleName) throws RollerException { 442 RoleData removeme = null; 443 Iterator iter = roles.iterator(); 444 while (iter.hasNext()) { 445 RoleData role = (RoleData) iter.next(); 446 if (role.getRole().equals(roleName)) { 447 removeme = role; 448 } 449 } 450 451 456 if(removeme != null) { 457 roles.remove(removeme); 458 } 459 } 460 461 462 465 public void grantRole(String roleName) throws RollerException { 466 if (!hasRole(roleName)) { 467 RoleData role = new RoleData(null, this, roleName); 468 roles.add(role); 469 } 470 } 471 472 } 473 | Popular Tags |