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 String
ERROR_PARAMETER
static String
MISSING_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 void
clientInit()
protected String
computeErrorMessage(Exception e)
Return the error message depending on the thrown exception.String
getLoginUrl()
String
getPasswordParameter()
String
getUsernameParameter()
protected HttpAction
handleInvalidCredentials(WebContext context, String username, String message, String errorMessage)
protected Optional<UsernamePasswordCredentials>
retrieveCredentials(WebContext context)
void
setLoginUrl(String loginUrl)
void
setPasswordParameter(String passwordParameter)
void
setUsernameParameter(String usernameParameter)
String
toString()
-
Methods inherited from class org.pac4j.core.client.IndirectClient
computeFinalCallbackUrl, defaultLogoutActionBuilder, defaultRedirectionActionBuilder, getAjaxRequestResolver, getCallbackUrl, getCallbackUrlResolver, 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, getUserProfile, notifySessionRenewal, renewUserProfile, retrieveUserProfile, setAuthenticator, setAuthorizationGenerator, setAuthorizationGenerators, setAuthorizationGenerators, setCredentialsExtractor, setCustomProperties, setName, setProfileCreator
-
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:
clientInit
in classIndirectClient<UsernamePasswordCredentials>
-
retrieveCredentials
protected Optional<UsernamePasswordCredentials> retrieveCredentials(WebContext context)
- Overrides:
retrieveCredentials
in 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:
toString
in classIndirectClient<UsernamePasswordCredentials>
-
-