Class StatelessSessionManager


  • public class StatelessSessionManager
    extends Object
    Responsible for creating StatelessSession and SessionInfo instances from JWT tokens. These operations are crucial for the Stateless Session implementation. Also provides logic methods to determine whether a SessionID/Token ID or HttpServletRequest contains a JWT token.
    Since:
    13.0.0
    • Constructor Detail

      • StatelessSessionManager

        @Inject
        public StatelessSessionManager​(StatelessJWTCache cache,
                                       SessionServerConfig sessionServerConfig,
                                       SessionServiceConfig sessionServiceConfig)
        Guice initialised constructor.
        Parameters:
        cache - Non null.
        sessionServerConfig - Non null.
        sessionServiceConfig - Non null.
    • Method Detail

      • containsJwt

        public boolean containsJwt​(jakarta.servlet.http.HttpServletRequest request)
                            throws SessionException
        Parameters:
        request - Non null.
        Returns:
        True if the HttpServletRequest contained the Jwt Token.
        Throws:
        SessionException - If there was any expected error.
      • containsJwt

        public boolean containsJwt​(String tokenId)
        Determines whether the given token id contains a client-side JWT.
        Parameters:
        tokenId - the token id to check.
        Returns:
        true if the token contains a client-side session JWT.
      • containsJwt

        public boolean containsJwt​(SessionID sid)
        Determines whether the given session id contains a client-side JWT.
        Parameters:
        sid - the session id to check.
        Returns:
        true if the session id contains a client-side session JWT.
      • generate

        public StatelessSession generate​(String tokenId)
                                  throws SessionException
        Generates a StatelessSession based on the String which is assumed to contain a Jwt token. This will be parsed and used to generate the StatelessSession. Side Effect: calls #getSessionInfo which may cache the JWT/SessionInfo.
        Parameters:
        tokenId - Non null TokenID to use for parsing.
        Returns:
        A non null StatelessSessionID.
        Throws:
        SessionException - if the stateless session cannot be generated
      • getSessionInfo

        public SessionInfo getSessionInfo​(SessionID sessionID)
                                   throws SessionException
        Will create the SessionInfo from the JWT contained within the SessionID. Side Effect: Will cache the generated JWT and SessionInfo combination.
        Parameters:
        sessionID - Maybe null SessionID.
        Returns:
        SessionInfo Non null SessionInfo which corresponds to the SessionID.
        Throws:
        SessionException - If there was any problem with getting the SessionInfo from the JWT within with SessionID
      • generate

        public StatelessSession generate​(SessionInfo info)
                                  throws SessionException
        Generates a StatelessSession by converting the SessionInfo into a JWT token which can then be used to build up the StatelessSession. Note: Will cache this generated JWT as a side effect.
        Parameters:
        info - The SessionInfo to generate the StatelessSession from. Non null.
        Returns:
        A non null StatelessSession.
        Throws:
        SessionException - If there was an unexpected error.
      • getJWTFromSessionID

        public static String getJWTFromSessionID​(SessionID sessionID,
                                                 boolean cleanupC66Encoding)
        Understands the detail around extracting the encoded JWT from the SessionID.
        Parameters:
        sessionID - Possibly null SessionID.
        cleanupC66Encoding - Whether to undo damage done to the JWT by c66 decoding if detected.
        Returns:
        Null if there was no JWT present, otherwise a valid JWT.