public final class ExtensionsOAuthUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_REFRESH_ATTEMPTS
Default max number of times that a refresh token and retry workflow should be executed for a component failing with
AccessTokenExpiredException |
| Modifier and Type | Method and Description |
|---|---|
static Map<Field,String> |
getCallbackValuesExtractors(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel providerModel)
Traverses the
providerModel looking for the Java fields annotated with OAuthCallbackValue. |
static OAuthConnectionProviderWrapper |
getOAuthConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider provider)
Unwraps a given connection provider if necessary to get a
OAuthConnectionProviderWrapper. |
static OAuthConnectionProviderWrapper |
getOAuthConnectionProvider(ExecutionContextAdapter operationContext) |
static <T extends org.mule.runtime.extension.api.connectivity.oauth.OAuthState> |
getOAuthStateSetter(Object target,
Class<T> stateType,
org.mule.runtime.extension.api.connectivity.oauth.OAuthGrantType grantType)
|
static boolean |
refreshTokenIfNecessary(org.mule.runtime.api.connection.ConnectionProvider connectionProvider,
Throwable e)
Performs a token refresh if the given
ConnectionProvider knows how do it and the given Throwable signals a
refresh is needed by either being an AccessTokenExpiredException or by one appearing in the chain of causes. |
static boolean |
refreshTokenIfNecessary(ExecutionContextAdapter<org.mule.runtime.api.meta.model.operation.OperationModel> operationContext,
Throwable e)
Performs a token refresh if the underlying
ConnectionProvider of the given ExecutionContextAdapter knows how
do it and the given Throwable signals a refresh is needed by either being an AccessTokenExpiredException or
by one appearing in the chain of causes. |
static org.mule.runtime.extension.api.connectivity.oauth.AuthorizationCodeState |
toAuthorizationCodeState(AuthorizationCodeConfig config,
ResourceOwnerOAuthContext context) |
static ClientCredentialsLocation |
toCredentialsLocation(org.mule.runtime.extension.api.security.CredentialsPlacement placement) |
static <C> void |
updateOAuthParameters(Object target,
Map<Field,String> callbackValues,
ResourceOwnerOAuthContext context)
Updates the
target state with the values from the given context. |
static <C> org.mule.runtime.api.connection.ConnectionValidationResult |
validateOAuthConnection(org.mule.runtime.api.connection.ConnectionProvider<C> connectionProvider,
C connection,
ResourceOwnerOAuthContext context)
Invokes
ConnectionProvider.validate(Object) on the connectionProvider only if the given context
returns a non null value for the ResourceOwnerOAuthContext.getAccessToken() method. |
static <C> org.mule.runtime.api.connection.ConnectionValidationResult |
validateOAuthConnection(OAuthConnectionProviderWrapper<C> oAuthConnectionProviderWrapper,
C connection,
ResourceOwnerOAuthContext context)
Invokes
ConnectionProvider.validate(Object) on the connectionProvider only if the given context
returns a non null value for the ResourceOwnerOAuthContext.getAccessToken() method. |
static <T> T |
withRefreshToken(org.mule.runtime.api.connection.ConnectionProvider connectionProvider,
CheckedSupplier<T> supplier)
Gets the value provided by a
CheckedSupplier, if that fails and the reason is that a token refresh is needed, the
refresh is performed and the supplier is prompted to provide the value one more time. |
static <T> T |
withRefreshToken(Supplier<org.mule.runtime.api.connection.ConnectionProvider> connectionProviderSupplier,
CheckedSupplier<T> supplier)
Gets the value provided by a
CheckedSupplier, if that fails and the reason is that a token refresh is needed, the
refresh is performed up to MAX_REFRESH_ATTEMPTS times and the supplier is prompted to provide the value again. |
static <T> T |
withRefreshToken(Supplier<org.mule.runtime.api.connection.ConnectionProvider> connectionProviderSupplier,
CheckedSupplier<T> supplier,
int maxRefreshAttempts)
Gets the value provided by a
CheckedSupplier, if that fails and the reason is that a token refresh is needed, the
refresh is performed up to maxRefreshAttempts times and the supplier is prompted to provide the value again. |
public static final int MAX_REFRESH_ATTEMPTS
AccessTokenExpiredExceptionpublic static org.mule.runtime.extension.api.connectivity.oauth.AuthorizationCodeState toAuthorizationCodeState(AuthorizationCodeConfig config, ResourceOwnerOAuthContext context)
public static ClientCredentialsLocation toCredentialsLocation(org.mule.runtime.extension.api.security.CredentialsPlacement placement)
public static OAuthConnectionProviderWrapper getOAuthConnectionProvider(ExecutionContextAdapter operationContext)
public static OAuthConnectionProviderWrapper getOAuthConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider provider)
OAuthConnectionProviderWrapper.provider - connection provider to unwrappublic static Map<Field,String> getCallbackValuesExtractors(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel providerModel)
providerModel looking for the Java fields annotated with OAuthCallbackValue. Then returns a
Map in which the keys are the Field objects and the values are the expressions to be evaluated to obtain the
valuesproviderModel - an OAuth enabled ConnectionProviderModelMap with the value with fields and expressionspublic static <T extends org.mule.runtime.extension.api.connectivity.oauth.OAuthState> FieldSetter<Object,Object> getOAuthStateSetter(Object target, Class<T> stateType, org.mule.runtime.extension.api.connectivity.oauth.OAuthGrantType grantType)
T - the generic type of the OAuthStatetarget - the target in which the value is to be setstateType - the field's exact OAuthState typegrantType - the OAuthGrantType associated to the stateTypepublic static <C> void updateOAuthParameters(Object target, Map<Field,String> callbackValues, ResourceOwnerOAuthContext context)
target state with the values from the given context. This includes not only the provider's inner
OAuthState but also the fields annotated with OAuthCallbackValueC - the generic type of the connections generated by the connectionProvidertarget - an OAuth enabled targetcallbackValues - a Map with OAuthCallbackValue annotated fields and the expressions to be
evaluated for each.context - a ResourceOwnerOAuthContextpublic static <C> org.mule.runtime.api.connection.ConnectionValidationResult validateOAuthConnection(OAuthConnectionProviderWrapper<C> oAuthConnectionProviderWrapper, C connection, ResourceOwnerOAuthContext context)
ConnectionProvider.validate(Object) on the connectionProvider only if the given context
returns a non null value for the ResourceOwnerOAuthContext.getAccessToken() method. A failure result is
returned otherwiseC - the connection's generic typeoAuthConnectionProviderWrapper - a OAuthConnectionProviderWrapperconnection - a connection objectcontext - a ResourceOwnerOAuthContextConnectionValidationResultpublic static <C> org.mule.runtime.api.connection.ConnectionValidationResult validateOAuthConnection(org.mule.runtime.api.connection.ConnectionProvider<C> connectionProvider,
C connection,
ResourceOwnerOAuthContext context)
ConnectionProvider.validate(Object) on the connectionProvider only if the given context
returns a non null value for the ResourceOwnerOAuthContext.getAccessToken() method. A failure result is
returned otherwiseC - the connection's generic typeconnectionProvider - a ConnectionProviderconnection - a connection objectcontext - a ResourceOwnerOAuthContextConnectionValidationResultpublic static <T> T withRefreshToken(Supplier<org.mule.runtime.api.connection.ConnectionProvider> connectionProviderSupplier, CheckedSupplier<T> supplier) throws Exception
CheckedSupplier, if that fails and the reason is that a token refresh is needed, the
refresh is performed up to MAX_REFRESH_ATTEMPTS times and the supplier is prompted to provide the value again.T - the type of the value to be providedconnectionProviderSupplier - a supplier of the connection provider that created a connection used in the given supplier
to provide a value.supplier - a supplier that depends on an oauth based connection to provide a value.Exceptionpublic static <T> T withRefreshToken(Supplier<org.mule.runtime.api.connection.ConnectionProvider> connectionProviderSupplier, CheckedSupplier<T> supplier, int maxRefreshAttempts) throws Exception
CheckedSupplier, if that fails and the reason is that a token refresh is needed, the
refresh is performed up to maxRefreshAttempts times and the supplier is prompted to provide the value again.
If maxRefreshAttempts is lower than 1, no refresh or retries are performed
T - the type of the value to be providedconnectionProviderSupplier - a supplier of the connection provider that created a connection used in the given supplier
to provide a value.supplier - a supplier that depends on an oauth based connection to provide a value.maxRefreshAttempts - max amount of times that the refresh token operation should be executed and the operation
retried.Exceptionpublic static <T> T withRefreshToken(org.mule.runtime.api.connection.ConnectionProvider connectionProvider,
CheckedSupplier<T> supplier)
throws Exception
CheckedSupplier, if that fails and the reason is that a token refresh is needed, the
refresh is performed and the supplier is prompted to provide the value one more time.T - the type of the value to be providedconnectionProvider - the provider that created a connection used in the supplier to provide a value.supplier - a supplier that depends on an oauth based connection to provide a value.Exceptionpublic static boolean refreshTokenIfNecessary(ExecutionContextAdapter<org.mule.runtime.api.meta.model.operation.OperationModel> operationContext, Throwable e)
ConnectionProvider of the given ExecutionContextAdapter knows how
do it and the given Throwable signals a refresh is needed by either being an AccessTokenExpiredException or
by one appearing in the chain of causes.operationContext - connection provider that may be able to perform a token refresh.e - throwable that may signal that a token refresh is needed.public static boolean refreshTokenIfNecessary(org.mule.runtime.api.connection.ConnectionProvider connectionProvider,
Throwable e)
ConnectionProvider knows how do it and the given Throwable signals a
refresh is needed by either being an AccessTokenExpiredException or by one appearing in the chain of causes.connectionProvider - connection provider that may be able to perform a token refresh.e - throwable that may signal that a token refresh is needed.Copyright © 2003–2024 MuleSoft, Inc.. All rights reserved.