Class ApiKeyAuthenticationService
java.lang.Object
com.svenruppert.jsentinel.authentication.ApiKeyAuthenticationService
Authentication facade for long-lived API keys, sitting on top of
an
ApiKeyStore + PasswordHasher.
authenticate(plainKey) hashes the
candidate with the PasswordHasher (the same shape works:
hash(char[]) → String), looks the record up in the
store, applies the lifecycle invariants
(isActive) and:
- on success: updates
lastUsedAt, publishesApiKeyUsed, returns the record; - on failure: publishes
ApiKeyDeniedwith a short reason ("Unknown","ForeignTenant","Revoked","Expired") and returnsOptional.empty().
The caller (REST adapter / app code) reads the returned
record's scopes and treats them as
the permission set granted by the request. The framework does
not narrow the subject's standing permissions further — scopes
are the entire authorization surface of an API-key request.
Bound to one TenantId at construction. Multi-tenant
deployments instantiate one service per tenant.
-
Constructor Summary
ConstructorsConstructorDescriptionApiKeyAuthenticationService(ApiKeyStore store, PasswordHasher hasher, JSentinelAuditService auditService) Convenience constructor: tenantTenantId.DEFAULT, system clock.ApiKeyAuthenticationService(ApiKeyStore store, PasswordHasher hasher, JSentinelAuditService auditService, TenantId tenant, Clock clock) Full constructor. -
Method Summary
Modifier and TypeMethodDescriptionauthenticate(String plainKey) Authenticates the supplied plain key.
-
Constructor Details
-
ApiKeyAuthenticationService
public ApiKeyAuthenticationService(ApiKeyStore store, PasswordHasher hasher, JSentinelAuditService auditService) Convenience constructor: tenantTenantId.DEFAULT, system clock.- Parameters:
store- API-key store; non-nullhasher- hasher used to hash plain keys for lookup; non-nullauditService- audit sink; non-null
-
ApiKeyAuthenticationService
public ApiKeyAuthenticationService(ApiKeyStore store, PasswordHasher hasher, JSentinelAuditService auditService, TenantId tenant, Clock clock) Full constructor.- Parameters:
store- API-key store; non-nullhasher- hasher used to hash plain keys for lookup; non-nullauditService- audit sink; non-nulltenant- tenant scope;nullbecomesTenantId.DEFAULTclock- time source; non-null
-
-
Method Details
-
authenticate
Authenticates the supplied plain key.- Parameters:
plainKey- plain key value (from a header / cookie); null/blank yields empty- Returns:
- active record on success, empty on every failure mode
-