Package org.apache.sling.auth.core.spi

# Class AuthenticationInfo

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
org.apache.sling.auth.core.spi.AuthenticationInfo

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Map<String,Object>`

public class AuthenticationInfo extends HashMap<String,Object>
The `AuthenticationInfo` conveys any authentication credentials and/or details extracted by the `JakartaAuthenticationHandler.extractCredentials(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)` method from the request.

`JakartaAuthenticationHandler` implementations must return instances of this class which may be constructed through any of the provided public constructors.

Internally all values are stored in the map where some property names have special semantics and the data type of the properties are ensured by the `put(String, Object)` method implementation.

See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class java.util.AbstractMap

`AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K extends Object,V extends Object>`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`AUTH_TYPE`
The name of the special property providing the authentication type provided by the `JakartaAuthenticationHandler`.
`static final AuthenticationInfo`
`DOING_AUTH`
A special instance of this class which may be returned from the `JakartaAuthenticationHandler.extractCredentials(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)` method to inform the caller, that a response has been sent to the client to request for credentials.
`static final AuthenticationInfo`
`FAIL_AUTH`
A special instance of this class which may be returned from the `JakartaAuthenticationHandler.extractCredentials(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)` method to inform the caller that credential extraction failed for some reason.

## Constructor Summary

Constructors
Constructor
Description
`AuthenticationInfo(String authType)`
Creates an instance of this class with just the authentication type.
`AuthenticationInfo(String authType, String userId)`
Creates an instance of this class authenticating with the given type and userid.
`AuthenticationInfo(String authType, String userId, char[] password)`
Creates an instance of this class authenticating with the given type and userid/password connecting.

## Method Summary

Modifier and Type
Method
Description
`void`
`clear()`
Clears all properties from the map with the exception of the `AUTH_TYPE` property.
`final String`
`getAuthType()`
Returns the authentication type as stored in the `AUTH_TYPE` property in this map.
`final char[]`
`getPassword()`
Returns the password stored as the `ResourceResolverFactory.PASSWORD` property or `null` if the password is not set in this map.
`final String`
`getUser()`
Returns the user name stored as the `ResourceResolverFactory.USER` property or `null` if the user is not set in this map.
`Object`
`put(String key, Object value)`
Sets or resets a property with the given `key` to a new `value`.
`Object`
`remove(Object key)`
Removes the entry with the given `key` and returns its former value (if existing).
`final void`
`setAuthType(String authType)`
`final void`
`setPassword(char[] password)`
`final void`
`setUser(String user)`

### Methods inherited from class java.util.HashMap

`clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, values`

### Methods inherited from class java.util.AbstractMap

`equals, hashCode, toString`

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

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Map

`equals, hashCode`

## Field Details

### DOING_AUTH

public static final AuthenticationInfo DOING_AUTH
A special instance of this class which may be returned from the `JakartaAuthenticationHandler.extractCredentials(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)` method to inform the caller, that a response has been sent to the client to request for credentials.

If this value is returned, the request should be considered finished and no further actions should be taken on this request.

### FAIL_AUTH

public static final AuthenticationInfo FAIL_AUTH
A special instance of this class which may be returned from the `JakartaAuthenticationHandler.extractCredentials(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)` method to inform the caller that credential extraction failed for some reason.

If this value is returned, the handler signals that credentials would be present in the request but the credentials are not valid for use (for example OpenID identify failed to validate or some authentication cookie expired).

### AUTH_TYPE

public static final String AUTH_TYPE
The name of the special property providing the authentication type provided by the `JakartaAuthenticationHandler`. This value must be supplied to one of the constructors and is ultimately used as the value of the `HttpServletRequest.getAuthType` method.

This property is always present (and cannot be removed) in this map and is of `String` type.

See Also:
  - Constant Field Values

## Constructor Details

### AuthenticationInfo

public AuthenticationInfo(String authType)
Creates an instance of this class with just the authentication type. To effectively use this instance the user Id with optional password and/or the credentials should be set.

Parameters:
  `authType` - The authentication type, must not be `null`.

### AuthenticationInfo

public AuthenticationInfo(String authType, String userId)
Creates an instance of this class authenticating with the given type and userid.

Parameters:
  `authType` - The authentication type, must not be `null`.
  `userId` - The name of the user to authenticate as. This may be `null` for the constructor and later be set.
Throws:
  `NullPointerException` - if `authType` is `null`.

### AuthenticationInfo

public AuthenticationInfo(String authType, String userId, char[] password)
Creates an instance of this class authenticating with the given type and userid/password connecting.

Parameters:
  `authType` - The authentication type, must not be `null`.
  `userId` - The name of the user to authenticate as. This may be `null` for the constructor and later be set.
  `password` - The password to authenticate with or `null` if no password can be supplied.
Throws:
  `NullPointerException` - if `authType` is `null`.

## Method Details

### setAuthType

public final void setAuthType(String authType)

Parameters:
  `authType` - The authentication type to set. If this is `null` the current authentication type is not replaced.

### getAuthType

public final String getAuthType()
Returns the authentication type as stored in the `AUTH_TYPE` property in this map. This value is expected to never be `null`.

If authentication is taking place through one of the standard ways, such as Basic or Digest, the return value is one of the predefined constants of the `HttpServletRequest` interface. Otherwise the value may be specific to the `JakartaAuthenticationHandler` implementation.

Returns:
  The authentication type as stored in the `AUTH_TYPE` property.

### setUser

public final void setUser(String user)

Parameters:
  `user` - The name of the user to authenticate as. If this is `null` the current user name is not replaced.

### getUser

public final String getUser()
Returns the user name stored as the `ResourceResolverFactory.USER` property or `null` if the user is not set in this map.

Returns:
  The user name as stored in the `ResourceResolverFactory.USER` property.

### setPassword

public final void setPassword(char[] password)

Parameters:
  `password` - The password to authenticate with. If this is `null` the current password is not replaced.

### getPassword

public final char[] getPassword()
Returns the password stored as the `ResourceResolverFactory.PASSWORD` property or `null` if the password is not set in this map.

Returns:
  the password as stored in the `ResourceResolverFactory.PASSWORD` property

### put

public Object put(String key, Object value)
Sets or resets a property with the given `key` to a new `value`. Some keys have special meanings and their values are required to have predefined as listed in the following table:

Predefined Keys
`AUTH_TYPE` | `String`
`ResourceResolverFactory.USER` | `String`
`ResourceResolverFactory.PASSWORD` | `char[]`

If the value for the special key does not match the required type an `IllegalArgumentException` is thrown.

Specified by:
  `put` in interface `Map<String,Object>`
Overrides:
  `put` in class `HashMap<String,Object>`
Parameters:
  `key` - The name of the property to set
  `value` - The value of the property which must be of a special type if the `key` designates one of the predefined properties.
Returns:
  The value previously set for the given `key`.
Throws:
  `IllegalArgumentException` - if `key` designates one of the special properties and the `value` does not have the correct type for the respective key.

### remove

public Object remove(Object key)
Removes the entry with the given `key` and returns its former value (if existing). If the `key` is `AUTH_TYPE` the value is not actually removed and `null` is always returned.

Specified by:
  `remove` in interface `Map<String,Object>`
Overrides:
  `remove` in class `HashMap<String,Object>`
Parameters:
  `key` - Removes the value associated with this key.
Returns:
  The former value associated with the key.

### clear

public void clear()
Clears all properties from the map with the exception of the `AUTH_TYPE` property.

Specified by:
  `clear` in interface `Map<String,Object>`
Overrides:
  `clear` in class `HashMap<String,Object>`