Package dev.dokimos.server.service
Class ApiKeyService
java.lang.Object
dev.dokimos.server.service.ApiKeyService
Mints and manages scoped API keys. A raw key is generated from a CSPRNG, returned to the caller once,
and stored only as a SHA-256 hash. Reads and revocation operate on the hashed records and never expose
key material.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate(CreateApiKeyRequest request) Generates a key, stores its hash, and returns the raw key exactly once.voidPermanently deletes a key.Disables a key so future authentication attempts with it are rejected, keeping its record for audit.list()Lists every key as metadata only; key material is never included.
-
Constructor Details
-
ApiKeyService
-
-
Method Details
-
create
Generates a key, stores its hash, and returns the raw key exactly once.- Parameters:
request- the key definition- Returns:
- the created key's metadata plus the raw key (the only time it is exposed)
-
list
Lists every key as metadata only; key material is never included. -
disable
Disables a key so future authentication attempts with it are rejected, keeping its record for audit. Disabling an already-disabled key is a no-op.- Parameters:
id- the key to disable- Returns:
- the updated metadata
- Throws:
IllegalArgumentException- if no key has the id (mapped to 404)
-
delete
Permanently deletes a key.- Parameters:
id- the key to delete- Throws:
IllegalArgumentException- if no key has the id (mapped to 404)
-