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,org.apache.shiro.lang.util.Destroyable,NativeSessionManager,SessionManager,ValidatingSessionManager
public class DefaultSessionManager
extends AbstractValidatingSessionManager
implements org.apache.shiro.cache.CacheManagerAware
Default business-tier implementation of a
ValidatingSessionManager. All session CRUD operations are
delegated to an internal SessionDAO.- Since:
- 0.1
-
Field Summary
FieldsFields inherited from class org.apache.shiro.session.mgt.AbstractValidatingSessionManager
DEFAULT_SESSION_VALIDATION_INTERVAL, sessionValidationInterval, sessionValidationScheduler, sessionValidationSchedulerEnabledFields 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterExpired(Session session) protected voidafterStopped(Session session) protected voidPersists the given session instance to an underlying EIS (Enterprise Information System).protected voidprotected SessiondoCreateSession(SessionContext context) protected Collection<Session> Returns theSessionFactoryused to generate newSessioninstances.protected SerializablegetSessionId(SessionKey sessionKey) booleanReturnstrueif 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 voidprotected voidonExpiration(Session session) protected voidprotected 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, validateSessionsMethods 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, touchMethods inherited from class org.apache.shiro.session.mgt.AbstractSessionManager
getGlobalSessionTimeout, setGlobalSessionTimeoutMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.shiro.session.mgt.SessionManager
getSession, start
-
Field Details
-
sessionDAO
-
-
Constructor Details
-
DefaultSessionManager
public DefaultSessionManager()
-
-
Method Details
-
setSessionDAO
-
getSessionDAO
-
getSessionFactory
Returns theSessionFactoryused to generate newSessioninstances. The default instance is aSimpleSessionFactory.- Returns:
- the
SessionFactoryused to generate newSessioninstances. - Since:
- 1.0
-
setSessionFactory
Sets theSessionFactoryused to generate newSessioninstances. The default instance is aSimpleSessionFactory.- Parameters:
sessionFactory- theSessionFactoryused to generate newSessioninstances.- Since:
- 1.0
-
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
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
- Specified by:
setCacheManagerin interfaceorg.apache.shiro.cache.CacheManagerAware
-
doCreateSession
- Specified by:
doCreateSessionin classAbstractValidatingSessionManager
-
newSessionInstance
-
create
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
- Overrides:
onStopin classAbstractNativeSessionManager
-
afterStopped
- Overrides:
afterStoppedin classAbstractNativeSessionManager
-
onExpiration
- Overrides:
onExpirationin classAbstractValidatingSessionManager
-
afterExpired
- Overrides:
afterExpiredin classAbstractValidatingSessionManager
-
onChange
- Overrides:
onChangein classAbstractNativeSessionManager
-
retrieveSession
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
-
retrieveSessionFromDataSource
protected Session retrieveSessionFromDataSource(Serializable sessionId) throws UnknownSessionException - Throws:
UnknownSessionException
-
delete
-
getActiveSessions
- Specified by:
getActiveSessionsin classAbstractValidatingSessionManager
-