1 9 package org.jboss.portal.core.impl.user; 10 11 import java.util.Date ; 12 import java.util.HashMap ; 13 import java.util.HashSet ; 14 import java.util.Map ; 15 import java.util.Set ; 16 import java.util.Calendar ; 17 import java.util.Iterator ; 18 19 import org.apache.log4j.Logger; 20 import org.jboss.portal.core.impl.preferences.MappedPreferenceSet; 21 import org.jboss.portal.core.impl.preferences.MappedPreferenceStore; 22 import org.jboss.portal.core.model.PropertyMap; 23 import org.jboss.portal.core.model.User; 24 import org.jboss.portal.core.model.Role; 25 import org.jboss.portal.core.CoreConstants; 26 import org.jboss.portal.core.security.AuthorizationRealm; 27 import org.jboss.portal.server.plugins.preferences.PreferenceStore; 28 29 38 public class UserImpl 39 implements User 40 { 41 42 private static final Logger log = Logger.getLogger(UserImpl.class); 43 44 private Integer id; 45 46 public String userName; 47 48 public String givenName; 49 50 public String familyName; 51 52 public String realEmail; 53 54 public String fakeEmail; 55 56 public boolean viewRealEmail; 57 58 public String password; 59 60 public boolean enabled = false; 61 62 private UserPrefSet preferenceSet; 63 64 private Map dynamic; 65 66 private PropertyMap properties; 67 68 private Set roles; 69 70 private Date registrationDate; 71 72 private Set roleNames; 73 74 77 private final MappedPreferenceStore store = new MappedPreferenceStore() 78 { 79 protected MappedPreferenceSet getRoot() 80 { 81 if (preferenceSet == null) 82 { 83 if (log.isDebugEnabled()) 84 { 85 log.debug("No root - create a new one"); 86 } 87 preferenceSet = new UserPrefSet("root"); 88 } 89 return preferenceSet; 90 } 91 }; 92 93 96 public UserImpl() 97 { 98 this.id = null; 99 this.userName = null; 100 this.dynamic = new HashMap (); 101 this.properties = new PropertyMapImpl(this); 102 this.roles = new HashSet (); 103 this.registrationDate = new Date (); 104 } 105 106 public UserImpl(String userName) 107 { 108 this.id = null; 109 this.userName = userName; 110 this.dynamic = new HashMap (); 111 this.properties = new PropertyMapImpl(this); 112 this.roles = new HashSet (); 113 this.registrationDate = new Date (); 114 } 115 116 119 private void setID(Integer id) 120 { 121 this.id = id; 122 } 123 124 127 private void setUserName(String userName) 128 { 129 this.userName = userName; 130 } 131 132 public void setGivenName(String givenName) 133 { 134 this.givenName = givenName; 135 } 136 137 public void setFamilyName(String familyName) 138 { 139 this.familyName = familyName; 140 } 141 142 148 private UserPrefSet getRootPreferenceSet() 149 { 150 return preferenceSet; 152 } 153 154 private void setRootPreferenceSet(UserPrefSet preferenceSet) 155 { 156 this.preferenceSet = preferenceSet; 157 } 158 159 172 public Map getDynamic() 173 { 174 return dynamic; 175 } 176 177 180 private void setDynamic(Map dynamic) 181 { 182 this.dynamic = dynamic; 183 } 184 185 188 public void setRoles(Set roles) 189 { 190 this.roles = roles; 191 this.roleNames = null; 192 } 193 194 public Set getRoleNames() 195 { 196 if (roleNames == null) 197 { 198 Iterator it = roles.iterator(); 199 roleNames = new HashSet (); 200 while (it.hasNext()) 201 { 202 roleNames.add(((Role)it.next()).getName()); 203 } 204 } 205 return roleNames; 206 } 207 208 211 216 public Integer getID() 217 { 218 return id; 219 } 220 221 227 public String getUserName() 228 { 229 return userName; 230 } 231 232 238 public String getGivenName() 239 { 240 return givenName; 241 } 242 243 249 public String getFamilyName() 250 { 251 return familyName; 252 } 253 254 public void setPassword(String password) 255 { 256 this.password = password; 257 } 258 259 265 public String getPassword() 266 { 267 return password; 268 } 269 270 276 public String getRealEmail() 277 { 278 return realEmail; 279 } 280 281 public void setRealEmail(String realEmail) 282 { 283 this.realEmail = realEmail; 284 } 285 286 292 public String getFakeEmail() 293 { 294 return fakeEmail; 295 } 296 297 public void setFakeEmail(String fakeEmail) 298 { 299 this.fakeEmail = fakeEmail; 300 } 301 302 308 public Date getRegistrationDate() 309 { 310 return registrationDate; 311 } 312 313 public void setRegistrationDate(Date registrationDate) 314 { 315 this.registrationDate = registrationDate; 316 } 317 318 324 public boolean getViewRealEmail() 325 { 326 return viewRealEmail; 327 } 328 329 public void setViewRealEmail(boolean viewRealEmail) 330 { 331 this.viewRealEmail = viewRealEmail; 332 } 333 334 public void setEnabled(boolean enable) 335 { 336 this.enabled = enable; 337 } 338 339 345 public boolean getEnabled() 346 { 347 return enabled; 348 } 349 350 public PropertyMap getProperties() 351 { 352 return properties; 353 } 354 355 public PreferenceStore getPreferenceStore() 356 { 357 return store; 358 } 359 360 373 public Set getRoles() 374 { 375 return roles; 376 } 377 378 public String toString() 379 { 380 return "User[" + id + "," + userName + "]"; 381 } 382 383 public Date getLastVisitDate() 384 { 385 Date date = null; 386 String dateAsString = (String )getDynamic().get(CoreConstants.INFO_USER_LAST_LOGIN_DATE); 387 if (dateAsString != null) 388 { 389 try 390 { 391 long dateAsLong = Long.parseLong(dateAsString); 392 date = new Date (dateAsLong); 393 } 394 catch (NumberFormatException e) 395 { 396 log.error("Bad date format " + dateAsString + " try to remove it", e); 397 getDynamic().remove(CoreConstants.INFO_USER_LAST_LOGIN_DATE); 398 } 399 } 400 return date; 401 } 402 403 public void setLastVisitDate(Date date) 404 { 405 if (date == null) 406 { 407 getDynamic().remove(CoreConstants.INFO_USER_LAST_LOGIN_DATE); 408 } 409 else 410 { 411 long dateAsLong = date.getTime(); 412 String dateAsString = Long.toString(dateAsLong); 413 getDynamic().put(CoreConstants.INFO_USER_LAST_LOGIN_DATE, dateAsString); 414 } 415 } 416 417 public String getSignature() 418 { 419 return (String )getDynamic().get(CoreConstants.INFO_USER_SIGNATURE); 420 } 421 } 422 | Popular Tags |