Package org.apache.shiro.session.mgt
Class DefaultSessionManager
- java.lang.Object
-
- org.apache.shiro.session.mgt.AbstractSessionManager
-
- org.apache.shiro.session.mgt.AbstractNativeSessionManager
-
- org.apache.shiro.session.mgt.AbstractValidatingSessionManager
-
- org.apache.shiro.session.mgt.DefaultSessionManager
-
- All Implemented Interfaces:
org.apache.shiro.cache.CacheManagerAware
,org.apache.shiro.event.EventBusAware
,NativeSessionManager
,SessionManager
,ValidatingSessionManager
,org.apache.shiro.util.Destroyable
public class DefaultSessionManager extends AbstractValidatingSessionManager implements org.apache.shiro.cache.CacheManagerAware
Default business-tier implementation of aValidatingSessionManager
. All session CRUD operations are delegated to an internalSessionDAO
.- Since:
- 0.1
-
-
Field Summary
Fields Modifier and Type Field Description protected SessionDAO
sessionDAO
-
Fields inherited from class org.apache.shiro.session.mgt.AbstractValidatingSessionManager
DEFAULT_SESSION_VALIDATION_INTERVAL, sessionValidationInterval, sessionValidationScheduler, sessionValidationSchedulerEnabled
-
Fields inherited from class org.apache.shiro.session.mgt.AbstractSessionManager
DEFAULT_GLOBAL_SESSION_TIMEOUT, MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND
-
-
Constructor Summary
Constructors Constructor Description DefaultSessionManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterExpired(Session session)
protected void
afterStopped(Session session)
protected void
create(Session session)
Persists the given session instance to an underlying EIS (Enterprise Information System).protected void
delete(Session session)
protected Session
doCreateSession(SessionContext context)
protected Collection<Session>
getActiveSessions()
SessionDAO
getSessionDAO()
SessionFactory
getSessionFactory()
Returns theSessionFactory
used to generate newSession
instances.protected Serializable
getSessionId(SessionKey sessionKey)
boolean
isDeleteInvalidSessions()
Returnstrue
if sessions should be automatically deleted after they are discovered to be invalid,false
if invalid sessions will be manually deleted by some process external to Shiro's control.protected Session
newSessionInstance(SessionContext context)
protected void
onChange(Session session)
protected void
onExpiration(Session session)
protected void
onStop(Session session)
protected Session
retrieveSession(SessionKey sessionKey)
Looks up a session from the underlying data store based on the specified session key.protected Session
retrieveSessionFromDataSource(Serializable sessionId)
void
setCacheManager(org.apache.shiro.cache.CacheManager cacheManager)
void
setDeleteInvalidSessions(boolean deleteInvalidSessions)
Sets whether or not sessions should be automatically deleted after they are discovered to be invalid.void
setSessionDAO(SessionDAO sessionDAO)
void
setSessionFactory(SessionFactory sessionFactory)
Sets theSessionFactory
used to generate newSession
instances.-
Methods inherited from class org.apache.shiro.session.mgt.AbstractValidatingSessionManager
afterSessionValidationEnabled, beforeSessionValidationDisabled, createSession, createSessionValidationScheduler, destroy, disableSessionValidation, doGetSession, doValidate, enableSessionValidation, getSessionValidationInterval, getSessionValidationScheduler, getTimeout, isSessionValidationSchedulerEnabled, onExpiration, onInvalidation, setSessionValidationInterval, setSessionValidationScheduler, setSessionValidationSchedulerEnabled, validate, validateSessions
-
Methods inherited from class org.apache.shiro.session.mgt.AbstractNativeSessionManager
applyGlobalSessionTimeout, beforeInvalidNotification, checkValid, createExposedSession, createExposedSession, getAttribute, getAttributeKeys, getEventBus, getHost, getLastAccessTime, getSession, getSessionListeners, getStartTimestamp, getTimeout, isValid, notifyExpiration, notifyStart, notifyStop, onStart, onStop, publishEvent, removeAttribute, setAttribute, setEventBus, setSessionListeners, setTimeout, start, stop, touch
-
Methods inherited from class org.apache.shiro.session.mgt.AbstractSessionManager
getGlobalSessionTimeout, setGlobalSessionTimeout
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.shiro.session.mgt.SessionManager
getSession, start
-
-
-
-
Field Detail
-
sessionDAO
protected SessionDAO sessionDAO
-
-
Method Detail
-
setSessionDAO
public void setSessionDAO(SessionDAO sessionDAO)
-
getSessionDAO
public SessionDAO getSessionDAO()
-
getSessionFactory
public SessionFactory getSessionFactory()
Returns theSessionFactory
used to generate newSession
instances. The default instance is aSimpleSessionFactory
.- Returns:
- the
SessionFactory
used to generate newSession
instances. - Since:
- 1.0
-
setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)
Sets theSessionFactory
used to generate newSession
instances. The default instance is aSimpleSessionFactory
.- Parameters:
sessionFactory
- theSessionFactory
used to generate newSession
instances.- Since:
- 1.0
-
isDeleteInvalidSessions
public boolean isDeleteInvalidSessions()
Returnstrue
if sessions should be automatically deleted after they are discovered to be invalid,false
if invalid sessions will be manually deleted by some process external to Shiro's control. The default istrue
to ensure no orphans exist in the underlying data store.Usage
It is ok to set this tofalse
ONLY if you have some other process that you manage yourself that periodically deletes invalid sessions from the backing data store over time, such as via a Quartz or Cron job. If you do not do this, the invalid sessions will become 'orphans' and fill up the data store over time. This property is provided because some systems need the ability to perform querying/reporting against sessions in the data store, even after they have stopped or expired. Setting this attribute tofalse
will allow such querying, but with the caveat that the application developer/configurer deletes the sessions themselves by some other means (cron, quartz, etc).- Returns:
true
if sessions should be automatically deleted after they are discovered to be invalid,false
if invalid sessions will be manually deleted by some process external to Shiro's control.- Since:
- 1.0
-
setDeleteInvalidSessions
public void setDeleteInvalidSessions(boolean deleteInvalidSessions)
Sets whether or not sessions should be automatically deleted after they are discovered to be invalid. Default value istrue
to ensure no orphans will exist in the underlying data store.WARNING
Only set this value tofalse
if you are manually going to delete sessions yourself by some process (quartz, cron, etc) external to Shiro's control. See theisDeleteInvalidSessions()
JavaDoc for more.- Parameters:
deleteInvalidSessions
- whether or not sessions should be automatically deleted after they are discovered to be invalid.- Since:
- 1.0
-
setCacheManager
public void setCacheManager(org.apache.shiro.cache.CacheManager cacheManager)
- Specified by:
setCacheManager
in interfaceorg.apache.shiro.cache.CacheManagerAware
-
doCreateSession
protected Session doCreateSession(SessionContext context)
- Specified by:
doCreateSession
in classAbstractValidatingSessionManager
-
newSessionInstance
protected Session newSessionInstance(SessionContext context)
-
create
protected void create(Session session)
Persists the given session instance to an underlying EIS (Enterprise Information System). This implementation delegates and callsthis.
sessionDAO
.create
(session);- Parameters:
session
- the Session instance to persist to the underlying EIS.
-
onStop
protected void onStop(Session session)
- Overrides:
onStop
in classAbstractNativeSessionManager
-
afterStopped
protected void afterStopped(Session session)
- Overrides:
afterStopped
in classAbstractNativeSessionManager
-
onExpiration
protected void onExpiration(Session session)
- Overrides:
onExpiration
in classAbstractValidatingSessionManager
-
afterExpired
protected void afterExpired(Session session)
- Overrides:
afterExpired
in classAbstractValidatingSessionManager
-
onChange
protected void onChange(Session session)
- Overrides:
onChange
in classAbstractNativeSessionManager
-
retrieveSession
protected Session retrieveSession(SessionKey sessionKey) throws UnknownSessionException
Description copied from class:AbstractValidatingSessionManager
Looks up a session from the underlying data store based on the specified session key.- Specified by:
retrieveSession
in classAbstractValidatingSessionManager
- Parameters:
sessionKey
- the session key to use to look up the target session.- Returns:
- the session identified by
sessionId
. - Throws:
UnknownSessionException
- if there is no session identified bysessionId
.
-
getSessionId
protected Serializable getSessionId(SessionKey sessionKey)
-
retrieveSessionFromDataSource
protected Session retrieveSessionFromDataSource(Serializable sessionId) throws UnknownSessionException
- Throws:
UnknownSessionException
-
delete
protected void delete(Session session)
-
getActiveSessions
protected Collection<Session> getActiveSessions()
- Specified by:
getActiveSessions
in classAbstractValidatingSessionManager
-
-