Interface RefreshTokenStore

All Known Implementing Classes:
InMemoryRefreshTokenStore

@ExperimentalJSentinelApi public interface RefreshTokenStore
Persistent store for RefreshTokenRecords — backs the planned rotating-refresh-token flow (V00.70 Phase 7b).

Hash-only lookups. Rotation is recorded by calling markReplaced(String, String, Instant) on the consumed record after saving its successor. Replayed/already-rotated tokens are detected by inspecting RefreshTokenRecord.replacedByHash() at validation time; a chain-revoke is the application's responsibility.

Implementations must be thread-safe.

  • Method Details

    • findByHash

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

      void save(RefreshTokenRecord record)
      Persists or replaces the supplied record. Keyed on RefreshTokenRecord.tokenHash().
      Parameters:
      record - record to persist; must not be null
    • markReplaced

      boolean markReplaced(String oldHash, String newHash, Instant at)
      Links oldHash as replaced by newHash at at. No-op when oldHash already carries a successor.
      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

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

      int deleteBySubject(TenantId tenant, SubjectId subjectId)
      Drops every token (active, replaced or revoked) issued to subjectId within tenant.
      Parameters:
      tenant - tenant scope; non-null
      subjectId - subject; non-null
      Returns:
      number of records removed
    • purgeExpired

      int purgeExpired(Instant now)
      Drops every record whose RefreshTokenRecord.expiresAt() is at or before now.
      Parameters:
      now - retention boundary; non-null
      Returns:
      number of records purged