Package net.shibboleth.idp.authn.impl

# Class PrePopulateUsername

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
org.opensaml.profile.action.AbstractProfileAction
org.opensaml.profile.action.AbstractConditionalProfileAction
net.shibboleth.idp.profile.AbstractProfileAction
net.shibboleth.idp.authn.AbstractAuthenticationAction
net.shibboleth.idp.authn.AbstractExtractionAction
net.shibboleth.idp.authn.impl.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 Summary

Fields
Modifier and Type
Field
Description
`private EncryptedCookieManager`
`cookieManager`
Optional cookie manager to use.
`private final org.slf4j.Logger`
`log`
Class logger.
`private List<String>`
`precedence`
Order to pull username from.
`private UsernamePasswordContext`
`usernameContext`
Context to operate on.
`private String`
`usernameFieldName`
Form parameter name to carry username.
`private Function<ProfileRequestContext,UsernamePasswordContext>`
`usernamePasswordContextCreationStrategy`
Strategy used to create/locate the `UsernamePasswordContext` to operate on.

## Constructor Summary

Constructors
Constructor
Description
`PrePopulateUsername()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`doExecute(ProfileRequestContext profileRequestContext, AuthenticationContext authenticationContext)`
Performs this authentication action.
`protected boolean`
`doPreExecute(ProfileRequestContext profileRequestContext, AuthenticationContext authenticationContext)`
Performs this authentication action's pre-execute step.
`private String`
`getUsernameFromCookie(ProfileRequestContext profileRequestContext)`
Gets the username from an existing sealed cookie, if any.
`private String`
`getUsernameFromForm(ProfileRequestContext profileRequestContext)`
Gets the username from a form submission.
`private String`
`getUsernameFromSession(ProfileRequestContext profileRequestContext, AuthenticationContext authenticationContext)`
Gets the username from an existing `IdPSession`, if any.
`void`
`setEncryptedCookieManager(EncryptedCookieManager manager)`
Sets optional `EncryptedCookieManager` to use.
`void`
`setPrecedence(Collection<String> order)`
Sets the precedence rules to use in populating the username.
`void`
`setUsernameFieldName(String name)`
Sets the name of the form field to carry the username.
`void`
`setUsernamePasswordContextCreationStrategy(Function<ProfileRequestContext,UsernamePasswordContext> strategy)`
Set the strategy used to create/locate the `UsernamePasswordContext` to operate on.

### Methods inherited from class net.shibboleth.idp.authn.AbstractExtractionAction

`applyTransforms, applyTransforms, setLowercase, setTransforms, setTrim, setUppercase, setUsernameRemappingStrategy`

### Methods inherited from class net.shibboleth.idp.authn.AbstractAuthenticationAction

`doExecute, doPreExecute, setAuthenticationContextLookupStrategy`

### Methods inherited from class net.shibboleth.idp.profile.AbstractProfileAction

`doExecute, execute, getBean, getBean, getMessage, getMessage, getMessage, getParameter, getParameter, getProfileContextLookupStrategy, getRequestContext, getResult, setMessageSource, setProfileContextLookupStrategy`

### Methods inherited from class org.opensaml.profile.action.AbstractConditionalProfileAction

`getActivationCondition, setActivationCondition`

### Methods inherited from class org.opensaml.profile.action.AbstractProfileAction

`doPostExecute, doPostExecute, ensureHttpServletRequest, ensureHttpServletResponse, execute, getHttpServletRequest, getHttpServletRequestSupplier, getHttpServletResponse, getHttpServletResponseSupplier, getLogPrefix, isPreExecuteCalled, setHttpServletRequestSupplier, setHttpServletResponseSupplier`

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, doInitialize, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.shibboleth.shared.component.InitializableComponent

`initialize, isInitialized`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### usernamePasswordContextCreationStrategy

@Nonnull private Function<ProfileRequestContext,UsernamePasswordContext> usernamePasswordContextCreationStrategy
Strategy used to create/locate the `UsernamePasswordContext` to operate on.

### usernameFieldName

@Nonnull @NotEmpty private String usernameFieldName
Form parameter name to carry username.

### cookieManager

@Nullable private EncryptedCookieManager cookieManager
Optional cookie manager to use.

### precedence

@Nonnull private List<String> precedence
Order to pull username from.

### usernameContext

@NonnullBeforeExec private UsernamePasswordContext usernameContext
Context to operate on.

## 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

### setEncryptedCookieManager

public void setEncryptedCookieManager(@Nullable EncryptedCookieManager manager)
Sets optional `EncryptedCookieManager` to use.

Parameters:
  `manager` - cookie manager

### 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