Package net.shibboleth.idp.authn.impl

# Class DefaultAuthenticationResultSerializer

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.idp.authn.impl.DefaultAuthenticationResultSerializer

All Implemented Interfaces:
  `Component`, `DestructableComponent`, `InitializableComponent`, `StorageSerializer<AuthenticationResult>`

public class DefaultAuthenticationResultSerializer extends AbstractInitializableComponent implements StorageSerializer<AuthenticationResult>
Handles serialization of results, delegating handling of `Principal` objects to one or more `PrincipalSerializer` plugins.

## Field Summary

Fields
Modifier and Type
Field
Description
`private static final String`
`ADDTL_DATA_FIELD`
Field name of private credentials array.
`private static final String`
`AUTHN_INSTANT_FIELD`
Field name of authentication instant.
`private final AuthenticationResultPrincipalSerializer`
`authnResultPrincipalSerializer`
Specialized serializer for `AuthenticationResultPrincipal` that requires a circular ref.
`private static final String`
`FLOW_ID_FIELD`
Field name of Flow ID.
`private final JsonGeneratorFactory`
`generatorFactory`
JSON generator factory.
`private final GenericPrincipalSerializer`
`genericSerializer`
Generic principal serializer for any unsupported principals.
`private final org.slf4j.Logger`
`log`
Class logger.
`private static final String`
`PRINCIPAL_ARRAY_FIELD`
Field name of principal array.
`private Collection<PrincipalSerializer<String>>`
`principalSerializers`
Principal serializers.
`private final PrincipalServiceManager`
`principalServiceManager`
Manager for principal services.
`private static final String`
`PRIV_CREDS_ARRAY_FIELD`
Field name of private credentials array.
`private static final String`
`PUB_CREDS_ARRAY_FIELD`
Field name of public credentials array.
`private final JsonReaderFactory`
`readerFactory`
JSON reader factory.
`private static final String`
`RESULT_LIFETIME_FIELD`
Field name of optional result-specific lifetime.
`private static final String`
`RESULT_TIMEOUT_FIELD`
Field name of optional result-specific inactivity timeout.
`private static final String`
`X509_CREDS_ARRAY_FIELD`
Field name of X.509 certificates array.

## Constructor Summary

