Class InMemoryRefreshTokenStore

java.lang.Object
com.svenruppert.jsentinel.authentication.InMemoryRefreshTokenStore
All Implemented Interfaces:
RefreshTokenStore

@ExperimentalJSentinelApi public final class InMemoryRefreshTokenStore extends Object implements RefreshTokenStore
In-memory RefreshTokenStore backed by a ConcurrentHashMap. Atomic mutations through compute/computeIfPresent.
  • Constructor Details

    • InMemoryRefreshTokenStore

      public InMemoryRefreshTokenStore()
      Creates an empty store.
  • Method Details

    • findByHash

      public Optional<RefreshTokenRecord> findByHash(String tokenHash)
      Description copied from interface: RefreshTokenStore
      Looks up a record by its hash.
      Specified by:
      findByHash in interface RefreshTokenStore
      Parameters:
      tokenHash - token hash; must not be null or blank
      Returns:
      the record, if present
    • save

      public void save(RefreshTokenRecord record)
      Description copied from interface: RefreshTokenStore
      Persists or replaces the supplied record. Keyed on RefreshTokenRecord.tokenHash().
      Specified by:
      save in interface RefreshTokenStore
      Parameters:
      record - record to persist; must not be null
    • markReplaced

      public boolean markReplaced(String oldHash, String newHash, Instant at)
      Description copied from interface: RefreshTokenStore
      Links oldHash as replaced by newHash at at. No-op when oldHash already carries a successor.
      Specified by:
      markReplaced in interface RefreshTokenStore
      Parameters:
      oldHash - hash of the consumed token; non-blank
      newHash - hash of the successor; non-blank
      at - rotation instant; non-null (recorded as the consumed record's revokedAt is left untouched — replacement is tracked through replacedByHash only)
      Returns:
      true if the link was set on a record that previously had no successor; false otherwise
    • markRevoked

      public boolean markRevoked(String tokenHash, Instant at)
      Description copied from interface: RefreshTokenStore
      Marks the record for tokenHash revoked at at. No-op when the record is already revoked.
      Specified by:
      markRevoked in interface RefreshTokenStore
      Parameters:
      tokenHash - token hash; non-blank
      at - revocation instant; non-null
      Returns:
      true if a not-yet-revoked record was marked
    • deleteBySubject

      public int deleteBySubject(TenantId tenant, SubjectId subjectId)
      Description copied from interface: RefreshTokenStore
      Drops every token (active, replaced or revoked) issued to subjectId within tenant.
      Specified by:
      deleteBySubject in interface RefreshTokenStore
      Parameters:
      tenant - tenant scope; non-null
      subjectId - subject; non-null
      Returns:
      number of records removed
    • purgeExpired

      public int purgeExpired(Instant now)
      Description copied from interface: RefreshTokenStore
      Drops every record whose RefreshTokenRecord.expiresAt() is at or before now.
      Specified by:
      purgeExpired in interface RefreshTokenStore
      Parameters:
      now - retention boundary; non-null
      Returns:
      number of records purged