Interface ApiKeyCredentialRepository

All Known Implementing Classes:
JdbcApiKeyCredentialRepository

public interface ApiKeyCredentialRepository
Repository for persisting and retrieving ApiKeyCredential records.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Deletes the credential with the given id.
    boolean
    expireBy(UUID id, Instant expiresAt, Instant now)
    Brings a live key's expiry forward to expiresAt, never later than it already is, in one statement, so rotations that race each other leave the earliest expiry.
    Finds a credential by its id, so that revoking it can report its name.
    Finds a credential by its SHA-256 key hash.
    save(ApiKeyCredential credential)
    Persists a credential.
    boolean
    touch(UUID id, Instant now, Instant notSince)
    Records that a key signed in, unless it already did within the interval: the write happens only when the key was never used or last used before notSince, so a busy key costs one write per interval.
  • Method Details

    • findByKeyHash

      Optional<ApiKeyCredential> findByKeyHash(String keyHash)
      Finds a credential by its SHA-256 key hash.
      Parameters:
      keyHash - the SHA-256 hex-encoded hash of the raw API key
      Returns:
      the matching credential, or empty if not found
    • findById

      default Optional<ApiKeyCredential> findById(UUID id)
      Finds a credential by its id, so that revoking it can report its name. A repository that cannot find by id keeps this default, and revocations it serves report no name.
      Parameters:
      id - the credential UUID
      Returns:
      the matching credential, or empty if not found
    • save

      Persists a credential. If a record with the same id already exists it is updated with the new key hash.
      Parameters:
      credential - the credential to save
      Returns:
      the saved credential
    • deleteById

      boolean deleteById(UUID id)
      Deletes the credential with the given id.
      Parameters:
      id - the credential UUID
      Returns:
      true if a credential was deleted, false if there was none
    • touch

      boolean touch(UUID id, Instant now, Instant notSince)
      Records that a key signed in, unless it already did within the interval: the write happens only when the key was never used or last used before notSince, so a busy key costs one write per interval.
      Parameters:
      id - the key's credential id
      now - when it signed in
      notSince - the earliest earlier use that makes this write unnecessary
      Returns:
      true when the time was written
    • expireBy

      boolean expireBy(UUID id, Instant expiresAt, Instant now)
      Brings a live key's expiry forward to expiresAt, never later than it already is, in one statement, so rotations that race each other leave the earliest expiry.
      Parameters:
      id - the key's credential id
      expiresAt - the latest the key may now expire
      now - the key must not have expired by this instant
      Returns:
      true when the key exists and has not expired; false when it was revoked or has expired, and nothing was written