1 24 25 package com.rift.coad.lib.security; 27 28 import org.apache.log4j.Logger; 30 31 32 38 public final class SessionManager { 39 40 private Logger log = 42 Logger.getLogger(SessionManager.class.getName()); 43 44 45 private static SessionManager singleton = null; 47 48 private ThreadsPermissionContainer permissions = null; 50 51 52 55 private SessionManager(ThreadsPermissionContainer permissions) { 56 this.permissions = permissions; 57 } 58 59 60 67 public synchronized static SessionManager init( 68 ThreadsPermissionContainer permissions) 69 throws SecurityException { 70 if (singleton != null) { 71 throw new SecurityException ( 72 "The SessionManager has already been initialized."); 73 } 74 singleton = new SessionManager(permissions); 75 return singleton; 76 } 77 78 79 85 public synchronized static SessionManager getInstance() 86 throws SecurityException { 87 if (singleton != null) { 88 return singleton; 89 } 90 throw new SecurityException ( 91 "The session manager has not been initialized"); 92 } 93 94 95 102 public void initSession() throws SecurityException { 103 Long threadId = new Long (Thread.currentThread().getId()); 104 permissions.putSession(threadId, 105 new ThreadPermissionSession(threadId,new UserSession())); 106 } 107 108 109 116 public ThreadPermissionSession getSession() 117 throws SecurityException { 118 return permissions.getSession(); 119 } 120 121 122 127 public void purgeSession() throws SecurityException { 128 Long threadId = new Long (Thread.currentThread().getId()); 129 permissions.removeSession(threadId); 130 } 131 } 132 | Popular Tags |