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 SessionDAOsessionDAO-
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 voidafterExpired(Session session)protected voidafterStopped(Session session)protected voidcreate(Session session)Persists the given session instance to an underlying EIS (Enterprise Information System).protected voiddelete(Session session)protected SessiondoCreateSession(SessionContext context)protected Collection<Session>getActiveSessions()SessionDAOgetSessionDAO()SessionFactorygetSessionFactory()Returns theSessionFactoryused to generate newSessioninstances.protected SerializablegetSessionId(SessionKey sessionKey)booleanisDeleteInvalidSessions()Returnstrueif sessions should be automatically deleted after they are discovered to be invalid,falseif invalid sessions will be manually deleted by some process external to Shiro's control.protected SessionnewSessionInstance(SessionContext context)protected voidonChange(Session session)protected voidonExpiration(Session session)protected voidonStop(Session session)protected SessionretrieveSession(SessionKey sessionKey)Looks up a session from the underlying data store based on the specified session key.protected SessionretrieveSessionFromDataSource(Serializable sessionId)voidsetCacheManager(org.apache.shiro.cache.CacheManager cacheManager)voidsetDeleteInvalidSessions(boolean deleteInvalidSessions)Sets whether or not sessions should be automatically deleted after they are discovered to be invalid.voidsetSessionDAO(SessionDAO sessionDAO)voidsetSessionFactory(SessionFactory sessionFactory)Sets theSessionFactoryused to generate newSessioninstances.-
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 theSessionFactoryused to generate newSessioninstances. The default instance is aSimpleSessionFactory.- Returns:
- the
SessionFactoryused to generate newSessioninstances. - Since:
- 1.0
-
setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)
Sets theSessionFactoryused to generate newSessioninstances. The default instance is aSimpleSessionFactory.- Parameters:
sessionFactory- theSessionFactoryused to generate newSessioninstances.- Since:
- 1.0
-
isDeleteInvalidSessions
public boolean isDeleteInvalidSessions()
Returnstrueif sessions should be automatically deleted after they are discovered to be invalid,falseif invalid sessions will be manually deleted by some process external to Shiro's control. The default istrueto ensure no orphans exist in the underlying data store.Usage
It is ok to set this tofalseONLY 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 tofalsewill allow such querying, but with the caveat that the application developer/configurer deletes the sessions themselves by some other means (cron, quartz, etc).- Returns:
trueif sessions should be automatically deleted after they are discovered to be invalid,falseif 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 istrueto ensure no orphans will exist in the underlying data store.WARNING
Only set this value tofalseif 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:
setCacheManagerin interfaceorg.apache.shiro.cache.CacheManagerAware
-
doCreateSession
protected Session doCreateSession(SessionContext context)
- Specified by:
doCreateSessionin 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:
onStopin classAbstractNativeSessionManager
-
afterStopped
protected void afterStopped(Session session)
- Overrides:
afterStoppedin classAbstractNativeSessionManager
-
onExpiration
protected void onExpiration(Session session)
- Overrides:
onExpirationin classAbstractValidatingSessionManager
-
afterExpired
protected void afterExpired(Session session)
- Overrides:
afterExpiredin classAbstractValidatingSessionManager
-
onChange
protected void onChange(Session session)
- Overrides:
onChangein classAbstractNativeSessionManager
-
retrieveSession
protected Session retrieveSession(SessionKey sessionKey) throws UnknownSessionException
Description copied from class:AbstractValidatingSessionManagerLooks up a session from the underlying data store based on the specified session key.- Specified by:
retrieveSessionin 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:
getActiveSessionsin classAbstractValidatingSessionManager
-
-