Interface ApiKeyStore
- All Known Implementing Classes:
InMemoryApiKeyStore
Persistent store for
ApiKeyRecords — backs the planned
API-key authentication flow (V00.70 Phase 7b).
Keys are looked up by their hash; the plain value
never enters the store. Revoked and expired records remain visible
to findByHash(String) so the auth flow can distinguish
"known but rejected" from "unknown".
Implementations must be thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionbooleandeleteByHash(String keyHash) Removes the record forkeyHash.findByHash(String keyHash) Looks up an API-key record by its hash.listBySubject(TenantId tenant, SubjectId subjectId) Returns every record (active, revoked, or expired) belonging tosubjectIdwithintenant, in insertion order (oldest first).booleanUpdates theApiKeyRecord.lastUsedAt()timestamp of the record forkeyHash.intpurgeExpired(Instant now) Drops every record whoseApiKeyRecord.expiresAt()is at or beforenow.booleanMarks the record forkeyHashrevoked atat.voidsave(ApiKeyRecord record) Persists or replaces the supplied record.
-
Method Details
-
findByHash
Looks up an API-key record by its hash.- Parameters:
keyHash- key hash; must not benullor blank- Returns:
- the record, if present
-
save
Persists or replaces the supplied record. Keyed onApiKeyRecord.keyHash().- Parameters:
record- record to persist; must not benull
-
listBySubject
Returns every record (active, revoked, or expired) belonging tosubjectIdwithintenant, in insertion order (oldest first). Used by an "manage my API keys" UI.- Parameters:
tenant- tenant scope; must not benullsubjectId- subject; must not benull- Returns:
- immutable list of records; empty when none exist
-
markUsed
Updates theApiKeyRecord.lastUsedAt()timestamp of the record forkeyHash.- Parameters:
keyHash- key hash; must not benullor blankat- instant of use; must not benull- Returns:
trueif the record existed and was updated,falsewhen no such key existed
-
revoke
Marks the record forkeyHashrevoked atat. No-op on an already-revoked record.- Parameters:
keyHash- key hash; must not benullor blankat- instant of revocation; must not benull- Returns:
trueif a not-yet-revoked record was marked,falsewhen no such key existed or when it was already revoked
-
deleteByHash
Removes the record forkeyHash.- Parameters:
keyHash- key hash; must not benullor blank- Returns:
truewhen a record was removed
-
purgeExpired
Drops every record whoseApiKeyRecord.expiresAt()is at or beforenow.- Parameters:
now- retention boundary; must not benull- Returns:
- number of records purged
-