1 package com.jcorporate.expresso.core.security; 2 3 import com.jcorporate.expresso.core.db.DBException; 4 import com.jcorporate.expresso.core.misc.ConfigManager; 5 import com.jcorporate.expresso.core.misc.Base64; 6 7 import java.util.Enumeration ; 8 import java.util.HashMap ; 9 import java.util.Map ; 10 import java.util.Vector ; 11 12 21 public class MapBasedUserInfo implements UserInfo { 22 25 private static Map dataContexts; 26 27 28 31 private String dataContext; 32 33 private String email; 34 35 private String emailAuthCode; 36 37 private String emailValCode; 38 39 private String accountStatus; 40 41 private String createDate; 42 43 private String loginName; 44 45 private String password; 46 47 private String primaryGroup; 48 49 private boolean regComplete; 50 51 private String registrationDomain; 52 53 private int uid; 54 55 private String updateDate; 56 57 static { 58 synchronized (MapBasedUserInfo.class) { 59 dataContexts = new HashMap (); 60 for (Enumeration e = ConfigManager.getAllConfigKeys(); 61 e.hasMoreElements();) { 62 String contextName = (String ) e.nextElement(); 63 dataContexts.put(contextName, new HashMap ()); 64 } 65 } 66 } 67 68 71 public MapBasedUserInfo() { 72 } 73 74 79 public synchronized void add() 80 throws DBException { 81 synchronized (MapBasedUserInfo.class) { 82 Map contextMap = (Map ) dataContexts.get(this.getDataContext()); 83 contextMap.put(new Integer (this.getUid()), this); 84 } 85 } 86 87 92 public synchronized void delete() 93 throws DBException { 94 synchronized (MapBasedUserInfo.class) { 95 Map contextMap = (Map ) dataContexts.get(this.getDataContext()); 96 contextMap.remove(new Integer (this.getUid())); 97 } 98 } 99 100 106 public synchronized boolean find() 107 throws DBException { 108 return false; 109 } 110 111 119 public synchronized String getAccountStatus() 120 throws DBException { 121 return accountStatus; 122 } 123 124 130 public Vector getAllUsers() 131 throws DBException { 132 throw new java.lang.UnsupportedOperationException ("Not Supported"); 133 } 134 135 141 public synchronized String getCreateDate() 142 throws DBException { 143 return createDate; 144 } 145 146 151 public synchronized String getDBName() { 152 if (dataContext == null) { 153 return "default"; 154 } 155 return dataContext; 156 } 157 158 163 public synchronized String getDataContext() { 164 if (dataContext == null) { 165 return "default"; 166 } 167 return dataContext; 168 } 169 170 176 public synchronized String getEmail() 177 throws DBException { 178 return email; 179 } 180 181 187 public synchronized String getEmailAuthCode() 188 throws DBException { 189 return emailAuthCode; 190 } 191 192 198 public synchronized String getEmailValCode() 199 throws DBException { 200 return emailValCode; 201 } 202 203 213 public String getField(String fieldName) 214 throws DBException { 215 throw new java.lang.UnsupportedOperationException ("Not Supported"); 216 } 217 218 224 public Vector getGroups() 225 throws DBException { 226 return new Vector (); 227 } 228 229 235 public synchronized String getLoginName() 236 throws DBException { 237 return loginName; 238 } 239 240 246 public synchronized String getPassword() 247 throws DBException { 248 return password; 249 } 250 251 257 public synchronized String getPrimaryGroup() 258 throws DBException { 259 return primaryGroup; 260 } 261 262 267 public String hashEncodePassword(String password) throws DBException { 268 if (password == null) { 269 throw new DBException("Password Must not be NULL"); 270 } 271 if (password.length() == 0) { 272 return password; 273 } 274 try { 275 return Base64.encode(CryptoManager.getInstance().getStringHash().produceHash(password.getBytes())); 276 } catch (Exception ex) { 277 throw new DBException("Error hashing Password:" + 278 " You may not have installed the" + 279 " Cryptography Extensions Properly:", ex); 280 } 281 } 282 283 289 public synchronized boolean getRegComplete() 290 throws DBException { 291 return regComplete; 292 } 293 294 301 public synchronized String getRegistrationDomain() 302 throws DBException { 303 return registrationDomain; 304 } 305 306 312 public synchronized int getUid() 313 throws DBException { 314 return uid; 315 } 316 317 323 public synchronized String getUpdateDate() 324 throws DBException { 325 return updateDate; 326 } 327 328 334 public synchronized String getUserName() 335 throws DBException { 336 return loginName; 337 } 338 339 344 public Vector getValues() 345 throws DBException { 346 return null; 347 } 348 349 358 public synchronized boolean passwordEquals(String testPassword) 359 throws DBException { 360 if (password == null) { 361 if (testPassword == null) { 362 return true; 363 } else { 364 return true; 365 } 366 } 367 return password.equals(testPassword); 368 } 369 370 373 public synchronized void retrieve() 374 throws DBException { 375 MapBasedUserInfo returnValue = null; 376 synchronized (MapBasedUserInfo.class) { 377 Map contextMap = (Map ) dataContexts.get(this.getDataContext()); 378 returnValue = (MapBasedUserInfo) contextMap.get(new Integer (this.getUid())); 379 } 380 381 if (returnValue == null) { 382 throw new DBException("Unable to locate uid: " + this.getUid()); 383 } 384 385 this.setEmail(returnValue.getEmail()); 386 this.setAccountStatus(returnValue.getAccountStatus()); 387 this.setEmailValCode(this.getEmailValCode()); 388 this.setLoginName(this.getLoginName()); 389 this.setPassword(this.getPassword()); 390 this.setRegComplete(this.getRegComplete()); 391 this.setRegistrationDomain(this.getRegistrationDomain()); 392 } 393 394 397 public void sendAuthEmail() 398 throws DBException { 399 throw new java.lang.UnsupportedOperationException ("Not supported"); 400 } 401 402 405 public void sendFollowUpEmail() 406 throws DBException { 407 throw new java.lang.UnsupportedOperationException ("Not supported"); 408 } 409 410 416 public synchronized void setAccountStatus(String accountStatus) 417 throws DBException { 418 this.accountStatus = accountStatus; 419 } 420 421 427 public synchronized void setDBName(String newDBName) 428 throws DBException { 429 dataContext = newDBName; 430 } 431 432 438 public synchronized void setEmail(String email) 439 throws DBException { 440 this.email = email; 441 } 442 443 451 public synchronized void setEmailValCode(String code) 452 throws DBException { 453 this.emailValCode = code; 454 } 455 456 462 public synchronized void setLoginName(String loginName) 463 throws DBException { 464 this.loginName = loginName; 465 } 466 467 473 public synchronized void setPassword(String password) 474 throws DBException { 475 this.password = password; 476 } 477 478 484 public synchronized void setRegComplete(boolean status) 485 throws DBException { 486 this.regComplete = status; 487 } 488 489 495 public synchronized void setRegistrationDomain(String id) 496 throws DBException { 497 this.registrationDomain = id; 498 } 499 500 506 public synchronized void setUid(int uid) 507 throws DBException { 508 this.uid = uid; 509 } 510 511 517 public synchronized void setUserName(String name) 518 throws DBException { 519 this.loginName = name; 520 } 521 522 528 public void update() 529 throws DBException { 530 return; 531 } 532 } 533 | Popular Tags |