Class SessionManagerImpl

java.lang.Object
ch.tocco.nice2.userbase.impl.SessionManagerImpl
All Implemented Interfaces:
SessionManager

@Component public class SessionManagerImpl extends Object implements SessionManager
  • Constructor Details

  • Method Details

    • deleteExpiredSessions

      public void deleteExpiredSessions(long timeoutMillis) throws SessionDataException
      Description copied from interface: SessionManager
      Removes at most amount sessions that are older than the specified time out.
      Specified by:
      deleteExpiredSessions in interface SessionManager
      Parameters:
      timeoutMillis - timeout to find sessions older than this
      Throws:
      SessionDataException
    • getSession

      public Optional<Session> getSession(UUID uuid, long timeoutMillis, @Nullable String userAgent, @Nullable ApiKey apiKey) throws SessionDataException
      Description copied from interface: SessionManager
      Finds the session with the specified uuid, which is not older than the specified timeout (= session.time >= (now-timeout)) and has the same user agent. Session time is updated automatically.
      Specified by:
      getSession in interface SessionManager
      Parameters:
      uuid - the id of the session.
      timeoutMillis - the timeout interval in milliseconds. Session is only returned if it is not older than the current time minus this timeout.
      userAgent - the user agent whuch must match.
      Returns:
      the session or Optional.empty().
      Throws:
      SessionDataException
    • isSessionActive

      public boolean isSessionActive(UUID uuid, long timeoutMillis)
      Specified by:
      isSessionActive in interface SessionManager
      Returns:
      true if there is an active session with the given uuid
    • getSessionTimeOut

      public org.joda.time.Duration getSessionTimeOut()
      Specified by:
      getSessionTimeOut in interface SessionManager
    • createSession

      public Session createSession(String username, String ipAddress, @Nullable String userAgent) throws SessionDataException
      Description copied from interface: SessionManager
      Creates a new session for the existing principal.
      Specified by:
      createSession in interface SessionManager
      Parameters:
      username - the current user's username
      ipAddress - the ip address of the client
      userAgent - the user agent of the client
      Returns:
      the created session
      Throws:
      SessionDataException
    • createSession

      public Session createSession(String username, ApiKey apiKey, String ipAddress, @Nullable String userAgent) throws SessionDataException
      Description copied from interface: SessionManager
      Create a new Session for a given ApiKey.
      Specified by:
      createSession in interface SessionManager
      Throws:
      SessionDataException
    • deleteSession

      public void deleteSession(UUID uuid)
      Description copied from interface: SessionManager
      Deletes the session with the specified uuid.
      Specified by:
      deleteSession in interface SessionManager
      Parameters:
      uuid - the id of the session.
    • deleteAllSessions

      public void deleteAllSessions(String username, boolean includingCurrent)
      Description copied from interface: SessionManager
      Deletes all available sessions of specified principal.
      Specified by:
      deleteAllSessions in interface SessionManager
      Parameters:
      username - of principal
      includingCurrent - when set to true, also set currently used session which will lead to an invalid current session.
    • setSessionTimeoutInMinutes

      @Value("${nice2.userbase.sessionTimeoutInMinutes}") public void setSessionTimeoutInMinutes(int sessionTimeoutInMinutes)