Class PrePopulateUsername

All Implemented Interfaces:
Component, DestructableComponent, InitializableComponent, ProfileAction, Aware, MessageSource, MessageSourceAware, Action

public class PrePopulateUsername extends AbstractExtractionAction
An action to populate a username into a cleared UsernamePasswordContext, either from a form submission, a cookie, or an existing session to "prime" the login view.

Because this action is essentially a UI optimization, it's forgiving of errors or problems it encounters and will only warn.

Since:
5.1.0
Event:
EventIds.PROCEED_EVENT_ID
Postcondition:
UsernamePasswordContext.setUsername(String) is called with an existing value if found
  • Field Details

  • Constructor Details

    • PrePopulateUsername

      public PrePopulateUsername()
      Constructor.
  • Method Details

    • setUsernamePasswordContextCreationStrategy

      public void setUsernamePasswordContextCreationStrategy(@Nonnull Function<ProfileRequestContext,UsernamePasswordContext> strategy)
      Set the strategy used to create/locate the UsernamePasswordContext to operate on.
      Parameters:
      strategy - creation strategy
    • setUsernameFieldName

      public void setUsernameFieldName(@Nonnull String name)
      Sets the name of the form field to carry the username.
      Parameters:
      name - field name
    • setCookieName

      public void setCookieName(@Nullable String name)
      Set cookie name to use for cached username.
      Parameters:
      name - cookie name
    • setCookieManager

      public void setCookieManager(@Nullable CookieManager manager)
      Sets optional CookieManager to use.
      Parameters:
      manager - cookie manager
    • setDataSealer

      public void setDataSealer(@Nullable DataSealer sealer)
      Sets optional DataSealer to use.
      Parameters:
      sealer - data sealer
    • setPrecedence

      public void setPrecedence(@Nonnull Collection<String> order)
      Sets the precedence rules to use in populating the username.

      Valid tokens are "form", "session", and "cookie" and that is the default order.

      Parameters:
      order - precedence to use
    • doPreExecute

      protected boolean doPreExecute(@Nonnull ProfileRequestContext profileRequestContext, @Nonnull AuthenticationContext authenticationContext)
      Performs this authentication action's pre-execute step. Default implementation just returns true.
      Overrides:
      doPreExecute in class AbstractAuthenticationAction
      Parameters:
      profileRequestContext - the current IdP profile request context
      authenticationContext - the current authentication context
      Returns:
      true iff execution should continue
    • doExecute

      protected void doExecute(@Nonnull ProfileRequestContext profileRequestContext, @Nonnull AuthenticationContext authenticationContext)
      Performs this authentication action. Default implementation throws an exception.
      Overrides:
      doExecute in class AbstractAuthenticationAction
      Parameters:
      profileRequestContext - the current IdP profile request context
      authenticationContext - the current authentication context
    • getUsernameFromForm

      @Nullable private String getUsernameFromForm(@Nonnull ProfileRequestContext profileRequestContext)
      Gets the username from a form submission.

      Also processes do-not-cache instruction.

      Parameters:
      profileRequestContext - profile request context
      Returns:
      submitted username, after applying any configured transforms
    • getUsernameFromCookie

      @Nullable private String getUsernameFromCookie(@Nonnull ProfileRequestContext profileRequestContext)
      Gets the username from an existing sealed cookie, if any.
      Parameters:
      profileRequestContext - profile request context
      Returns:
      username from existing sealed cookie, or null
    • getUsernameFromSession

      @Nullable private String getUsernameFromSession(@Nonnull ProfileRequestContext profileRequestContext, @Nonnull AuthenticationContext authenticationContext)
      Gets the username from an existing IdPSession, if any.
      Parameters:
      profileRequestContext - profile request context
      authenticationContext - authentication context
      Returns:
      username from existing session, or null