Class AbstractJWTSession<A,B>

java.lang.Object
io.inverno.mod.session.AbstractSession<A,JWTSession<A,B>>
io.inverno.mod.session.jwt.AbstractJWTSession<A,B>
Type Parameters:
A - the session data type
B - the stateless session data type
All Implemented Interfaces:
JWTSession<A,B>, Session<A>

public abstract class AbstractJWTSession<A,B> extends AbstractSession<A,JWTSession<A,B>> implements JWTSession<A,B>

Base JWTSession implementation class.

Since:
1.13
Author:
Jeremy Kuhn
  • Field Details

    • tokenId

      protected String tokenId
      The JWT session token id (i.e. JTI)
    • statelessSessionData

      protected B statelessSessionData
      The stateless session data stored in the JWT session id.
    • statelessDataSet

      protected boolean statelessDataSet
      Flag indicating whether stateless data were set.
    • statelessDataGet

      protected boolean statelessDataGet
      Flag indicating whether stateless data were get.
    • statelessSessionDataSaveStrategy

      protected SessionDataSaveStrategy<B> statelessSessionDataSaveStrategy
      Stateless session data save strategy.
    • expirationSet

      protected boolean expirationSet
      Flag indicating whether expiration settings were changed.
  • Constructor Details

    • AbstractJWTSession

      protected AbstractJWTSession(JWTSessionIdGenerator<A,B> sessionIdGenerator, JWTSessionStore<A,B> sessionStore, Long maxInactiveInterval, Long expirationTime, SessionDataSaveStrategy<B> statelessSessionDataSaveStrategy) throws IllegalArgumentException

      Creates a new JWT session.

      Parameters:
      sessionIdGenerator - a JWT session id generator
      sessionStore - a JWT session store
      maxInactiveInterval - the maximum inactive interval in milliseconds
      expirationTime - the expiration time in milliseconds
      statelessSessionDataSaveStrategy - the stateless session data save strategy
      Throws:
      IllegalArgumentException - if both maximum inactive interval and expiration time are null
    • AbstractJWTSession

      protected AbstractJWTSession(JWTSessionIdGenerator<A,B> sessionIdGenerator, JWTSessionStore<A,B> sessionStore, String id, JWTClaimsSet claimsSet, B statelessSessionData, SessionDataSaveStrategy<B> statelessSessionDataSaveStrategy, long lastAccessedTime, boolean isNew) throws IllegalArgumentException

      Creates an existing JWT session.

      Parameters:
      sessionIdGenerator - a JWT session id generator
      sessionStore - a JWT session store
      id - the JWT session id
      claimsSet - the JWT session claims set
      statelessSessionData - the stateless session data
      statelessSessionDataSaveStrategy - the stateless session data save strategy
      lastAccessedTime - the last accessed time in milliseconds
      isNew - true to set the original id to null, false otherwise
      Throws:
      IllegalArgumentException - if both maximum inactive interval and expiration time are null
    • AbstractJWTSession

      protected AbstractJWTSession(JWTSessionIdGenerator<A,B> sessionIdGenerator, JWTSessionStore<A,B> sessionStore, String id, String tokenId, long creationTime, long lastAccessedTime, Long maxInactiveInterval, Long expirationTime, B statelessSessionData, SessionDataSaveStrategy<B> statelessSessionDataSaveStrategy, boolean isNew) throws IllegalArgumentException

      Creates an existing JWT session.

      Parameters:
      sessionIdGenerator - a JWT session id generator
      sessionStore - a JWT session store
      id - the JWT session id
      tokenId - tje JWT token id (i.e. JTI)
      creationTime - the creation time in milliseconds
      lastAccessedTime - the last accessed time in milliseconds
      maxInactiveInterval - the maximum inactive interval in milliseconds
      expirationTime - the expiration time in milliseconds
      statelessSessionData - the stateless session data save strategy
      statelessSessionDataSaveStrategy - the stateless session data save strategy
      isNew - true to set the original id to null, false otherwise
      Throws:
      IllegalArgumentException - if both maximum inactive interval and expiration time are null
  • Method Details

    • getTokenId

      public String getTokenId()

      Returns the JWT token id (i.e. JTI)

      Returns:
      the JWT token id
    • setLastAccessedTime

      protected void setLastAccessedTime(long lastAccessedTime)
      Description copied from class: AbstractSession

      Sets the last accessed time.

      Overrides:
      setLastAccessedTime in class AbstractSession<A,JWTSession<A,B>>
      Parameters:
      lastAccessedTime - the last accessed time
    • setStatelessData

      public void setStatelessData(B statelessSessionData)
      Description copied from interface: JWTSession

      Sets the stateless session data.

      Specified by:
      setStatelessData in interface JWTSession<A,B>
      Parameters:
      statelessSessionData - the stateless session data
    • getStatelessData

      public B getStatelessData()
      Description copied from interface: JWTSession

      Returns the stateless session data.

      Specified by:
      getStatelessData in interface JWTSession<A,B>
      Returns:
      the stateless session data or null if exist in the session
    • setMaxInactiveInterval

      public void setMaxInactiveInterval(long maxInactiveInterval)
      Description copied from interface: Session

      Sets the maximum inactive interval in milliseconds.

      The maximum inactive interval replaces the expiration time if any was set.

      Specified by:
      setMaxInactiveInterval in interface Session<A>
      Overrides:
      setMaxInactiveInterval in class AbstractSession<A,JWTSession<A,B>>
      Parameters:
      maxInactiveInterval - a maximum inactive interval in milliseconds
    • setExpirationTime

      public void setExpirationTime(long expirationTime)
      Description copied from interface: Session

      Sets the session expiration time in milliseconds.

      The expiration time replaces the maximum inactive interval if any was set.

      Specified by:
      setExpirationTime in interface Session<A>
      Overrides:
      setExpirationTime in class AbstractSession<A,JWTSession<A,B>>
      Parameters:
      expirationTime - an expiration time in milliseconds
    • isExpired

      public boolean isExpired()
      Description copied from interface: Session

      Determines whether the session has expired.

      Specified by:
      isExpired in interface Session<A>
      Overrides:
      isExpired in class AbstractSession<A,JWTSession<A,B>>
      Returns:
      true if the session has expired, false otherwise
    • refreshId

      public Mono<String> refreshId(boolean force)
      Description copied from interface: Session

      Refreshes the session id.

      Specified by:
      refreshId in interface Session<A>
      Overrides:
      refreshId in class AbstractSession<A,JWTSession<A,B>>
      Parameters:
      force - true to force refresh, false to only refresh the id if it is stale
      Returns:
      a mono that emits the new session identifier or an empty mono if the identifier did not need to be refreshed
    • invalidate

      public Mono<Void> invalidate()
      Description copied from interface: Session

      Invalidates the session.

      Specified by:
      invalidate in interface Session<A>
      Overrides:
      invalidate in class AbstractSession<A,JWTSession<A,B>>
      Returns:
      a mono which completes when the session is invalidated