Package org.pac4j.http.client.indirect
Class FormClient
- java.lang.Object
-
- org.pac4j.core.util.InitializableObject
-
- org.pac4j.core.client.BaseClient<C>
-
- org.pac4j.core.client.IndirectClient<UsernamePasswordCredentials>
-
- org.pac4j.http.client.indirect.FormClient
-
- All Implemented Interfaces:
Client<UsernamePasswordCredentials>
public class FormClient extends IndirectClient<UsernamePasswordCredentials>
This class is the client to authenticate users through HTTP form.
The login url of the form must be defined through the
setLoginUrl(String)method. For authentication, the user is redirected to this login form. The username and password inputs must be posted on the callback url. Their names can be defined by using thesetUsernameParameter(String)andsetPasswordParameter(String)methods.- Since:
- 1.4.0
- Author:
- Jerome Leleu
-
-
Field Summary
Fields Modifier and Type Field Description static StringERROR_PARAMETERstatic StringMISSING_FIELD_ERROR-
Fields inherited from class org.pac4j.core.client.IndirectClient
ATTEMPTED_AUTHENTICATION_SUFFIX, callbackUrl, callbackUrlResolver, urlResolver
-
Fields inherited from class org.pac4j.core.client.BaseClient
logger
-
-
Constructor Summary
Constructors Constructor Description FormClient()FormClient(String loginUrl, String usernameParameter, String passwordParameter, Authenticator usernamePasswordAuthenticator)FormClient(String loginUrl, Authenticator usernamePasswordAuthenticator)FormClient(String loginUrl, Authenticator usernamePasswordAuthenticator, ProfileCreator profileCreator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclientInit()protected StringcomputeErrorMessage(Exception e)Return the error message depending on the thrown exception.StringgetLoginUrl()StringgetPasswordParameter()StringgetUsernameParameter()protected HttpActionhandleInvalidCredentials(WebContext context, String username, String message, String errorMessage)protected Optional<UsernamePasswordCredentials>retrieveCredentials(WebContext context)voidsetLoginUrl(String loginUrl)voidsetPasswordParameter(String passwordParameter)voidsetUsernameParameter(String usernameParameter)StringtoString()-
Methods inherited from class org.pac4j.core.client.IndirectClient
computeFinalCallbackUrl, defaultLogoutActionBuilder, defaultRedirectionActionBuilder, getAjaxRequestResolver, getCallbackUrl, getCallbackUrlResolver, getCodeVerifierSessionAttributeName, getCredentials, getLogoutAction, getLogoutActionBuilder, getNonceSessionAttributeName, getRedirectionAction, getRedirectionActionBuilder, getStateSessionAttributeName, getUrlResolver, internalInit, newDefaultCallbackUrlResolver, setAjaxRequestResolver, setCallbackUrl, setCallbackUrlResolver, setLogoutActionBuilder, setRedirectionActionBuilder, setUrlResolver
-
Methods inherited from class org.pac4j.core.client.BaseClient
addAuthorizationGenerator, addAuthorizationGenerators, defaultAuthenticator, defaultCredentialsExtractor, defaultProfileCreator, getAuthenticator, getAuthorizationGenerators, getCredentialsExtractor, getCustomProperties, getName, getProfileCreator, getProfileFactoryWhenNotAuthenticated, getUserProfile, notifySessionRenewal, renewUserProfile, retrieveUserProfile, setAuthenticator, setAuthorizationGenerator, setAuthorizationGenerators, setAuthorizationGenerators, setCredentialsExtractor, setCustomProperties, setName, setProfileCreator, setProfileFactoryWhenNotAuthenticated
-
Methods inherited from class org.pac4j.core.util.InitializableObject
init, isInitialized
-
-
-
-
Field Detail
-
ERROR_PARAMETER
public static final String ERROR_PARAMETER
- See Also:
- Constant Field Values
-
MISSING_FIELD_ERROR
public static final String MISSING_FIELD_ERROR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FormClient
public FormClient()
-
FormClient
public FormClient(String loginUrl, Authenticator usernamePasswordAuthenticator)
-
FormClient
public FormClient(String loginUrl, String usernameParameter, String passwordParameter, Authenticator usernamePasswordAuthenticator)
-
FormClient
public FormClient(String loginUrl, Authenticator usernamePasswordAuthenticator, ProfileCreator profileCreator)
-
-
Method Detail
-
clientInit
protected void clientInit()
- Specified by:
clientInitin classIndirectClient<UsernamePasswordCredentials>
-
retrieveCredentials
protected Optional<UsernamePasswordCredentials> retrieveCredentials(WebContext context)
- Overrides:
retrieveCredentialsin classBaseClient<UsernamePasswordCredentials>
-
handleInvalidCredentials
protected HttpAction handleInvalidCredentials(WebContext context, String username, String message, String errorMessage)
-
computeErrorMessage
protected String computeErrorMessage(Exception e)
Return the error message depending on the thrown exception. Can be overriden for other message computation.- Parameters:
e- the technical exception- Returns:
- the error message
-
getLoginUrl
public String getLoginUrl()
-
setLoginUrl
public void setLoginUrl(String loginUrl)
-
getUsernameParameter
public String getUsernameParameter()
-
setUsernameParameter
public void setUsernameParameter(String usernameParameter)
-
getPasswordParameter
public String getPasswordParameter()
-
setPasswordParameter
public void setPasswordParameter(String passwordParameter)
-
toString
public String toString()
- Overrides:
toStringin classIndirectClient<UsernamePasswordCredentials>
-
-