Interface SessionService

  • All Superinterfaces:
    java.lang.AutoCloseable

    public interface SessionService
    extends java.lang.AutoCloseable
    Generates, caches, stores, give access and removes sessions
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close()
      Закрывает различные ресурсы
      SessionIdentity createSession​(java.lang.Object sessionData)
      Creates new session in storage with specified sessionData
      <T> T getSessionData​(java.lang.String sessionId)
      Gives session data by session id
      java.util.Optional<java.lang.String> getToken​(java.lang.String sessionId)
      Loads token for specified session
      void idle()
      This method must be called every 5 seconds to do pending operations
      void removeOldSessions​(int hoursOld)
      Removes all sessions with age is too big.
      void removeSession​(java.lang.String sessionId)
      Removes session from cache and from storage
      boolean verifyId​(java.lang.String sessionId)
      Verifies session id salt.
      boolean verifyToken​(java.lang.String sessionId, java.lang.String token)
      Verify token: loads token from storage ot cache and check its identity
    • Method Detail

      • createSession

        SessionIdentity createSession​(java.lang.Object sessionData)
        Creates new session in storage with specified sessionData
        Parameters:
        sessionData - additional session data to store in session (it can contain userId, role or else)
        Returns:
        session identity witch contains session id and token. Session id contains salt that nobody cannot create it
      • getSessionData

        <T> T getSessionData​(java.lang.String sessionId)
        Gives session data by session id
        Parameters:
        sessionId - session id
        Returns:
        session data or null if session with specified id is absent
      • verifyId

        boolean verifyId​(java.lang.String sessionId)
        Verifies session id salt. Very quick operation
        Parameters:
        sessionId - session id
        Returns:
        verification result: true - session id salt is good, false - otherwise
      • verifyToken

        boolean verifyToken​(java.lang.String sessionId,
                            java.lang.String token)
        Verify token: loads token from storage ot cache and check its identity
        Parameters:
        sessionId - session id
        token - verifying token
        Returns:
        verification result: true - tokens are same to each other, false - tokens are not same
      • getToken

        java.util.Optional<java.lang.String> getToken​(java.lang.String sessionId)
        Loads token for specified session
        Parameters:
        sessionId - specified session id
        Returns:
        token
      • removeSession

        void removeSession​(java.lang.String sessionId)
        Removes session from cache and from storage
        Parameters:
        sessionId - removing session id
      • removeOldSessions

        void removeOldSessions​(int hoursOld)
        Removes all sessions with age is too big.
        Parameters:
        hoursOld - number of hours of age to delete sessions
      • idle

        void idle()
        This method must be called every 5 seconds to do pending operations
      • close

        void close()
        Закрывает различные ресурсы
        Specified by:
        close in interface java.lang.AutoCloseable