Interface Session

All Known Implementing Classes:
MapSession, ReactiveRedisIndexedSessionRepository.RedisSession

public interface Session
Provides a way to identify a user in an agnostic way. This allows the session to be used by an HttpSession, WebSocket Session, or even non web related sessions.
Since:
1.0
  • Method Details

    • getId

      String getId()
      Gets a unique string that identifies the Session.
      Returns:
      a unique string that identifies the Session
    • changeSessionId

      String changeSessionId()
      Changes the session id. After invoking the getId() will return a new identifier.
      Returns:
      the new session id which getId() will now return
    • getAttribute

      <T> T getAttribute(String attributeName)
      Gets the Object associated with the specified name or null if no Object is associated to that name.
      Type Parameters:
      T - the return type of the attribute
      Parameters:
      attributeName - the name of the attribute to get
      Returns:
      the Object associated with the specified name or null if no Object is associated to that name
    • getRequiredAttribute

      default <T> T getRequiredAttribute(String name)
      Return the session attribute value or if not present raise an IllegalArgumentException.
      Type Parameters:
      T - the attribute type
      Parameters:
      name - the attribute name
      Returns:
      the attribute value
    • getAttributeOrDefault

      default <T> T getAttributeOrDefault(String name, T defaultValue)
      Return the session attribute value, or a default, fallback value.
      Type Parameters:
      T - the attribute type
      Parameters:
      name - the attribute name
      defaultValue - a default value to return instead
      Returns:
      the attribute value
    • getAttributeNames

      Set<String> getAttributeNames()
      Gets the attribute names that have a value associated with it. Each value can be passed into getAttribute(String) to obtain the attribute value.
      Returns:
      the attribute names that have a value associated with it.
      See Also:
    • setAttribute

      void setAttribute(String attributeName, Object attributeValue)
      Sets the attribute value for the provided attribute name. If the attributeValue is null, it has the same result as removing the attribute with removeAttribute(String) .
      Parameters:
      attributeName - the attribute name to set
      attributeValue - the value of the attribute to set. If null, the attribute will be removed.
    • removeAttribute

      void removeAttribute(String attributeName)
      Removes the attribute with the provided attribute name.
      Parameters:
      attributeName - the name of the attribute to remove
    • getCreationTime

      Instant getCreationTime()
      Gets the time when this session was created.
      Returns:
      the time when this session was created.
    • setLastAccessedTime

      void setLastAccessedTime(Instant lastAccessedTime)
      Sets the last accessed time.
      Parameters:
      lastAccessedTime - the last accessed time
    • getLastAccessedTime

      Instant getLastAccessedTime()
      Gets the last time this Session was accessed.
      Returns:
      the last time the client sent a request associated with the session
    • setMaxInactiveInterval

      void setMaxInactiveInterval(Duration interval)
      Sets the maximum inactive interval between requests before this session will be invalidated. A negative time indicates that the session will never timeout.
      Parameters:
      interval - the amount of time that the Session should be kept alive between client requests.
    • getMaxInactiveInterval

      Duration getMaxInactiveInterval()
      Gets the maximum inactive interval between requests before this session will be invalidated. A negative time indicates that the session will never timeout.
      Returns:
      the maximum inactive interval between requests before this session will be invalidated. A negative time indicates that the session will never timeout.
    • isExpired

      boolean isExpired()
      Returns true if the session is expired.
      Returns:
      true if the session is expired, else false.