Interface ApiKeyCredentialRepository
- All Known Implementing Classes:
JdbcApiKeyCredentialRepository
public interface ApiKeyCredentialRepository
Repository for persisting and retrieving
ApiKeyCredential records.-
Method Summary
Modifier and TypeMethodDescriptionbooleandeleteById(UUID id) Deletes the credential with the given id.booleanBrings a live key's expiry forward toexpiresAt, never later than it already is, in one statement, so rotations that race each other leave the earliest expiry.default Optional<ApiKeyCredential> Finds a credential by its id, so that revoking it can report its name.findByKeyHash(String keyHash) Finds a credential by its SHA-256 key hash.save(ApiKeyCredential credential) Persists a credential.booleanRecords 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 beforenotSince, so a busy key costs one write per interval.
-
Method Details
-
findByKeyHash
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
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 sameidalready exists it is updated with the new key hash.- Parameters:
credential- the credential to save- Returns:
- the saved credential
-
deleteById
Deletes the credential with the given id.- Parameters:
id- the credential UUID- Returns:
trueif a credential was deleted,falseif there was none
-
touch
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 beforenotSince, so a busy key costs one write per interval.- Parameters:
id- the key's credential idnow- when it signed innotSince- the earliest earlier use that makes this write unnecessary- Returns:
truewhen the time was written
-
expireBy
Brings a live key's expiry forward toexpiresAt, 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 idexpiresAt- the latest the key may now expirenow- the key must not have expired by this instant- Returns:
truewhen the key exists and has not expired;falsewhen it was revoked or has expired, and nothing was written
-