Class SessionInfo

  • All Implemented Interfaces:
    SilverpeasUserSession
    Direct Known Subclasses:
    HTTPSessionInfo, OneShotSessionInfo

    public abstract class SessionInfo
    extends Object
    implements SilverpeasUserSession
    Default implementation of a user session in Silverpeas. It gathers information about an opened session of a user. It is an abstract class providing a default implementation of a user session in Silverpeas for whatever technical session in use. It is the responsibility of the concrete class extending the SessionInfo abstract class to define on which technical session the user sessions in Silverpeas have to be built.
    • Field Detail

      • NoneSession

        public static final SessionInfo NoneSession
        A non defined session. To use instead of null or to represent a session info not bound to any user session.
    • Constructor Detail

      • SessionInfo

        protected SessionInfo​(String sessionId,
                              User user)
        Constructs a new instance about a given opened user session.
        Parameters:
        sessionId - the identifier of the opened session.
        user - the user for which a session was opened.
    • Method Detail

      • getIPAddress

        public String getIPAddress()
        Gets the IP address of the remote client that opened the session.
        Returns:
        the client remote IP address.
      • setIPAddress

        public void setIPAddress​(String ip)
        Sets the IP address of the remote client that requests a session opening with Silverpeas.
        Parameters:
        ip - the IP address of the remote client.
      • getLastAccessTimestamp

        public long getLastAccessTimestamp()
        Gets the timestamp of the last access by the client behind this session.
        Returns:
        timestamp of the last access.
      • getOpeningTimestamp

        public long getOpeningTimestamp()
        Gets the timestamp at which the session with Silverpeas was opened.
        Returns:
        the session opening timestamp.
      • getLastIdleDuration

        public long getLastIdleDuration()
        Gets the last duration of its idle time. A one-shot session cannot be in idle state. Invoking this method on such a session will throw an IllegalStateException exception.
        Returns:
        the session alive timestamp.
      • setAsIdle

        public void setAsIdle()
        Sets this session as currently idle. A one-shot session cannot be in idle state. Invoking this method on such a session will throw an IllegalStateException exception.
      • setAsOneShot

        public void setAsOneShot()
        Sets this session as a one-shot one. A one-shot session cannot become a long-living session after.
      • getSessionId

        public String getSessionId()
        Gets the unique identifier of the session.
        Returns:
        the session identifier.
      • getUserDetail

        public User getUserDetail()
        Gets the profile of the user that opened the session.
        Returns:
        a UserDetail instance with the profile information on the user.
      • updateLastAccess

        public void updateLastAccess()
        Updates the last access timestamp. A one-shot session cannot used in several user calls. Invoking this method on such a session will throw an IllegalStateException exception.
      • setAttribute

        public <T> void setAttribute​(String name,
                                     T value)
        Sets an attribute named by the specified name with the specified value. If no attribute exists with the specified name, then it is added to the session.
        Specified by:
        setAttribute in interface SilverpeasUserSession
        Type Parameters:
        T - the type of the attribute value.
        Parameters:
        name - the name of the attribute to set.
        value - the value of the attribute to set.
      • getAttribute

        public <T> T getAttribute​(String name)
        Gets the value of the attribute named by the specified name.
        Specified by:
        getAttribute in interface SilverpeasUserSession
        Type Parameters:
        T - the type of the attribute value.
        Parameters:
        name - the name of the attribute to get.
        Returns:
        the value of the attribute or null if no such attribute exists.
      • unsetAttribute

        public void unsetAttribute​(String name)
        Unsets the specified attribute. The consequence of an unset is the attribute is then removed from the session.
        Specified by:
        unsetAttribute in interface SilverpeasUserSession
        Parameters:
        name - the name of the attribute to unset.
      • onClosed

        public void onClosed()
        Frees the allocated resources used in the session management and carried by this session information. This method must be called at session closing by the session management system.
      • isDefined

        public boolean isDefined()
        Is this session defined? A session is defined if it's a session opened to a user in Silverpeas.
        Specified by:
        isDefined in interface SilverpeasUserSession
        Returns:
        true if this session is defined, false otherwise.
      • isAnonymous

        public boolean isAnonymous()
        Is this session an anonymous one? A session is anonymous when no users are explicitly authenticated and then identified and the users uses Silverpeas under the cover of a transparent anonymous user account.
        Specified by:
        isAnonymous in interface SilverpeasUserSession
        Returns:
        true if this session is a defined anonymous one, false otherwise.
      • isOneShot

        public boolean isOneShot()
        Is this session a one-shot one? A one-shot session is a short time living session that doesn't live over the scope of a functional call (id est over the scope of an HTTP request).
        Specified by:
        isOneShot in interface SilverpeasUserSession
        Returns:
        true if this session is a one-shot one, false otherwise.
      • getCache

        public org.silverpeas.kernel.cache.model.SimpleCache getCache()
        Provides a cache associated to the current session.
        Returns:
        the user session cache.