Constructors
Constructor
Description
`DefaultAuthenticationResultSerializer()`
Constructor.
`DefaultAuthenticationResultSerializer(PrincipalServiceManager manager, GenericPrincipalSerializer defaultSerializer)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`AuthenticationResult`
`deserialize(long version, String context, String key, String value, Long expiration)`
`private Principal`
`deserializePrincipal(JsonValue jsonValue)`
Attempt to deserialize a principal with the registered and default serializers.
`void`
`doInitialize()`
`GenericPrincipalSerializer`
`getGenericPrincipalSerializer()`
Returns the `GenericPrincipalSerializer` used for any unsupported principals found in the `AuthenticationResult`.
`String`
`serialize(AuthenticationResult instance)`
`private void`
`serializePrincipal(JsonGenerator generator, Principal principal)`
Attempt to serialize a principal with the registered and default serializers.

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

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, 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

### FLOW_ID_FIELD

@Nonnull @NotEmpty private static final String FLOW_ID_FIELD
Field name of Flow ID.

See Also:
  - Constant Field Values

### AUTHN_INSTANT_FIELD

@Nonnull @NotEmpty private static final String AUTHN_INSTANT_FIELD
Field name of authentication instant.

See Also:
  - Constant Field Values

### RESULT_LIFETIME_FIELD

@Nonnull @NotEmpty private static final String RESULT_LIFETIME_FIELD
Field name of optional result-specific lifetime.

See Also:
  - Constant Field Values

### RESULT_TIMEOUT_FIELD

@Nonnull @NotEmpty private static final String RESULT_TIMEOUT_FIELD
Field name of optional result-specific inactivity timeout.

See Also:
  - Constant Field Values

### PRINCIPAL_ARRAY_FIELD

@Nonnull @NotEmpty private static final String PRINCIPAL_ARRAY_FIELD
Field name of principal array.

See Also:
  - Constant Field Values

### PUB_CREDS_ARRAY_FIELD

@Nonnull @NotEmpty private static final String PUB_CREDS_ARRAY_FIELD
Field name of public credentials array.

See Also:
  - Constant Field Values

### X509_CREDS_ARRAY_FIELD

@Nonnull @NotEmpty private static final String X509_CREDS_ARRAY_FIELD
Field name of X.509 certificates array.

See Also:
  - Constant Field Values

### PRIV_CREDS_ARRAY_FIELD

@Nonnull @NotEmpty private static final String PRIV_CREDS_ARRAY_FIELD
Field name of private credentials array.

See Also:
  - Constant Field Values

### ADDTL_DATA_FIELD

@Nonnull @NotEmpty private static final String ADDTL_DATA_FIELD
Field name of private credentials array.

See Also:
  - Constant Field Values

### log

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

### generatorFactory

@Nonnull private final JsonGeneratorFactory generatorFactory
JSON generator factory.

### readerFactory

@Nonnull private final JsonReaderFactory readerFactory
JSON reader factory.

### principalServiceManager

@Nonnull private final PrincipalServiceManager principalServiceManager
Manager for principal services.

### principalSerializers

@Nonnull private Collection<PrincipalSerializer<String>> principalSerializers
Principal serializers.

### authnResultPrincipalSerializer

@Nonnull private final AuthenticationResultPrincipalSerializer authnResultPrincipalSerializer
Specialized serializer for `AuthenticationResultPrincipal` that requires a circular ref.

### genericSerializer

@Nonnull private final GenericPrincipalSerializer genericSerializer
Generic principal serializer for any unsupported principals.

## Constructor Details

### DefaultAuthenticationResultSerializer

public DefaultAuthenticationResultSerializer() throws ComponentInitializationException
Constructor.

This is mostly left to facilitate tests that can live with essentially no real serialization support.

Throws:
  `ComponentInitializationException` - if unable to instantiate internal defaults

### DefaultAuthenticationResultSerializer

public DefaultAuthenticationResultSerializer(@Nonnull PrincipalServiceManager manager, @Nonnull GenericPrincipalSerializer defaultSerializer)
Constructor.

Parameters:
  `manager` - `PrincipalServiceManager` to use
  `defaultSerializer` - the default serializer to use
Since:
  4.1.0

## Method Details

### getGenericPrincipalSerializer

@Nonnull public GenericPrincipalSerializer getGenericPrincipalSerializer()
Returns the `GenericPrincipalSerializer` used for any unsupported principals found in the `AuthenticationResult`.

Returns:
  generic principal serializer

### doInitialize

public void doInitialize() throws ComponentInitializationException

Overrides:
  `doInitialize` in class `AbstractInitializableComponent`
Throws:
  `ComponentInitializationException`

### serialize

@Nonnull @NotEmpty public String serialize(@Nonnull AuthenticationResult instance) throws IOException

Specified by:
  `serialize` in interface `StorageSerializer<AuthenticationResult>`
Throws:
  `IOException`

### deserialize

@Nonnull public AuthenticationResult deserialize(long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable Long expiration) throws IOException

Specified by:
  `deserialize` in interface `StorageSerializer<AuthenticationResult>`
Throws:
  `IOException`

### serializePrincipal

private void serializePrincipal(@Nonnull JsonGenerator generator, @Nonnull Principal principal) throws IOException
Attempt to serialize a principal with the registered and default serializers.

Parameters:
  `generator` - the JSON context to write into
  `principal` - object to serialize
Throws:
  `IOException` - if serialization fails

### deserializePrincipal

@Nullable private Principal deserializePrincipal(@Nonnull JsonValue jsonValue) throws IOException
Attempt to deserialize a principal with the registered and default serializers.

Parameters:
  `jsonValue` - the JSON object to parse
Returns:
  the `Principal` recovered, or null
Throws:
  `IOException` - if an error occurs