Class MemorySessions

java.lang.Object
rife.authentication.sessionmanagers.MemorySessions
All Implemented Interfaces:
SessionManager

public class MemorySessions extends Object implements SessionManager
  • Constructor Details

    • MemorySessions

      public MemorySessions()
  • Method Details

    • getSessionDuration

      public long getSessionDuration()
      Description copied from interface: SessionManager
      Obtains the maximum time that a user can stay inactive before an active session becomes invalid.
      Specified by:
      getSessionDuration in interface SessionManager
      Returns:
      The maximum time of inactivity in milliseconds.
    • setSessionDuration

      public void setSessionDuration(long milliseconds)
      Description copied from interface: SessionManager
      Sets the maximum time that a user can stay inactive before an active session becomes invalid.
      Specified by:
      setSessionDuration in interface SessionManager
      Parameters:
      milliseconds - The maximum time of inactivity in milliseconds.
    • getRestrictAuthData

      public boolean getRestrictAuthData()
      Description copied from interface: SessionManager
      Obtains the restriction policy of the authentication ID in regard to the user's auth data.

      The default is false, or no restriction.

      Specified by:
      getRestrictAuthData in interface SessionManager
      Returns:
      true if the authentication is restricted to one auth data; or

      false if the authentication ID can be used with any auth data

    • setRestrictAuthData

      public void setRestrictAuthData(boolean flags)
      Description copied from interface: SessionManager
      Sets the restriction policy of the authentication ID in regard to the user's auth data.

      The default is false, or no restriction.

      Specified by:
      setRestrictAuthData in interface SessionManager
      Parameters:
      flags - true to activate the auth data restriction; or

      false otherwise

    • getSessionPurgeFrequency

      public int getSessionPurgeFrequency()
      Description copied from interface: SessionManager
      Obtains the frequency at which the purging will happen in relationship to the scale.

      This defaults to RifeConfig.AuthenticationConfig.getSessionPurgeFrequency().

      Specified by:
      getSessionPurgeFrequency in interface SessionManager
      Returns:
      the purge frequency
      See Also:
    • setSessionPurgeFrequency

      public void setSessionPurgeFrequency(int frequency)
      Description copied from interface: SessionManager
      Set the frequency at which the purging will happen in relationship to the scale.

      By default, the frequency and scale respectively are 20 and 1000, which means that the purging will have once every fifty times the authentication sessions are accessed.

      Specified by:
      setSessionPurgeFrequency in interface SessionManager
      Parameters:
      frequency - the purge frequency
      See Also:
    • getSessionPurgeScale

      public int getSessionPurgeScale()
      Description copied from interface: SessionManager
      Obtains the scale at which the purging will happen in relationship to the frequency.

      This defaults to RifeConfig.AuthenticationConfig.getSessionPurgeScale().

      Specified by:
      getSessionPurgeScale in interface SessionManager
      Returns:
      the purge scale
      See Also:
    • setSessionPurgeScale

      public void setSessionPurgeScale(int scale)
      Description copied from interface: SessionManager
      Set the scale at which the purging will happen in relationship to the frequency.

      By default, the frequency and scale respectively are 20 and 1000, which means that the purging will have once every fifty times the authentication sessions are accessed.

      Specified by:
      setSessionPurgeScale in interface SessionManager
      Parameters:
      scale - the purge scale
      See Also:
    • purgeSessions

      public void purgeSessions()
      Description copied from interface: SessionManager
      Removes all sessions that are inactive. This means that all sessions where the inactivity time has been exceeded, will be removed.
      Specified by:
      purgeSessions in interface SessionManager
    • startSession

      public String startSession(long userId, String authData, boolean remembered) throws SessionManagerException
      Description copied from interface: SessionManager
      Starts a new session.
      Specified by:
      startSession in interface SessionManager
      Parameters:
      userId - The id that uniquely identifies the user that is allowed to use this session.
      authData - The authentication data that is associated with the session.
      remembered - Indicates whether the session is started through remember me or from scratch.
      Returns:
      A String that uniquely identifies the authentication session that was just started.
      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when a session is started. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • isSessionValid

      public boolean isSessionValid(String authId, String authData) throws SessionManagerException
      Description copied from interface: SessionManager
      Verifies if a session is valid and still active.
      Specified by:
      isSessionValid in interface SessionManager
      Parameters:
      authId - The unique id of the authentication session that needs to be verified.
      authData - The authentication data that is associated with the session.
      Returns:
      true if a valid active session was found; or

      false if this was not possible.

      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when a session is verified. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • getSessionUserId

      public long getSessionUserId(String authId) throws SessionManagerException
      Description copied from interface: SessionManager
      Retrieves the id of a user that has access to a particular session.
      Specified by:
      getSessionUserId in interface SessionManager
      Parameters:
      authId - The unique id of the authentication session for which the user needs to be looked up.
      Returns:
      A long >= 0 that corresponds to the user id that has access to the session; or

      -1 if the session couldn't be found.

      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when user id of a session is retrieved. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • continueSession

      public boolean continueSession(String authId) throws SessionManagerException
      Description copied from interface: SessionManager
      Continues an already active session. This means that the inactivity time-out is reset to the maximal value. This is typically called each time a user accesses an application.
      Specified by:
      continueSession in interface SessionManager
      Parameters:
      authId - The unique id of the authentication session that needs to be continued.
      Returns:
      true if the session was successfully continued; or

      false if this was not possible (i.e. the session couldn't be found).

      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when a session is continued. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • eraseSession

      public boolean eraseSession(String authId) throws SessionManagerException
      Description copied from interface: SessionManager
      Removes all traces of an authentication session. This makes the session instantly inactive and invalid.
      Specified by:
      eraseSession in interface SessionManager
      Parameters:
      authId - The unique id of the authentication session that needs to be erased.
      Returns:
      true if the session was successfully erased; or

      false if this was not possible (i.e. the session couldn't be found).

      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when a session is erased. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • wasRemembered

      public boolean wasRemembered(String authId) throws SessionManagerException
      Description copied from interface: SessionManager
      Checks if a session was previously automatically created from remembered data.
      Specified by:
      wasRemembered in interface SessionManager
      Parameters:
      authId - The unique id of the authentication session that needs to be erased.
      Returns:
      true if the session was created automatically from remembered data; or

      false if it was created from full credentials or if the session couldn't be found.

      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when a session is erased. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • eraseUserSessions

      public boolean eraseUserSessions(long userId) throws SessionManagerException
      Description copied from interface: SessionManager
      Removes all traces of all authentication sessions for a particular user. This makes all sessions of this user instantly inactive and invalid.
      Specified by:
      eraseUserSessions in interface SessionManager
      Parameters:
      userId - The id that uniquely identifies the user whose sessions are to be erased.
      Returns:
      true if the sessions were successfully erased; or

      false if this was not possible (i.e. no sessions couldn't be found).

      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when a session is erased. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • eraseAllSessions

      public void eraseAllSessions() throws SessionManagerException
      Description copied from interface: SessionManager
      Removes all available sessions. This makes all sessions instantly invalid and inactive for all users.
      Specified by:
      eraseAllSessions in interface SessionManager
      Throws:
      SessionManagerException - An undefined number of exceptional cases or error situations can occur when a session is erased. They are all indicated by throwing an instance of SessionManagerException. It's up to the implementations of this interface to give more specific meanings to these exceptions.
    • getSession

      public MemorySession getSession(String authId)
    • countSessions

      public long countSessions()
      Description copied from interface: SessionManager
      Counts the number of active sessions.
      Specified by:
      countSessions in interface SessionManager
      Returns:
      The number of active sessions.
    • listSessions

      public boolean listSessions(ListSessions processor)
      Description copied from interface: SessionManager
      Lists the active sessions.
      Specified by:
      listSessions in interface SessionManager
      Parameters:
      processor - The row processor that will be used to list the active sessions.
      Returns:
      true if active sessions were found; or

      false if no session was active.