Record Class SessionRecord

java.lang.Object
java.lang.Record
com.svenruppert.jsentinel.session.SessionRecord
Record Components:
sessionId - unique session identifier
subjectId - authenticated subject; non-null
tenant - tenant scope; null becomes TenantId.DEFAULT
createdAt - when the session was opened; non-null
lastActivityAt - last activity on the session; non-null, must not predate createdAt
securityVersionAtLogin - subject security version at login; non-null
status - current lifecycle state; non-null

@ExperimentalJSentinelApi public record SessionRecord(SessionId sessionId, SubjectId subjectId, TenantId tenant, Instant createdAt, Instant lastActivityAt, JSentinelVersion securityVersionAtLogin, SessionStatus status) extends Record
Persistent representation of a single authenticated session.

Stored by SessionStore keyed on sessionId(); queried by (tenant, subjectId) when an admin or a security service needs to enumerate every session of a given subject (e.g. "revoke all sessions of alice after a password change").

The securityVersionAtLogin component is the JSentinelVersion of the subject at the moment this session was opened. A planned JSentinelVersionCheck interceptor (Phase 4 of the V00.70 roadmap) compares this value to the subject's current security version on every request: a mismatch means the subject's authority has changed since login, and the session must be re-validated.

Mutation: records are immutable. Callers update fields by building a new SessionRecord via the with… convenience methods and calling SessionStore.save(...) again.

  • Constructor Details

    • SessionRecord

      public SessionRecord(SessionId sessionId, SubjectId subjectId, TenantId tenant, Instant createdAt, Instant lastActivityAt, JSentinelVersion securityVersionAtLogin, SessionStatus status)
      Validates the record components and normalises a null tenant to TenantId.DEFAULT.
      Parameters:
      sessionId - unique session identifier; non-null
      subjectId - authenticated subject; non-null
      tenant - tenant scope; null becomes DEFAULT
      createdAt - creation instant; non-null
      lastActivityAt - last activity instant; non-null and not before createdAt
      securityVersionAtLogin - subject security version; non-null
      status - lifecycle state; non-null
  • Method Details

    • withLastActivityAt

      public SessionRecord withLastActivityAt(Instant newLastActivity)
      Returns a copy with lastActivityAt() updated to newLastActivity.
      Parameters:
      newLastActivity - new last-activity instant; non-null
      Returns:
      new SessionRecord; receiver unchanged
    • withStatus

      public SessionRecord withStatus(SessionStatus newStatus)
      Returns a copy with status() updated to newStatus. Use this to transition an SessionStatus.ACTIVE session to SessionStatus.EXPIRED or SessionStatus.REVOKED.
      Parameters:
      newStatus - new lifecycle state; non-null
      Returns:
      new SessionRecord; receiver unchanged
    • toString

      public final 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.
    • sessionId

      public SessionId sessionId()
      Returns the value of the sessionId record component.
      Returns:
      the value of the sessionId record component
    • subjectId

      public SubjectId subjectId()
      Returns the value of the subjectId record component.
      Returns:
      the value of the subjectId record component
    • tenant

      public TenantId tenant()
      Returns the value of the tenant record component.
      Returns:
      the value of the tenant record component
    • createdAt

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

      public Instant lastActivityAt()
      Returns the value of the lastActivityAt record component.
      Returns:
      the value of the lastActivityAt record component
    • securityVersionAtLogin

      public JSentinelVersion securityVersionAtLogin()
      Returns the value of the securityVersionAtLogin record component.
      Returns:
      the value of the securityVersionAtLogin record component
    • status

      public SessionStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component