Class DefaultDuoOIDCClientRegistry

All Implemented Interfaces:
DuoOIDCClientRegistry, Component, DestructableComponent, IdentifiableComponent, IdentifiedComponent, InitializableComponent

@ThreadSafe public class DefaultDuoOIDCClientRegistry extends AbstractIdentifiableInitializableComponent implements DuoOIDCClientRegistry

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.