Package com.axelor.auth.pac4j.local
Class AxelorApiKeyClient
java.lang.Object
org.pac4j.core.util.InitializableObject
org.pac4j.core.client.BaseClient
org.pac4j.core.client.DirectClient
org.pac4j.http.client.direct.HeaderClient
com.axelor.auth.pac4j.local.AxelorApiKeyClient
- All Implemented Interfaces:
StatelessClient,org.pac4j.core.client.Client
public class AxelorApiKeyClient
extends org.pac4j.http.client.direct.HeaderClient
implements StatelessClient
Direct client for API key-based authentication.
Reads the API key from the API-KEY request header and delegates its validation to
AxelorApiKeyAuthenticator.
Being a StatelessClient, it authenticates each request on its own and never lets a
session be created.
Rejected API keys never reach a Shiro realm, so they are reported to the CredentialsHandler for the failed login to be tracked.
-
Field Summary
Fields inherited from class org.pac4j.core.client.BaseClient
logger, saveProfileInSession -
Constructor Summary
ConstructorsConstructorDescriptionAxelorApiKeyClient(AxelorApiKeyAuthenticator axelorApiKeyAuthenticator, CredentialsHandler credentialsHandler) -
Method Summary
Modifier and TypeMethodDescriptionOptional<org.pac4j.core.credentials.Credentials> getCredentials(org.pac4j.core.context.CallContext ctx) Extracts the API key credentials from the request.booleanhasCredentials(org.pac4j.core.context.WebContext context) Whether the request carries an API key.protected Optional<org.pac4j.core.credentials.Credentials> internalValidateCredentials(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials credentials) Validates the extracted credentials against the authenticator.Methods inherited from class org.pac4j.http.client.direct.HeaderClient
getHeaderName, getPrefixHeader, internalInit, setHeaderName, setPrefixHeader, toStringMethods inherited from class org.pac4j.core.client.DirectClient
afterInternalInit, beforeInternalInit, checkCredentials, getLogoutAction, getRedirectionAction, processLogoutMethods inherited from class org.pac4j.core.client.BaseClient
addAuthorizationGenerator, addAuthorizationGenerators, findSessionLogoutHandler, getAuthenticator, getAuthorizationGenerators, getConfig, getCredentialsExtractor, getCustomProperties, getLogger, getName, getProfileCreator, getProfileFactoryWhenNotAuthenticated, getSaveProfileInSession, getSaveProfileInSession, getUserProfile, isMultiProfile, isMultiProfile, notifySessionRenewal, renewUserProfile, setAuthenticator, setAuthenticatorIfUndefined, setAuthorizationGenerator, setAuthorizationGenerators, setAuthorizationGenerators, setConfig, setCredentialsExtractor, setCredentialsExtractorIfUndefined, setCustomProperties, setMultiProfile, setName, setProfileCreator, setProfileCreatorIfUndefined, setProfileFactoryWhenNotAuthenticated, setSaveProfileInSession, validateCredentialsMethods inherited from class org.pac4j.core.util.InitializableObject
getInitialized, getLastAttempt, getMaxAttempts, getMinTimeIntervalBetweenAttemptsInMilliseconds, getNbAttempts, init, init, init, init, isInitialized, isInitializing, reinit, setMaxAttempts, setMinTimeIntervalBetweenAttemptsInMilliseconds, shouldInitializeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.axelor.auth.pac4j.local.StatelessClient
disableSessionCreation
-
Constructor Details
-
AxelorApiKeyClient
@Inject public AxelorApiKeyClient(AxelorApiKeyAuthenticator axelorApiKeyAuthenticator, CredentialsHandler credentialsHandler)
-
-
Method Details
-
hasCredentials
public boolean hasCredentials(org.pac4j.core.context.WebContext context) Whether the request carries an API key.- Specified by:
hasCredentialsin interfaceStatelessClient- Parameters:
context- the web context- Returns:
trueif theAPI-KEYheader is present
-
getCredentials
public Optional<org.pac4j.core.credentials.Credentials> getCredentials(org.pac4j.core.context.CallContext ctx) Extracts the API key credentials from the request.Session creation is disabled as soon as an API key is found, so that authenticating with an API key never creates a session.
- Specified by:
getCredentialsin interfaceorg.pac4j.core.client.Client- Overrides:
getCredentialsin classorg.pac4j.core.client.BaseClient- Parameters:
ctx- the call context- Returns:
- the extracted credentials, or empty if the request carries no API key
-
internalValidateCredentials
protected Optional<org.pac4j.core.credentials.Credentials> internalValidateCredentials(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials credentials) Validates the extracted credentials against the authenticator.The authenticator rejects invalid credentials before any Shiro login is attempted, so such failures are reported to the
CredentialsHandler, along with the submitted API key when it could be extracted.- Overrides:
internalValidateCredentialsin classorg.pac4j.core.client.BaseClient- Parameters:
ctx- the call contextcredentials- the credentials to validate- Returns:
- the validated credentials, or empty if they were rejected
-