Package com.axelor.auth.pac4j.local
Class AxelorApiKeyAuthenticator
java.lang.Object
com.axelor.auth.pac4j.local.AxelorApiKeyAuthenticator
- All Implemented Interfaces:
org.pac4j.core.credentials.authenticator.Authenticator
public class AxelorApiKeyAuthenticator
extends Object
implements org.pac4j.core.credentials.authenticator.Authenticator
Authenticator implementation for API key-based authentication.
The authenticator performs the following validations:
- Verifies the API key is present and has the correct format
- Validates the token against the stored digest
- Checks if the token has not expired
- Confirms the associated user account is active
When authentication is successful, the authenticator updates the "last used" date of the token.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordThe two parts composing an API key. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from interface org.pac4j.core.credentials.authenticator.Authenticator
ALWAYS_VALIDATE, NEVER_VALIDATE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected AxelorApiKeyAuthenticator.ApiKeyextractApiKey(org.pac4j.core.credentials.TokenCredentials tokenCredentials) Extracts the key and the token composing the API key of the given credentials.voidsetUserTokenLastUsed(UserToken userToken) Optional<org.pac4j.core.credentials.Credentials> validate(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials credentials) protected UserTokenFinds the user token matching the given API key.
-
Field Details
-
UNSUPPORTED_CREDENTIALS
- See Also:
-
MISSING_API_KEY
- See Also:
-
INVALID_API_KEY
- See Also:
-
USER_DISABLED
- See Also:
-
-
Constructor Details
-
AxelorApiKeyAuthenticator
public AxelorApiKeyAuthenticator()
-
-
Method Details
-
validate
public Optional<org.pac4j.core.credentials.Credentials> validate(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials credentials) - Specified by:
validatein interfaceorg.pac4j.core.credentials.authenticator.Authenticator
-
extractApiKey
protected AxelorApiKeyAuthenticator.ApiKey extractApiKey(org.pac4j.core.credentials.TokenCredentials tokenCredentials) Extracts the key and the token composing the API key of the given credentials.- Parameters:
tokenCredentials- the credentials holding the API key- Returns:
- the key and the token extracted from the API key
- Throws:
org.pac4j.core.exception.BadCredentialsException- if the API key is missing or malformed
-
validateUser
Finds the user token matching the given API key.- Parameters:
apiKey- the key and the token extracted from the API key- Returns:
- the matching user token, owned by an active user
- Throws:
org.pac4j.core.exception.AccountNotFoundException- if the API key is invalid or expired, or if its owner is disabled
-
setUserTokenLastUsed
-