# Interface ContextFactory

public interface ContextFactory
Contains configuration for creating AuthContext objects from user credentials.

Since:
  15 Jun 2020
Author:
  Mark Taylor
See Also:
  - `AuthScheme.createContextFactory(Challenge, URL)`

## Method Summary

Modifier and Type
Method
Description
`AuthContext`
`createContext(UserInterface ui)`
Attempts to create an authentication context, by enquiring for input from the UI as appropriate.
`AuthContext`
`createUnauthContext()`
Creates a context representing unauthenticated (anonymous) access.

## Method Details

### createContext

AuthContext createContext(UserInterface ui)
Attempts to create an authentication context, by enquiring for input from the UI as appropriate. Should return an apparently viable, though not guaranteed valid, context (`AuthContext.hasCredentials()` will return true), or null if the user declined to authenticate.

If appropriate, the implementation of this method should offer the user retry attempts following failed or inadequate credential entry in accordance with the supplied UserInterface. Note however that retries must not be attempted if `UserInterface.canRetry()` returns false or following a null return from `UserInterface.readUserPassword(String[])`.

Parameters:
  `ui` - user interface that can be used to query the user for credentials
Returns:
  authentication context, or null if the user declined to authenticate

### createUnauthContext

AuthContext createUnauthContext()
Creates a context representing unauthenticated (anonymous) access. The resulting context, for which `AuthContext.hasCredentials()` will return false, may or may not be capable of connecting, but it can represent the choice of a user not to authenticate for a given challenge.

Returns:
  anonymous authentication context