Class FormClient

java.lang.Object
org.pac4j.core.util.InitializableObject
org.pac4j.core.client.BaseClient
org.pac4j.core.client.IndirectClient
org.pac4j.http.client.indirect.FormClient
All Implemented Interfaces:
org.pac4j.core.client.Client

public class FormClient extends org.pac4j.core.client.IndirectClient

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 the setUsernameParameter(String) and setPasswordParameter(String) methods.

Since:
1.4.0
Author:
Jerome Leleu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant ERROR_PARAMETER="error"
    static final String
    Constant MISSING_FIELD_ERROR="missing_field"

    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, saveProfileInSession
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for FormClient.
    FormClient(String loginUrl, String usernameParameter, String passwordParameter, org.pac4j.core.credentials.authenticator.Authenticator usernamePasswordAuthenticator)
    Constructor for FormClient.
    FormClient(String loginUrl, org.pac4j.core.credentials.authenticator.Authenticator usernamePasswordAuthenticator)
    Constructor for FormClient.
    FormClient(String loginUrl, org.pac4j.core.credentials.authenticator.Authenticator usernamePasswordAuthenticator, org.pac4j.core.profile.creator.ProfileCreator profileCreator)
    Constructor for FormClient.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Return the error message depending on the thrown exception.
    Optional<org.pac4j.core.credentials.Credentials>
    getCredentials(org.pac4j.core.context.CallContext ctx)
    protected org.pac4j.core.exception.http.HttpAction
    handleInvalidCredentials(org.pac4j.core.context.CallContext ctx, String username, String message, String errorMessage)
    handleInvalidCredentials.
    protected void
    internalInit(boolean forceReinit)
    protected Optional<org.pac4j.core.credentials.Credentials>
    internalValidateCredentials(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials credentials)

    Methods inherited from class org.pac4j.core.client.IndirectClient

    afterInternalInit, beforeInternalInit, checkCredentials, computeFinalCallbackUrl, getAjaxRequestResolver, getCallbackUrl, getCallbackUrlResolver, getCodeVerifierSessionAttributeName, getLogoutAction, getLogoutActionBuilder, getLogoutProcessor, getNonceSessionAttributeName, getRedirectionAction, getRedirectionActionBuilder, getStateSessionAttributeName, getUrlResolver, isCheckAuthenticationAttempt, newDefaultCallbackUrlResolver, processLogout, setAjaxRequestResolver, setCallbackUrl, setCallbackUrlResolver, setCheckAuthenticationAttempt, setLogoutActionBuilder, setLogoutActionBuilderIfUndefined, setLogoutProcessor, setLogoutProcessorIfUndefined, setRedirectionActionBuilder, setRedirectionActionBuilderIfUndefined, setUrlResolver, toString

    Methods 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, validateCredentials

    Methods inherited from class org.pac4j.core.util.InitializableObject

    getInitialized, getLastAttempt, getMaxAttempts, getMinTimeIntervalBetweenAttemptsInMilliseconds, getNbAttempts, init, init, isInitialized, reinit, setMaxAttempts, setMinTimeIntervalBetweenAttemptsInMilliseconds, shouldInitialize

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • ERROR_PARAMETER

      public static final String ERROR_PARAMETER
      Constant ERROR_PARAMETER="error"
      See Also:
    • MISSING_FIELD_ERROR

      public static final String MISSING_FIELD_ERROR
      Constant MISSING_FIELD_ERROR="missing_field"
      See Also:
  • Constructor Details

    • FormClient

      public FormClient()

      Constructor for FormClient.

    • FormClient

      public FormClient(String loginUrl, org.pac4j.core.credentials.authenticator.Authenticator usernamePasswordAuthenticator)

      Constructor for FormClient.

      Parameters:
      loginUrl - a String object
      usernamePasswordAuthenticator - a Authenticator object
    • FormClient

      public FormClient(String loginUrl, String usernameParameter, String passwordParameter, org.pac4j.core.credentials.authenticator.Authenticator usernamePasswordAuthenticator)

      Constructor for FormClient.

      Parameters:
      loginUrl - a String object
      usernameParameter - a String object
      passwordParameter - a String object
      usernamePasswordAuthenticator - a Authenticator object
    • FormClient

      public FormClient(String loginUrl, org.pac4j.core.credentials.authenticator.Authenticator usernamePasswordAuthenticator, org.pac4j.core.profile.creator.ProfileCreator profileCreator)

      Constructor for FormClient.

      Parameters:
      loginUrl - a String object
      usernamePasswordAuthenticator - a Authenticator object
      profileCreator - a ProfileCreator object
  • Method Details

    • internalInit

      protected void internalInit(boolean forceReinit)
      Specified by:
      internalInit in class org.pac4j.core.util.InitializableObject
    • getCredentials

      public Optional<org.pac4j.core.credentials.Credentials> getCredentials(org.pac4j.core.context.CallContext ctx)
      Specified by:
      getCredentials in interface org.pac4j.core.client.Client
      Overrides:
      getCredentials in class org.pac4j.core.client.BaseClient
    • internalValidateCredentials

      protected Optional<org.pac4j.core.credentials.Credentials> internalValidateCredentials(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials credentials)
      Overrides:
      internalValidateCredentials in class org.pac4j.core.client.BaseClient
    • handleInvalidCredentials

      protected org.pac4j.core.exception.http.HttpAction handleInvalidCredentials(org.pac4j.core.context.CallContext ctx, String username, String message, String errorMessage)

      handleInvalidCredentials.

      Parameters:
      ctx - a CallContext object
      username - a String object
      message - a String object
      errorMessage - a String object
      Returns:
      a HttpAction object
    • 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