Class RestAuthenticator
java.lang.Object
org.pac4j.core.util.InitializableObject
org.pac4j.core.profile.definition.ProfileDefinitionAware
org.pac4j.http.credentials.authenticator.RestAuthenticator
- All Implemented Interfaces:
org.pac4j.core.credentials.authenticator.Authenticator
public class RestAuthenticator
extends org.pac4j.core.profile.definition.ProfileDefinitionAware
implements org.pac4j.core.credentials.authenticator.Authenticator
Authenticates against a REST API. The username/password are passed as a basic auth via a POST request,
the JSON response is a user profile.
- Since:
- 2.1.0
- Author:
- Jerome Leleu
-
Field Summary
Fields inherited from interface org.pac4j.core.credentials.authenticator.Authenticator
ALWAYS_VALIDATE, NEVER_VALIDATE -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for RestAuthenticator.RestAuthenticator(String url) Constructor for RestAuthenticator. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildProfile(org.pac4j.core.credentials.UsernamePasswordCredentials credentials, String body) buildProfile.protected StringcallRestApi(String username, String password) Return the body from the REST API, passing the username/pasword auth.protected voidinternalInit(boolean forceReinit) Optional<org.pac4j.core.credentials.Credentials>validate(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials cred) Methods inherited from class org.pac4j.core.profile.definition.ProfileDefinitionAware
getProfileDefinition, setProfileDefinition, setProfileDefinitionIfUndefinedMethods inherited from class org.pac4j.core.util.InitializableObject
afterInternalInit, beforeInternalInit, getInitialized, getLastAttempt, getMaxAttempts, getMinTimeIntervalBetweenAttemptsInMilliseconds, getNbAttempts, init, init, isInitialized, reinit, setMaxAttempts, setMinTimeIntervalBetweenAttemptsInMilliseconds, shouldInitialize, toString
-
Constructor Details
-
RestAuthenticator
public RestAuthenticator()Constructor for RestAuthenticator.
-
RestAuthenticator
Constructor for RestAuthenticator.
- Parameters:
url- aStringobject
-
-
Method Details
-
internalInit
protected void internalInit(boolean forceReinit) - Specified by:
internalInitin classorg.pac4j.core.util.InitializableObject
-
validate
public Optional<org.pac4j.core.credentials.Credentials> validate(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials cred) - Specified by:
validatein interfaceorg.pac4j.core.credentials.authenticator.Authenticator
-
buildProfile
protected void buildProfile(org.pac4j.core.credentials.UsernamePasswordCredentials credentials, String body) buildProfile.
- Parameters:
credentials- aUsernamePasswordCredentialsobjectbody- aStringobject
-
callRestApi
Return the body from the REST API, passing the username/pasword auth. To be overridden using another HTTP client if necessary.- Parameters:
username- the usernamepassword- the password- Returns:
- the response body
-