Class DefaultDuoOIDCClientRegistry
- All Implemented Interfaces:
DuoOIDCClientRegistry,Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent
The default Duo Client registry for mapping a DuoOIDCIntegration to either a new
or existing DuoOIDCClient (assumed thread-safe) singleton instance.
Clients are created and registered one-to-one against a DuoOIDCIntegration. Once created, the same client
instance is reused for the same given Duo integration for the lifetime of the IdP.
The DuoOIDCIntegration is the 'key' to the map holding the clients. It therefore should decide its
own 'business key' using the Object.equals(Object) and Object.hashCode() method appropriately. For example,
the DefaultDuoOIDCIntegration uses the clientID as its key. The key should be immutable.
Supports thread-safe lazy initialization of clients when they are first requested. A single, configurable, client factory is called to initialize new clients.
Initialization and fetching is thread safe thanks to the use of a ConcurrentMap and its
ConcurrentMap.computeIfAbsent(Object, Function) operation. This guarantees that two clients should never
be created for the same integration. The client is safely published by the map.
The registry itself is effectively immutable once published by spring.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classA function for creating a new Duo client from the configured client factory for the given Duo integration. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DuoOIDCClientFactoryFactory to produce Duo clients.private final ConcurrentMap<DuoOIDCIntegration,DuoOIDCClient> Registry of Duo client to Duo integration.private final Function<DuoOIDCIntegration,DuoOIDCClient> Function for creating a DuoClient from a DuoIntegration.private final org.slf4j.LoggerClass logger. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprivate DuoOIDCClientFactoryInternally synchronized method for obtaining the 'current' client factory.getClientOrCreate(DuoOIDCIntegration integration) Retrieve an existing, or create a new, Duo client for the given Duo integration.voidsetClientFactory(DuoOIDCClientFactory factory) Set the client factory to use.Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setIdMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentExceptionMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getId
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
clientFactory
Factory to produce Duo clients. -
clientRegistry
@Nonnull @NonnullElements private final ConcurrentMap<DuoOIDCIntegration,DuoOIDCClient> clientRegistryRegistry of Duo client to Duo integration. -
clientRegistryMappingFunction
Function for creating a DuoClient from a DuoIntegration.
-
-
Constructor Details
-
DefaultDuoOIDCClientRegistry
public DefaultDuoOIDCClientRegistry()Constructor.
-
-
Method Details
-
setClientFactory
Set the client factory to use.- Parameters:
factory- the factory.
-
getClientFactory
Internally synchronized method for obtaining the 'current' client factory.- Returns:
- the client factory.
-
getClientOrCreate
@Nonnull public DuoOIDCClient getClientOrCreate(@Nonnull DuoOIDCIntegration integration) throws DuoRegistryException Description copied from interface:DuoOIDCClientRegistryRetrieve an existing, or create a new, Duo client for the given Duo integration. The client should be fully initialised and safely published on return.
implSpec: Only one client should exist per integration i.e. given the same integration, the same client instance should be returned.
implNote: Clients could either be pre-registered, or lazy-initialised when first needed.
- Specified by:
getClientOrCreatein interfaceDuoOIDCClientRegistry- Parameters:
integration- the Duo integration to find a client for, nevernull.- Returns:
- a
DuoOIDCClientappropriate for this integration, nevernull. - Throws:
DuoRegistryException- if there is an issue locating or creating a Duo client.
-
doInitialize
- Overrides:
doInitializein classAbstractIdentifiedInitializableComponent- Throws:
ComponentInitializationException
-