Class ApiKeyAuthenticator
- All Implemented Interfaces:
Authenticator
Authenticator backed by two credential sources that coexist for backward compatibility: the
single legacy key configured via DOKIMOS_API_KEY (which maps to Role.ADMIN), and the
scoped keys stored in api_keys (each hashed, each carrying its own role and tenant).
The deployment is in authenticated mode when either a legacy key is configured or at least
one enabled scoped key exists. Outside authenticated mode the behavior is unchanged from before this
feature: reads and writes both pass through as the system principal.
In authenticated mode reads stay open (matching the prior default that reads are always allowed) while
writes require a valid Bearer credential. A presented raw key is hashed with SHA-256 and
matched against enabled keys; the resolved principal carries the key's role and tenant.
-
Constructor Summary
ConstructorsConstructorDescriptionApiKeyAuthenticator(ApiKeyProperties apiKeyProperties, ApiKeyRepository apiKeyRepository) -
Method Summary
Modifier and TypeMethodDescriptionauthenticate(String method, String authorizationHeader) Resolves the principal for a request based on its method and credential.
-
Constructor Details
-
ApiKeyAuthenticator
-
-
Method Details
-
authenticate
Description copied from interface:AuthenticatorResolves the principal for a request based on its method and credential.The method is honored so reads stay open in the default deployment: a read returns the system principal when no credential is presented. A write with no configured authentication also returns the system principal (open mode). Otherwise a valid
Bearercredential resolves to the principal it identifies, and an invalid or missing credential on a write returns empty (rejected). Authorization of the resolved principal against the requested action is the caller's responsibility.- Specified by:
authenticatein interfaceAuthenticator- Parameters:
method- the HTTP methodauthorizationHeader- value of theAuthorizationheader, ornullwhen absent- Returns:
- the principal for an allowed request, or empty to reject
-