Record Class SessionState

java.lang.Object
java.lang.Record
com.jsgalactic.axiom.security.SessionState
Record Components:
identity - the signed-in identity, empty for an anonymous session
attributes - application data as text; an unmodifiable copy
createdAt - when the session was created; the absolute timeout counts from here
lastAccessedAt - when the session was last used; the idle timeout counts from here

public record SessionState(Optional<SecurityIdentity> identity, Map<String,String> attributes, Instant createdAt, Instant lastAccessedAt) extends Record
The data a SessionStore keeps for one session: who is signed in, application attributes and two timestamps. Immutable; the store, not the caller, owns the timestamps.

Attribute names match [A-Za-z0-9_.:-]{1,128}, values are at most 4,096 characters, and at most 64 attributes are kept, so a store can bound what one session costs. The session identifier is not part of the state.

  • Field Details

    • MAX_ATTRIBUTES

      public static final int MAX_ATTRIBUTES
      Most attributes one session holds.
      See Also:
    • MAX_VALUE_LENGTH

      public static final int MAX_VALUE_LENGTH
      Longest attribute value, in characters.
      See Also:
  • Constructor Details

  • Method Details

    • empty

      public static SessionState empty()
      Returns an anonymous state without attributes; the store stamps the times.
      Returns:
      the empty state
    • withIdentity

      public SessionState withIdentity(Optional<SecurityIdentity> identity)
      Returns a copy with another identity.
      Parameters:
      identity - the identity, or empty
      Returns:
      the copy
    • withAttributes

      public SessionState withAttributes(Map<String,String> attributes)
      Returns a copy with other attributes.
      Parameters:
      attributes - the attributes
      Returns:
      the copy
    • withTimes

      public SessionState withTimes(Instant createdAt, Instant lastAccessedAt)
      Returns a copy with other timestamps.
      Parameters:
      createdAt - the creation time
      lastAccessedAt - the last access time
      Returns:
      the copy
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • identity

      public Optional<SecurityIdentity> identity()
      Returns the value of the identity record component.
      Returns:
      the value of the identity record component
    • attributes

      public Map<String,String> attributes()
      Returns the value of the attributes record component.
      Returns:
      the value of the attributes record component
    • createdAt

      public Instant createdAt()
      Returns the value of the createdAt record component.
      Returns:
      the value of the createdAt record component
    • lastAccessedAt

      public Instant lastAccessedAt()
      Returns the value of the lastAccessedAt record component.
      Returns:
      the value of the lastAccessedAt record component