public final class ExtensionsOAuthUtils extends Object
| 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 <C,T extends org.mule.runtime.extension.api.connectivity.oauth.OAuthState> |
getOAuthStateSetter(org.mule.runtime.api.connection.ConnectionProvider<C> connectionProvider,
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(org.mule.runtime.api.connection.ConnectionProvider<C> connectionProvider,
Map<Field,String> callbackValues,
ResourceOwnerOAuthContext context)
Updates the
connectionProvider 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 <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. |
public 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 <C,T extends org.mule.runtime.extension.api.connectivity.oauth.OAuthState> FieldSetter<org.mule.runtime.api.connection.ConnectionProvider<C>,T> getOAuthStateSetter(org.mule.runtime.api.connection.ConnectionProvider<C> connectionProvider, Class<T> stateType, org.mule.runtime.extension.api.connectivity.oauth.OAuthGrantType grantType)
C - the generic type of the connections generated by the delegateT - the generic type of the OAuthStateconnectionProvider - the ConnectionProvider in which the value is to be setstateType - the field's exact OAuthState typegrantType - the OAuthGrantType associated to the stateTypepublic static <C> void updateOAuthParameters(org.mule.runtime.api.connection.ConnectionProvider<C> connectionProvider,
Map<Field,String> callbackValues,
ResourceOwnerOAuthContext context)
connectionProvider 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 connectionProviderconnectionProvider - an OAuth enabled ConnectionProvidercallbackValues - 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(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(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–2022 MuleSoft, Inc.. All rights reserved.