Class DefaultDuoAdminClient
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.idp.plugin.authn.duo.impl.DefaultDuoAdminClient
- All Implemented Interfaces:
DuoAdminClient,Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent
@ThreadSafeAfterInit
public class DefaultDuoAdminClient
extends AbstractIdentifiableInitializableComponent
implements DuoAdminClient
The default implementation of the
DuoAdminClient for looking up information from the DuoAdmin API.
This class is thread-safe and can be re-used once published.
- Since:
- 2.1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Function<ProfileRequestContext,DuoIntegration> Lookup strategy for Duo integration for Admin API use.private intRate limiting backoff multiplier.private static final intDefault rate limiting backoff multiplier.private static final intDefault initial backoff delay.private static final intDefault maximum backoff.private org.apache.hc.client5.http.classic.HttpClientHttpClient for contacting Duo.private HttpClientSecurityParametersHTTP client security parameters.private intInitial rate limiting delay.private final org.slf4j.LoggerClass logger.private intMaximum backoff delay.private com.fasterxml.jackson.databind.ObjectMapperJSON object mapper.private final RandomGenerates random backoff delay.private static final intThe error returned for rate limiting rejection.private StringThe location of the users admin endpoint. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.hc.core5.http.ClassicHttpRequestbuildRequest(ProfileRequestContext context, String path, Map<String, String> parameters) Build the HTTP request from the given path and parameters.private <T extends DuoAdminResponseWrapper<?>>
TdoAPIRequest(org.apache.hc.core5.http.ClassicHttpRequest request, com.fasterxml.jackson.core.type.TypeReference<T> wrapperTypeRef, int backoff) Performs a call to the Duo AdminAPI.protected voidprivate DuoIntegrationCheck the component is active and if it is get theDuoIntegrationto use.getUser(ProfileRequestContext context, String username) Get the User that corresponds to the given username from the Duo Admin API.Generic method for returning aDuoAdminListMapResponseWrapperresponse from the given path and parameters.<T extends DuoAdminResponseWrapper<?>>
Tretrieve(ProfileRequestContext context, String path, Map<String, String> parameters, com.fasterxml.jackson.core.type.TypeReference<T> wrapperTypeRef) Generic method for returning a type ofDuoAdminResponseWrapperresponse from the given path and parameters.voidSet the lookup strategy to use to locate the Duo Admin API integration.voidsetBackoffFactor(int factor) Set the rate limiting multipler factor.voidsetHttpClient(org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use for contacting Duo.voidSet the optional client security parameters.voidsetInitialBackoff(int backoff) Set the initial backoff delay.voidsetMaxBackoff(int backoff) Set the maximum backoff delay.voidsetObjectMapper(com.fasterxml.jackson.databind.ObjectMapper mapper) Set the JSONObjectMapper.voidsetUsersAdminEndpoint(String endpoint) Set the /users admin endpoint.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
-
DEFAULT_BACKOFF_FACTOR
private static final int DEFAULT_BACKOFF_FACTORDefault rate limiting backoff multiplier.- See Also:
-
DEFAULT_INITIAL_BACKOFF_MS
private static final int DEFAULT_INITIAL_BACKOFF_MSDefault initial backoff delay.- See Also:
-
DEFAULT_MAX_BACKOFF_MS
private static final int DEFAULT_MAX_BACKOFF_MSDefault maximum backoff.- See Also:
-
RATE_LIMIT_ERROR_CODE
private static final int RATE_LIMIT_ERROR_CODEThe error returned for rate limiting rejection.- See Also:
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
backoffFactor
private int backoffFactorRate limiting backoff multiplier. -
initialBackoff
private int initialBackoffInitial rate limiting delay. -
maxBackoff
private int maxBackoffMaximum backoff delay. -
random
Generates random backoff delay. -
httpClient
HttpClient for contacting Duo. -
httpClientSecurityParameters
HTTP client security parameters. -
objectMapper
JSON object mapper. -
adminDuoIntegrationLookupStrategy
Lookup strategy for Duo integration for Admin API use. -
usersAdminEndpoint
The location of the users admin endpoint.
-
-
Constructor Details
-
DefaultDuoAdminClient
public DefaultDuoAdminClient()Constructor.
-
-
Method Details
-
setBackoffFactor
public void setBackoffFactor(int factor) Set the rate limiting multipler factor.- Parameters:
factor- multipler
-
setInitialBackoff
public void setInitialBackoff(int backoff) Set the initial backoff delay.- Parameters:
backoff- initial backoff
-
setMaxBackoff
public void setMaxBackoff(int backoff) Set the maximum backoff delay.- Parameters:
backoff- maximum backoff
-
setHttpClient
public void setHttpClient(@Nonnull org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use for contacting Duo.- Parameters:
client- HttpClient
-
setHttpClientSecurityParameters
Set the optional client security parameters.- Parameters:
params- the new client security parameters
-
setObjectMapper
public void setObjectMapper(@Nonnull com.fasterxml.jackson.databind.ObjectMapper mapper) Set the JSONObjectMapper.- Parameters:
mapper- object mapper
-
setAdminDuoIntegrationLookupStrategy
public void setAdminDuoIntegrationLookupStrategy(@Nonnull Function<ProfileRequestContext, DuoIntegration> strategy) Set the lookup strategy to use to locate the Duo Admin API integration.- Parameters:
strategy- The lookup strategy to set.
-
setUsersAdminEndpoint
Set the /users admin endpoint.- Parameters:
endpoint- The users admin endpoint to set.
-
doInitialize
- Overrides:
doInitializein classAbstractIdentifiedInitializableComponent- Throws:
ComponentInitializationException
-
getUser
@Nullable public User getUser(@Nonnull ProfileRequestContext context, @Nonnull String username) throws DuoException Get the User that corresponds to the given username from the Duo Admin API.- Specified by:
getUserin interfaceDuoAdminClient- Parameters:
context- context the profile request context, typically used in locating theDuoIntegrationto useusername- a user name (or username alias) to look up a single user- Returns:
- the User iff found, or null
- Throws:
DuoException- on error retrieving a response from the API
-
retrieve
@Nonnull public <T extends DuoAdminResponseWrapper<?>> T retrieve(@Nonnull ProfileRequestContext context, @Nonnull @NotEmpty String path, @Nullable @NonnullElements Map<String, String> parameters, @Nonnull com.fasterxml.jackson.core.type.TypeReference<T> wrapperTypeRef) throws DuoExceptionGeneric method for returning a type ofDuoAdminResponseWrapperresponse from the given path and parameters.Note, only GET requests should be allowed and hence only retrieval operations should be supported.
- Specified by:
retrievein interfaceDuoAdminClient- Type Parameters:
T- the type of response- Parameters:
context- the profile request context, typically used in locating theDuoIntegrationto usepath- the path component of the API endpointparameters- any name value pairs to add to the HTTP request parameterswrapperTypeRef- the type of response to return- Returns:
- a
DuoAdminResponseWrapperwith the correct response type embedded - Throws:
DuoException- on error retrieving a response from the API
-
retrieve
@Nonnull public DuoAdminListMapResponseWrapper retrieve(@Nonnull ProfileRequestContext context, @Nonnull @NotEmpty String path, @Nullable @NonnullElements Map<String, String> parameters) throws DuoExceptionGeneric method for returning aDuoAdminListMapResponseWrapperresponse from the given path and parameters.Note, only GET requests should be allowed and hence only retrieval operations should be supported.
- Specified by:
retrievein interfaceDuoAdminClient- Parameters:
context- the profile request context, typically used in locating theDuoIntegrationto usepath- the path component of the API endpointparameters- any name value pairs to add to the HTTP request parameters- Returns:
- a
DuoAdminListMapResponseWrapperwith a List of Maps response type embedded - Throws:
DuoException- on error retrieving a response from the API
-
getIntegrationAndCheckComponentActive
@Nonnull private DuoIntegration getIntegrationAndCheckComponentActive(@Nonnull ProfileRequestContext prc) throws DuoException Check the component is active and if it is get theDuoIntegrationto use.- Parameters:
prc- the profile request context- Returns:
- the
DuoIntegrationto use - Throws:
DuoException- if the integration does not exist
-
buildRequest
@Nonnull private org.apache.hc.core5.http.ClassicHttpRequest buildRequest(@Nonnull ProfileRequestContext context, @Nonnull @NotEmpty String path, @Nullable @NonnullElements Map<String, String> parameters) throws DuoExceptionBuild the HTTP request from the given path and parameters.The
DuoIntegrationis located dynamically. The request is signed using the integration key and secret key from the located integration. Similarly the integration's API host is used as the host component of the URI.- Parameters:
context- the profile request context use to locate theDuoIntegrationto usepath- the path component of the API endpointparameters- a map of name value pairs to add to the HTTP request parameters- Returns:
- the built and signed HTTP request
- Throws:
DuoException- on error creating the request
-
doAPIRequest
@Nonnull private <T extends DuoAdminResponseWrapper<?>> T doAPIRequest(@Nonnull org.apache.hc.core5.http.ClassicHttpRequest request, @Nonnull com.fasterxml.jackson.core.type.TypeReference<T> wrapperTypeRef, int backoff) throws DuoException, IOException Performs a call to the Duo AdminAPI. Upon a successful call, the JSON response is mapped into the appropriate type ofDuoAdminResponseWrapper.- Type Parameters:
T- the DuoResponse type being wrapped- Parameters:
request- the prepared HTTP requestwrapperTypeRef- the type ofDuoResponseWrapperto usebackoff- the backoff delay to apply if needed- Returns:
- a
DuoResponseWrapper - Throws:
IOException- on an I/O errorDuoException- on a Duo-related error
-