Class StoreBackedSubjectSessionRegistry

java.lang.Object
com.svenruppert.jsentinel.logout.StoreBackedSubjectSessionRegistry
All Implemented Interfaces:
SubjectSessionRegistry

@ExperimentalJSentinelApi public final class StoreBackedSubjectSessionRegistry extends Object implements SubjectSessionRegistry
SubjectSessionRegistry that stores its (subject, sessionId) associations as full SessionRecords in a SessionStore.

The registry contract is narrower than what SessionStore can represent — it does not track createdAt / lastActivityAt / status — so this adapter fills the missing fields with sensible defaults at register time: timestamps from the supplied clock, JSentinelVersion.INITIAL (or the subject's current value when a JSentinelVersionStore is supplied), status SessionStatus.ACTIVE. Calling register again for an existing session id refreshes the lastActivityAt via upsert (idempotent in observable effect, as the contract requires).

Bound to one TenantId at construction. Multi-tenant deployments instantiate one registry per tenant.

For Phase 4c (JSentinelVersionCheck-driven session refresh), pass a JSentinelVersionStore so each fresh session captures the subject's current security version as its snapshot. Without one, every snapshot defaults to JSentinelVersion.INITIAL — fine for adapters that don't enforce drift but useless for the Vaadin/REST drift interceptors.

  • Constructor Details

    • StoreBackedSubjectSessionRegistry

      public StoreBackedSubjectSessionRegistry(SessionStore store)
      Builds a registry bound to TenantId.DEFAULT using a system clock and no version-store integration — every new session is recorded with JSentinelVersion.INITIAL.
      Parameters:
      store - backing session store; non-null
    • StoreBackedSubjectSessionRegistry

      public StoreBackedSubjectSessionRegistry(SessionStore store, TenantId tenant, Clock clock)
      Version-store-free constructor.
      Parameters:
      store - backing session store; non-null
      tenant - tenant scope; null becomes TenantId.DEFAULT
      clock - time source; non-null
    • StoreBackedSubjectSessionRegistry

      public StoreBackedSubjectSessionRegistry(SessionStore store, TenantId tenant, Clock clock, JSentinelVersionStore versionStore)
      Full constructor.
      Parameters:
      store - backing session store; non-null
      tenant - tenant scope; null becomes TenantId.DEFAULT
      clock - time source; non-null
      versionStore - optional version store consulted at register-time to capture the subject's current JSentinelVersion as the session snapshot; null falls back to JSentinelVersion.INITIAL
  • Method Details

    • register

      public void register(SubjectId subjectId, String sessionId)
      Description copied from interface: SubjectSessionRegistry
      Records that sessionId belongs to subjectId. Idempotent — registering the same pair twice is a no-op.
      Specified by:
      register in interface SubjectSessionRegistry
      Parameters:
      subjectId - subject the session belongs to
      sessionId - opaque session identifier (token, session id, …)
    • unregister

      public void unregister(SubjectId subjectId, String sessionId)
      Description copied from interface: SubjectSessionRegistry
      Removes the (subjectId, sessionId) association if present. No-op for unknown sessions.
      Specified by:
      unregister in interface SubjectSessionRegistry
      Parameters:
      subjectId - subject the session belongs to
      sessionId - opaque session identifier
    • sessionsOf

      public Collection<String> sessionsOf(SubjectId subjectId)
      Description copied from interface: SubjectSessionRegistry
      Returns every session id currently associated with subjectId. The returned collection is a snapshot; subsequent register / unregister calls do not leak into it.
      Specified by:
      sessionsOf in interface SubjectSessionRegistry
      Parameters:
      subjectId - subject to query
      Returns:
      snapshot of active session ids, possibly empty
    • clearAll

      public Collection<String> clearAll(SubjectId subjectId)
      Description copied from interface: SubjectSessionRegistry
      Forgets every association for subjectId. Returns the set of removed session ids so the caller can drive downstream cleanup (e.g. revoke tokens, invalidate Vaadin sessions).
      Specified by:
      clearAll in interface SubjectSessionRegistry
      Parameters:
      subjectId - subject whose sessions to forget
      Returns:
      removed session ids