Module org.mule.oauth.client.impl
Package org.mule.oauth.client.internal
Class AbstractOAuthDancer<T extends OAuthDancerConfig>
- java.lang.Object
-
- org.mule.oauth.client.internal.AbstractOAuthDancer<T>
-
- All Implemented Interfaces:
org.mule.runtime.api.lifecycle.Startable,org.mule.runtime.api.lifecycle.Stoppable
- Direct Known Subclasses:
DefaultAuthorizationCodeOAuthDancer,DefaultClientCredentialsOAuthDancer
public abstract class AbstractOAuthDancer<T extends OAuthDancerConfig> extends Object implements org.mule.runtime.api.lifecycle.Startable, org.mule.runtime.api.lifecycle.Stoppable
Base implementations with behavior common to all grant-types.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description protected Tconfigstatic intTOKEN_REQUEST_TIMEOUT_MILLIS
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractOAuthDancer(T config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoAddListener(org.mule.oauth.client.api.listener.OAuthStateListener listener)protected <T> CompletableFuture<T>doRefreshToken(Supplier<org.mule.oauth.client.api.state.ResourceOwnerOAuthContext> oauthContextSupplier, Function<org.mule.oauth.client.api.state.ResourceOwnerOAuthContext,CompletableFuture<T>> tokenRefreshRequester)Method for refreshing tokens in a thread-safe manner across nodes of a cluster.protected <T> CompletableFuture<T>doRefreshTokenRequest(Function<org.mule.oauth.client.api.state.ResourceOwnerOAuthContext,CompletableFuture<T>> tokenRefreshRequester, org.mule.oauth.client.api.state.ResourceOwnerOAuthContext oauthContext)protected voiddoRemoveListener(org.mule.oauth.client.api.listener.OAuthStateListener listener)org.mule.oauth.client.api.state.ResourceOwnerOAuthContextgetContextForResourceOwner(String resourceOwnerId)Retrieves the oauth context for a particular user.protected List<? extends org.mule.oauth.client.api.listener.OAuthStateListener>getListenersToNotifyInvalidation(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext resourceOwnerOAuthContext)Retrieves all the listeners that should be notified of a token invalidation event.protected org.mule.runtime.api.lock.LockFactorygetLockProvider()protected StringhandleClientCredentials(Map<String,String> formData)Based on the value ofclientCredentialsLocation, add the clientId and clientSecret values to the form or encode and return them.voidinvalidateContext(String resourceOwner)protected CompletableFuture<TokenResponse>invokeTokenUrl(String tokenUrl, Map<String,String> tokenRequestFormToSend, org.mule.runtime.api.util.MultiMap<String,String> queryParams, org.mule.runtime.api.util.MultiMap<String,String> headers, String authorization, boolean retrieveRefreshToken, Charset encoding)protected voidonEachListener(Consumer<org.mule.oauth.client.api.listener.OAuthStateListener> action)protected voidonEachListener(List<? extends org.mule.oauth.client.api.listener.OAuthStateListener> listeners, Consumer<org.mule.oauth.client.api.listener.OAuthStateListener> action)protected TokenResponseparseTokenResponse(org.mule.runtime.http.api.domain.message.response.HttpResponse response, String tokenUrl, boolean retrieveRefreshToken)protected <T> TresolveExpression(String expr, Object body, org.mule.runtime.api.util.MultiMap<String,String> headers, org.mule.runtime.api.metadata.MediaType responseContentType)protected <T> TresolveExpression(String expr, Object body, org.mule.runtime.api.util.MultiMap<String,String> headers, org.mule.runtime.api.util.MultiMap<String,String> queryParams, org.mule.runtime.api.metadata.MediaType responseContentType)voidstart()protected voidstartHttpClient()voidstop()protected voidstopHttpClient()protected <T> Function<Throwable,? extends T>tokenUrlExceptionHandler(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext defaultUserState)protected voidupdateOAuthContextAfterTokenResponse(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext defaultUserState)protected voidupdateResourceOwnerOAuthContext(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext resourceOwnerOAuthContext)Updates the resource owner oauth context information
-
-
-
Field Detail
-
TOKEN_REQUEST_TIMEOUT_MILLIS
public static final int TOKEN_REQUEST_TIMEOUT_MILLIS
- See Also:
- Constant Field Values
-
config
protected final T extends OAuthDancerConfig config
-
-
Constructor Detail
-
AbstractOAuthDancer
protected AbstractOAuthDancer(T config)
-
-
Method Detail
-
start
public void start() throws org.mule.runtime.api.exception.MuleException- Specified by:
startin interfaceorg.mule.runtime.api.lifecycle.Startable- Throws:
org.mule.runtime.api.exception.MuleException
-
startHttpClient
protected void startHttpClient()
-
stop
public void stop() throws org.mule.runtime.api.exception.MuleException- Specified by:
stopin interfaceorg.mule.runtime.api.lifecycle.Stoppable- Throws:
org.mule.runtime.api.exception.MuleException
-
stopHttpClient
protected void stopHttpClient()
-
handleClientCredentials
protected String handleClientCredentials(Map<String,String> formData)
Based on the value ofclientCredentialsLocation, add the clientId and clientSecret values to the form or encode and return them.- Parameters:
formData-
-
doRefreshToken
protected <T> CompletableFuture<T> doRefreshToken(Supplier<org.mule.oauth.client.api.state.ResourceOwnerOAuthContext> oauthContextSupplier, Function<org.mule.oauth.client.api.state.ResourceOwnerOAuthContext,CompletableFuture<T>> tokenRefreshRequester)
Method for refreshing tokens in a thread-safe manner across nodes of a cluster.
-
doRefreshTokenRequest
protected <T> CompletableFuture<T> doRefreshTokenRequest(Function<org.mule.oauth.client.api.state.ResourceOwnerOAuthContext,CompletableFuture<T>> tokenRefreshRequester, org.mule.oauth.client.api.state.ResourceOwnerOAuthContext oauthContext)
-
invokeTokenUrl
protected CompletableFuture<TokenResponse> invokeTokenUrl(String tokenUrl, Map<String,String> tokenRequestFormToSend, org.mule.runtime.api.util.MultiMap<String,String> queryParams, org.mule.runtime.api.util.MultiMap<String,String> headers, String authorization, boolean retrieveRefreshToken, Charset encoding)
-
parseTokenResponse
protected TokenResponse parseTokenResponse(org.mule.runtime.http.api.domain.message.response.HttpResponse response, String tokenUrl, boolean retrieveRefreshToken)
-
updateOAuthContextAfterTokenResponse
protected void updateOAuthContextAfterTokenResponse(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext defaultUserState)
-
tokenUrlExceptionHandler
protected <T> Function<Throwable,? extends T> tokenUrlExceptionHandler(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext defaultUserState)
-
resolveExpression
protected <T> T resolveExpression(String expr, Object body, org.mule.runtime.api.util.MultiMap<String,String> headers, org.mule.runtime.api.metadata.MediaType responseContentType)
-
resolveExpression
protected <T> T resolveExpression(String expr, Object body, org.mule.runtime.api.util.MultiMap<String,String> headers, org.mule.runtime.api.util.MultiMap<String,String> queryParams, org.mule.runtime.api.metadata.MediaType responseContentType)
-
invalidateContext
public void invalidateContext(String resourceOwner)
-
getListenersToNotifyInvalidation
protected List<? extends org.mule.oauth.client.api.listener.OAuthStateListener> getListenersToNotifyInvalidation(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext resourceOwnerOAuthContext)
Retrieves all the listeners that should be notified of a token invalidation event. Depending on the implementation these listeners could be the ones registered associated to the given resource owner in an explicit way and the ones that were registered in a general way (without indicating the resource owner).- Parameters:
resourceOwnerOAuthContext- context- Returns:
- the listeners to be notified of the token invalidation event.
-
getContextForResourceOwner
public org.mule.oauth.client.api.state.ResourceOwnerOAuthContext getContextForResourceOwner(String resourceOwnerId)
Retrieves the oauth context for a particular user. If there's no state for that user a new state is retrieve so never returns null.- Parameters:
resourceOwnerId- id of the user.- Returns:
- oauth state
-
updateResourceOwnerOAuthContext
protected void updateResourceOwnerOAuthContext(org.mule.oauth.client.api.state.ResourceOwnerOAuthContext resourceOwnerOAuthContext)
Updates the resource owner oauth context information- Parameters:
resourceOwnerOAuthContext-
-
getLockProvider
protected org.mule.runtime.api.lock.LockFactory getLockProvider()
-
doAddListener
protected void doAddListener(org.mule.oauth.client.api.listener.OAuthStateListener listener)
-
doRemoveListener
protected void doRemoveListener(org.mule.oauth.client.api.listener.OAuthStateListener listener)
-
onEachListener
protected void onEachListener(Consumer<org.mule.oauth.client.api.listener.OAuthStateListener> action)
-
-