Class AbstractHttpOAuthAction<T extends com.nimbusds.oauth2.sdk.Response>
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
org.opensaml.profile.action.AbstractProfileAction
org.opensaml.profile.action.AbstractConditionalProfileAction
net.shibboleth.idp.profile.AbstractProfileAction
net.shibboleth.sp.oidc.profile.impl.AbstractAuthorizationResponseAction
net.shibboleth.sp.oidc.profile.impl.AbstractHttpOAuthAction<T>
- Type Parameters:
T- the response type of the object returned as a result of the request.
- All Implemented Interfaces:
net.shibboleth.shared.component.Component,net.shibboleth.shared.component.DestructableComponent,net.shibboleth.shared.component.InitializableComponent,org.opensaml.profile.action.ProfileAction,Aware,MessageSource,MessageSourceAware,Action
- Direct Known Subclasses:
ExchangeCodeForAccessToken,UserInfoEndpointLookup
@ThreadSafeAfterInit
public abstract class AbstractHttpOAuthAction<T extends com.nimbusds.oauth2.sdk.Response>
extends AbstractAuthorizationResponseAction
An abstract class for OIDC/OAuth actions that make synchronous HTTP requests and return types of
responses.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.apache.hc.client5.http.classic.HttpClientHttp client for contacting the endpoint.private org.opensaml.security.httpclient.HttpClientSecurityParametersHTTP client security parameters.private Function<org.opensaml.profile.context.ProfileRequestContext,org.apache.hc.core5.http.ClassicHttpRequest> The message encoder to encode the HTTP request into aHttpUriRequest.private org.apache.hc.core5.http.io.HttpClientResponseHandler<T>The message decoder (Http response handler) to decode the HTTP response.private final org.slf4j.LoggerClass logger. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected TexecuteHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest request, net.shibboleth.oidc.profile.context.AbstractAuthenticatableOIDCContext authenticatableContext) Performs a call to an Http endpoint using the configured HttpClient, HttpClientResponseHandler, and security parameters.private StringformatErrorResponse(com.nimbusds.oauth2.sdk.ErrorObject error) Format an error message string from theErrorObjectprovided.Function<org.opensaml.profile.context.ProfileRequestContext,org.apache.hc.core5.http.ClassicHttpRequest> Get the HTTP request encoder strategy.org.apache.hc.core5.http.io.HttpClientResponseHandler<T>Get the HTTP response decoder/handler strategy.protected ThandleRequest(org.opensaml.profile.context.ProfileRequestContext profileRequestContext, net.shibboleth.oidc.profile.context.AbstractAuthenticatableOIDCContext authenticatableContext) Encode the request using the supplied request encoder strategy, execute a synchronous HTTP request and decode the response using the supplied Http client response decoder strategy/handler.voidsetHttpClient(org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use.voidsetHttpClientSecurityParameters(org.opensaml.security.httpclient.HttpClientSecurityParameters params) Set the optional client security parameters.voidsetHttpRequestEncoderStrategy(Function<org.opensaml.profile.context.ProfileRequestContext, org.apache.hc.core5.http.ClassicHttpRequest> strategy) Set the strategy used to map a HTTP request to aClassicHttpRequestobject.voidsetHttpResponseDecoderStrategy(org.apache.hc.core5.http.io.HttpClientResponseHandler<T> strategy) Set the strategy (Http client response handler) used to map a HTTP response the response type.Methods inherited from class net.shibboleth.sp.oidc.profile.impl.AbstractAuthorizationResponseAction
doPreExecute, getAuthenticationResponse, getProviderMetadataContext, setProviderMetadataLookupStrategyMethods inherited from class net.shibboleth.idp.profile.AbstractProfileAction
doExecute, execute, getBean, getBean, getMessage, getMessage, getMessage, getParameter, getParameter, getProfileContextLookupStrategy, getRequestContext, getResult, setMessageSource, setProfileContextLookupStrategyMethods inherited from class org.opensaml.profile.action.AbstractConditionalProfileAction
getActivationCondition, setActivationConditionMethods inherited from class org.opensaml.profile.action.AbstractProfileAction
doExecute, doPostExecute, doPostExecute, ensureHttpServletRequest, ensureHttpServletResponse, execute, getHttpServletRequest, getHttpServletRequestSupplier, getHttpServletResponse, getHttpServletResponseSupplier, getLogPrefix, isPreExecuteCalled, setHttpServletRequestSupplier, setHttpServletResponseSupplierMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, 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.InitializableComponent
initialize, isInitialized
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
httpRequestEncoderStrategy
@NonnullAfterInit private Function<org.opensaml.profile.context.ProfileRequestContext,org.apache.hc.core5.http.ClassicHttpRequest> httpRequestEncoderStrategyThe message encoder to encode the HTTP request into aHttpUriRequest. -
httpResponseDecoderStrategy
@NonnullAfterInit private org.apache.hc.core5.http.io.HttpClientResponseHandler<T extends com.nimbusds.oauth2.sdk.Response> httpResponseDecoderStrategyThe message decoder (Http response handler) to decode the HTTP response. -
httpClient
@NonnullAfterInit private org.apache.hc.client5.http.classic.HttpClient httpClientHttp client for contacting the endpoint. -
httpClientSecurityParameters
@Nullable private org.opensaml.security.httpclient.HttpClientSecurityParameters httpClientSecurityParametersHTTP client security parameters.
-
-
Constructor Details
-
AbstractHttpOAuthAction
public AbstractHttpOAuthAction()
-
-
Method Details
-
doInitialize
protected void doInitialize() throws net.shibboleth.shared.component.ComponentInitializationException- Overrides:
doInitializein classnet.shibboleth.shared.component.AbstractInitializableComponent- Throws:
net.shibboleth.shared.component.ComponentInitializationException
-
getHttpRequestEncoderStrategy
@NonnullAfterInit public Function<org.opensaml.profile.context.ProfileRequestContext,org.apache.hc.core5.http.ClassicHttpRequest> getHttpRequestEncoderStrategy()Get the HTTP request encoder strategy.- Returns:
- the request encoder.
-
getHttpResponseDecoderStrategy
@NonnullAfterInit public org.apache.hc.core5.http.io.HttpClientResponseHandler<T> getHttpResponseDecoderStrategy()Get the HTTP response decoder/handler strategy.- Returns:
- the response decoder.
-
setHttpResponseDecoderStrategy
public void setHttpResponseDecoderStrategy(@Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<T> strategy) Set the strategy (Http client response handler) used to map a HTTP response the response type.- Parameters:
strategy- the strategy
-
setHttpRequestEncoderStrategy
public void setHttpRequestEncoderStrategy(@Nonnull Function<org.opensaml.profile.context.ProfileRequestContext, org.apache.hc.core5.http.ClassicHttpRequest> strategy) Set the strategy used to map a HTTP request to aClassicHttpRequestobject.- Parameters:
strategy- the strategy
-
setHttpClient
public void setHttpClient(@Nonnull org.apache.hc.client5.http.classic.HttpClient client) Set theHttpClientto use.- Parameters:
client- client to use
-
setHttpClientSecurityParameters
public void setHttpClientSecurityParameters(@Nullable org.opensaml.security.httpclient.HttpClientSecurityParameters params) Set the optional client security parameters.- Parameters:
params- the new client security parameters
-
handleRequest
@Nonnull protected T handleRequest(@Nonnull org.opensaml.profile.context.ProfileRequestContext profileRequestContext, @Nullable net.shibboleth.oidc.profile.context.AbstractAuthenticatableOIDCContext authenticatableContext) throws org.opensaml.messaging.handler.MessageHandlerException Encode the request using the supplied request encoder strategy, execute a synchronous HTTP request and decode the response using the supplied Http client response decoder strategy/handler. If an error response is returned an exception is thrown—the OIDC error object is not propagated back to the caller.The request encoder strategy should return null to indicate an error constructing the request.
- Parameters:
profileRequestContext- the context to pull information out of for encoding the request.authenticatableContext- an authenticatable context to set the authenticated flag. Can be null if no flag is supplied.- Returns:
- a successful decoded response. Never
null. - Throws:
org.opensaml.messaging.handler.MessageHandlerException- on error making the request, or if an error response is returned.
-
formatErrorResponse
Format an error message string from theErrorObjectprovided.- Parameters:
error- the error object- Returns:
- a human readable error string
-
executeHttpRequest
@Nullable protected T executeHttpRequest(@Nonnull org.apache.hc.core5.http.ClassicHttpRequest request, @Nullable net.shibboleth.oidc.profile.context.AbstractAuthenticatableOIDCContext authenticatableContext) throws IOException Performs a call to an Http endpoint using the configured HttpClient, HttpClientResponseHandler, and security parameters.- Parameters:
request- the prepared HTTP requestauthenticatableContext- an authenticatable context to set the authenticated flag. Can be null if no flag is supplied.- Returns:
- the encoded Http response.
- Throws:
IOException- if there is an error producing a response
-