Class EnterpriseCacheSessionDAO

  • All Implemented Interfaces:
    org.apache.shiro.cache.CacheManagerAware, SessionDAO

    public class EnterpriseCacheSessionDAO
    extends CachingSessionDAO
    SessionDAO implementation that relies on an enterprise caching product as the EIS system of record for all sessions. It is expected that an injected Cache or CacheManager is backed by an enterprise caching product that can support all application sessions and/or provide disk paging for resilient data storage.

    Production Note

    This implementation defaults to using an in-memory map-based CacheManager, which is great for testing but will typically not scale for production environments and could easily cause OutOfMemoryExceptions. Just don't forget to configure* an instance of this class with a production-grade CacheManager that can handle disk paging for large numbers of sessions and you'll be fine.

    *If you configure Shiro's SecurityManager instance with such a CacheManager, it will be automatically applied to an instance of this class and you won't need to explicitly set it in configuration.

    Implementation Details

    This implementation relies heavily on the parent class's transparent caching behavior for all storage operations with the enterprise caching product. Because the parent class uses a Cache or CacheManager to perform caching, and the cache is considered the system of record, nothing further needs to be done for the doReadSession(java.io.Serializable), doUpdate(org.apache.shiro.session.Session) and doDelete(org.apache.shiro.session.Session) method implementations. This class implements those methods as required by the parent class, but they essentially do nothing.
    Since:
    1.0
    • Constructor Detail

      • EnterpriseCacheSessionDAO

        public EnterpriseCacheSessionDAO()
    • Method Detail

      • doCreate

        protected  doCreate​(Session session)
        Description copied from class: AbstractSessionDAO
        Subclass hook to actually persist the given Session instance to the underlying EIS.
        Specified by:
        doCreate in class AbstractSessionDAO
        Parameters:
        session - the Session instance to persist to the EIS.
        Returns:
        the id of the session created in the EIS (i.e. this is almost always a primary key and should be the value returned from Session.getId().
      • doReadSession

        protected  sessionId)
        Description copied from class: AbstractSessionDAO
        Subclass implementation hook that retrieves the Session object from the underlying EIS or null if a session with that ID could not be found.
        Specified by:
        doReadSession in class AbstractSessionDAO
        Parameters:
        sessionId - the id of the Session to retrieve.
        Returns:
        the Session in the EIS identified by sessionId or null if a session with that ID could not be found.
      • doUpdate

        protected void doUpdate​(Session session)
        Description copied from class: CachingSessionDAO
        Subclass implementation hook to actually persist the Session's state to the underlying EIS.
        Specified by:
        doUpdate in class CachingSessionDAO
        Parameters:
        session - the session object whose state will be propagated to the EIS.
      • doDelete

        protected void doDelete​(Session session)
        Description copied from class: CachingSessionDAO
        Subclass implementation hook to permanently delete the given Session from the underlying EIS.
        Specified by:
        doDelete in class CachingSessionDAO
        Parameters:
        session - the session instance to permanently delete from the EIS.