|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jsecurity.session.mgt.AbstractSessionManager
org.jsecurity.session.mgt.AbstractValidatingSessionManager
public abstract class AbstractValidatingSessionManager
Default business-tier implementation of the ValidatingSessionManager interface.
| Field Summary | |
|---|---|
static long |
DEFAULT_GLOBAL_SESSION_TIMEOUT
Default main session timeout value (30 * 60 * 1000 milliseconds = 30 minutes). |
static long |
DEFAULT_SESSION_VALIDATION_INTERVAL
The default interval at which sessions will be validated (1 hour); This can be overridden by calling setSessionValidationInterval(long) |
protected long |
globalSessionTimeout
|
protected static long |
MILLIS_PER_HOUR
|
protected static long |
MILLIS_PER_MINUTE
|
protected static long |
MILLIS_PER_SECOND
|
protected long |
sessionValidationInterval
|
protected SessionValidationScheduler |
sessionValidationScheduler
Scheduler used to validate sessions on a regular basis. |
protected boolean |
sessionValidationSchedulerEnabled
|
| Fields inherited from class org.jsecurity.session.mgt.AbstractSessionManager |
|---|
listeners |
| Constructor Summary | |
|---|---|
AbstractValidatingSessionManager()
|
|
| Method Summary | |
|---|---|
protected void |
afterSessionValidationEnabled()
|
protected void |
beforeSessionValidationDisabled()
|
protected Session |
createSession(InetAddress originatingHost)
|
protected SessionValidationScheduler |
createSessionValidationScheduler()
|
void |
destroy()
Called when this object is being destroyed, allowing any necessary cleanup of internal resources. |
protected void |
disableSessionValidation()
|
protected abstract Session |
doCreateSession(InetAddress originatingHost)
|
protected Session |
doGetSession(Serializable sessionId)
|
protected void |
enableSessionValidation()
|
void |
enableSessionValidationIfNecessary()
|
protected abstract Collection<Session> |
getActiveSessions()
|
long |
getGlobalSessionTimeout()
Returns the time in milliseconds that any session may remain idle before expiring. |
long |
getSessionValidationInterval()
|
SessionValidationScheduler |
getSessionValidationScheduler()
|
protected long |
getTimeout(Session session)
Subclass template hook in case per-session timeout is not based on Session.getTimeout(). |
boolean |
isSessionValidationSchedulerEnabled()
|
protected abstract Session |
retrieveSession(Serializable sessionId)
|
void |
setGlobalSessionTimeout(int globalSessionTimeout)
Sets the time in milliseconds that any session may remain idle before expiring. |
void |
setSessionValidationInterval(long sessionValidationInterval)
If using the underlying default SessionValidationScheduler (that is, the setSessionValidationScheduler method is
never called) , this method allows one to specify how
frequently session should be validated (to check for orphans). |
void |
setSessionValidationScheduler(SessionValidationScheduler sessionValidationScheduler)
|
void |
setSessionValidationSchedulerEnabled(boolean sessionValidationSchedulerEnabled)
|
protected void |
validate(Session session)
|
void |
validateSession(Serializable sessionId)
Proactively validates a single session. |
void |
validateSessions()
Performs session validation for all open/active sessions in the system (those that have not been stopped or expired), and validates each one. |
| Methods inherited from class org.jsecurity.session.mgt.AbstractSessionManager |
|---|
add, beforeInvalidNotification, getAttribute, getAttributeKeys, getHostAddress, getLastAccessTime, getSession, getStartTimestamp, getTimeout, isValid, notifyExpiration, notifyStart, notifyStop, onChange, onExpiration, onStop, remove, removeAttribute, setAttribute, setSessionListeners, setTimeout, start, stop, stop, touch |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.jsecurity.session.mgt.SessionManager |
|---|
getAttribute, getAttributeKeys, getHostAddress, getLastAccessTime, getStartTimestamp, getTimeout, isValid, removeAttribute, setAttribute, setTimeout, start, stop, touch |
| Field Detail |
|---|
protected static final long MILLIS_PER_SECOND
protected static final long MILLIS_PER_MINUTE
protected static final long MILLIS_PER_HOUR
public static final long DEFAULT_GLOBAL_SESSION_TIMEOUT
public static final long DEFAULT_SESSION_VALIDATION_INTERVAL
setSessionValidationInterval(long)
protected boolean sessionValidationSchedulerEnabled
protected SessionValidationScheduler sessionValidationScheduler
protected long sessionValidationInterval
protected long globalSessionTimeout
| Constructor Detail |
|---|
public AbstractValidatingSessionManager()
| Method Detail |
|---|
public boolean isSessionValidationSchedulerEnabled()
public void setSessionValidationSchedulerEnabled(boolean sessionValidationSchedulerEnabled)
public void setSessionValidationScheduler(SessionValidationScheduler sessionValidationScheduler)
public SessionValidationScheduler getSessionValidationScheduler()
public void enableSessionValidationIfNecessary()
public long getGlobalSessionTimeout()
getTimeout(Session) method if
so desired.
Unless overridden via the setGlobalSessionTimeout(int) method, the default value is
DEFAULT_GLOBAL_SESSION_TIMEOUT.
public void setGlobalSessionTimeout(int globalSessionTimeout)
getTimeout(org.jsecurity.session.Session) method to determine time-out values on a per-session basis.
globalSessionTimeout - the time in milliseconds any session may remain idle before
expiring.public void setSessionValidationInterval(long sessionValidationInterval)
setSessionValidationScheduler method is
never called) , this method allows one to specify how
frequently session should be validated (to check for orphans). The default value is
DEFAULT_SESSION_VALIDATION_INTERVAL.
If you override the default scheduler, it is assumed that overriding instance 'knows' how often to validate sessions, and this attribute will be ignored.
Unless this method is called, the default value is DEFAULT_SESSION_VALIDATION_INTERVAL.
sessionValidationInterval - the time in milliseconds between checking for valid sessions to reap orphans.public long getSessionValidationInterval()
protected final Session doGetSession(Serializable sessionId)
throws InvalidSessionException
doGetSession in class AbstractSessionManagerInvalidSessionException
protected abstract Session retrieveSession(Serializable sessionId)
throws InvalidSessionException
InvalidSessionException
protected final Session createSession(InetAddress originatingHost)
throws HostUnauthorizedException,
IllegalArgumentException
createSession in class AbstractSessionManagerHostUnauthorizedException
IllegalArgumentException
protected abstract Session doCreateSession(InetAddress originatingHost)
throws HostUnauthorizedException,
IllegalArgumentException
HostUnauthorizedException
IllegalArgumentException
protected void validate(Session session)
throws InvalidSessionException
InvalidSessionExceptionprotected long getTimeout(Session session)
Session.getTimeout().
This implementation merely returns Session.getTimeout()
session - the session for which to determine session timeout.
protected SessionValidationScheduler createSessionValidationScheduler()
protected void enableSessionValidation()
protected void afterSessionValidationEnabled()
protected void disableSessionValidation()
protected void beforeSessionValidationDisabled()
public void destroy()
Destroyable
destroy in interface Destroyablepublic void validateSessions()
ValidatingSessionManagerThis method is necessary in order to handle orphaned sessions and is expected to be run at a regular interval, such as once an hour, once a day or once a week, etc. The "best" frequency to run this method is entirely dependent upon the application and would be based on factors such as performance, average number of active users, hours of least activity, and other things.
Most enterprise applications use a request/response programming model. This is obvious in the case of web applications due to the HTTP protocol, but it is equally true of remote client applications making remote method invocations. The server essentially sits idle and only "works" when responding to client requests and/or method invocations. This type of model is particularly efficent since it means the security system only has to validate a session during those cases. Such "lazy" behavior enables the system to lie stateless and/or idle and only incur overhead for session validation when necessary.
However, if a client forgets to log-out, or in the event of a server failure, it is possible for sessions to be orphaned since no further requests would utilize that session. Because of these lower-probability cases, it is required to regularly clean-up the sessions maintained by the system.
Even in applications that aren't primarily based on a request/response model, such as those that use enterprise asynchronous messaging (where data is pushed to a client without first receiving a client request), it is almost always acceptable to utilize this lazy approach and run this method at defined interval.
Systems that want to proactively validate individual sessions may call the
validateSession method. Note that even in such
proactive systems, this ValidatingSessionManager.validateSessions() method should be invoked regularaly
anyway to guarantee no orphans exist.
Note: JSecurity supports automatic execution of this method at a regular interval
by using SessionValidationSchedulers. The JSecurity default SecurityManager implementations
needing session validation will create and use one by default if one is not provided by the
application configuration.
validateSessions in interface ValidatingSessionManagerValidatingSessionManager.validateSessions()protected abstract Collection<Session> getActiveSessions()
public void validateSession(Serializable sessionId)
ValidatingSessionManager
validateSession in interface ValidatingSessionManagersessionId - the id of the session to validate
|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||