Package dev.dokimos.server.entity
Class ApiKey
java.lang.Object
dev.dokimos.server.entity.ApiKey
A scoped API key used to authenticate write requests against
/api/v1/**. Only the SHA-256 hex
hash of the key is persisted (keyHash); the raw key is shown to the caller exactly once at
creation and never stored. Each key carries a Role that bounds what the caller may do, and an
optional tenant. Disabled keys are rejected at authentication time without being deleted, so a key can
be revoked while its audit trail (created_at, last_used_at) is preserved.-
Constructor Details
-
ApiKey
Creates an enabled key.- Parameters:
keyHash- SHA-256 hex hash of the raw key (never the raw key)name- human-readable label for the keyrole- privilege level granted to callers presenting this keytenantId- tenant the key belongs to, ornullfor an unscoped key
-
-
Method Details
-
getId
-
getKeyHash
-
getName
-
getRole
-
getTenantId
-
isEnabled
public boolean isEnabled() -
disable
public void disable()Disables the key so future authentication attempts with it are rejected. -
getCreatedAt
-
getLastUsedAt
-
markUsed
public void markUsed()Records that the key was just used to authenticate a request.
-