Class AbstractNativeSessionManager

    • Constructor Detail

      • AbstractNativeSessionManager

        public AbstractNativeSessionManager()
    • Method Detail

      • setSessionListeners

        public void setSessionListeners​(<SessionListener> listeners)
      • getEventBus

        protected org.apache.shiro.event.EventBus getEventBus()
        Returns the EventBus used to publish SessionEvents.
        Returns:
        the EventBus used to publish SessionEvents.
        Since:
        1.3
      • setEventBus

        public void setEventBus​(org.apache.shiro.event.EventBus eventBus)
        Sets the EventBus to use to publish SessionEvents.
        Specified by:
        setEventBus in interface org.apache.shiro.event.EventBusAware
        Parameters:
        eventBus - the EventBus to use to publish SessionEvents.
        Since:
        1.3
      • publishEvent

        protected void publishEvent​( event)
        Publishes events on the event bus if the event bus is non-null, otherwise does nothing.
        Parameters:
        event - the event to publish on the event bus if the event bus exists.
        Since:
        1.3
      • start

        public Session start​(SessionContext context)
        Description copied from interface: SessionManager
        Starts a new session based on the specified contextual initialization data, which can be used by the underlying implementation to determine how exactly to create the internal Session instance.

        This method is mainly used in framework development, as the implementation will often relay the argument to an underlying SessionFactory which could use the context to construct the internal Session instance in a specific manner. This allows pluggable Session creation logic by simply injecting a SessionFactory into the SessionManager instance.

        Specified by:
        start in interface SessionManager
        Parameters:
        context - the contextual initialization data that can be used by the implementation or underlying SessionFactory when instantiating the internal Session instance.
        Returns:
        the newly created session.
        See Also:
        SessionFactory.createSession(SessionContext)
      • createSession

        protected abstract Session createSession​(SessionContext context)
                                          throws AuthorizationException
        Creates a new Session Session instance based on the specified (possibly null) initialization data. Implementing classes must manage the persistent state of the returned session such that it could later be acquired via the getSession(SessionKey) method.
        Parameters:
        context - the initialization data that can be used by the implementation or underlying SessionFactory when instantiating the internal Session instance.
        Returns:
        the new Session instance.
        Throws:
        HostUnauthorizedException - if the system access control policy restricts access based on client location/IP and the specified hostAddress hasn't been enabled.
        AuthorizationException - if the system access control policy does not allow the currently executing caller to start sessions.
      • applyGlobalSessionTimeout

        protected void applyGlobalSessionTimeout​(Session session)
      • onStart

        protected void onStart​(Session session,
                               SessionContext context)
        Template method that allows subclasses to react to a new session being created.

        This method is invoked before any session listeners are notified.

        Parameters:
        session - the session that was just created.
        context - the SessionContext that was used to start the session.
      • getSession

        public Session getSession​(SessionKey key)
                           throws SessionException
        Description copied from interface: SessionManager
        Retrieves the session corresponding to the specified contextual data (such as a session ID if applicable), or null if no Session could be found. If a session is found but invalid (stopped or expired), a SessionException will be thrown.
        Specified by:
        getSession in interface SessionManager
        Parameters:
        key - the Session key to use to look-up the Session
        Returns:
        the Session instance corresponding to the given lookup key or null if no session could be acquired.
        Throws:
        SessionException - if a session was found but it was invalid (stopped/expired).
      • beforeInvalidNotification

        protected Session beforeInvalidNotification​(Session session)
        Returns the session instance to use to pass to registered SessionListeners for notification that the session has been invalidated (stopped or expired).

        The default implementation returns an ImmutableProxiedSession instance to ensure that the specified session argument is not modified by any listeners.

        Parameters:
        session - the Session object being invalidated.
        Returns:
        the Session instance to use to pass to registered SessionListeners for notification.
      • notifyStop

        protected void notifyStop​(Session session)
      • notifyExpiration

        protected void notifyExpiration​(Session session)
      • getTimeout

        public long getTimeout​(SessionKey key)
                        throws InvalidSessionException
        Description copied from interface: NativeSessionManager
        Returns the time in milliseconds that the associated session may remain idle before expiring.
        • A negative return value means the session will never expire.
        • A non-negative return value (0 or greater) means the session expiration will occur if idle for that length of time.
        Specified by:
        getTimeout in interface NativeSessionManager
        Parameters:
        key - the session key to use to look up the target session.
        Returns:
        the time in milliseconds that the associated session may remain idle before expiring.
        Throws:
        InvalidSessionException - if the session has been stopped or expired prior to calling this method.
      • setTimeout

        public void setTimeout​(SessionKey key,
                               long maxIdleTimeInMillis)
                        throws InvalidSessionException
        Description copied from interface: NativeSessionManager
        Sets the time in milliseconds that the associated session may remain idle before expiring.
        • A negative return value means the session will never expire.
        • A non-negative return value (0 or greater) means the session expiration will occur if idle for that length of time.
        Specified by:
        setTimeout in interface NativeSessionManager
        Parameters:
        key - the session key to use to look up the target session.
        maxIdleTimeInMillis - the time in milliseconds that the associated session may remain idle before expiring.
        Throws:
        InvalidSessionException - if the session has been stopped or expired prior to calling this method.
      • getHost

        public  getHost​(SessionKey key)
        Description copied from interface: NativeSessionManager
        Returns the host name or IP string of the host where the session was started, if known. If no host name or IP was specified when starting the session, this method returns null
        Specified by:
        getHost in interface NativeSessionManager
        Parameters:
        key - the session key to use to look up the target session.
        Returns:
        the host name or ip address of the host where the session originated, if known. If unknown, this method returns null.
      • getAttributeKeys

        public <> getAttributeKeys​(SessionKey key)
        Description copied from interface: NativeSessionManager
        Returns all attribute keys maintained by the target session or an empty collection if there are no attributes.
        Specified by:
        getAttributeKeys in interface NativeSessionManager
        Parameters:
        key - the session key to use to look up the target session.
        Returns:
        all attribute keys maintained by the target session or an empty collection if there are no attributes.
        See Also:
        Session.getAttributeKeys()
      • getAttribute

        public  getAttribute​(SessionKey sessionKey,
                                    attributeKey)
                            throws InvalidSessionException
        Description copied from interface: NativeSessionManager
        Returns the object bound to the associated session identified by the specified attribute key. If there is no object bound under the attribute key for the given session, null is returned.
        Specified by:
        getAttribute in interface NativeSessionManager
        Parameters:
        sessionKey - session key to use to look up the target session.
        attributeKey - the unique name of the object bound to the associated session
        Returns:
        the object bound under the attributeKey or null if there is no object bound.
        Throws:
        InvalidSessionException - if the specified session has stopped or expired prior to calling this method.
        See Also:
        Session.getAttribute(Object key)
      • isValid

        public boolean isValid​(SessionKey key)
        Description copied from interface: NativeSessionManager
        Returns true if the associated session is valid (it exists and is not stopped nor expired), false otherwise.
        Specified by:
        isValid in interface NativeSessionManager
        Parameters:
        key - the session key to use to look up the target session.
        Returns:
        true if the session is valid (exists and is not stopped or expired), false otherwise.
      • onStop

        protected void onStop​(Session session)
      • afterStopped

        protected void afterStopped​(Session session)
      • onChange

        protected void onChange​(Session s)