public abstract class BaseOAuth2Manager<C extends OAuth2Adapter> extends DefaultHttpCallbackAdapter implements MuleContextAware, Initialisable, Capabilities, Startable, Stoppable, Disposable, OAuth2Manager<OAuth2Adapter>, NameableObject
Modifier and Type | Field and Description |
---|---|
static String |
ACCESS_TOKEN_URL |
static String |
AUTHORIZATION_URL |
protected FlowConstruct |
flowConstruct
Flow Construct
|
protected MuleContext |
muleContext
muleContext
|
PHASE_NAME
PHASE_NAME
PHASE_NAME
PHASE_NAME
Constructor and Description |
---|
BaseOAuth2Manager() |
Modifier and Type | Method and Description |
---|---|
OAuth2Adapter |
acquireAccessToken(String accessTokenId)
Borrow an access token from the pool
|
String |
buildAuthorizeUrl(Map<String,String> extraParameters,
String authorizationUrl,
String redirectUri)
Generates the full URL of an authorization endpoint including query params
|
OAuth2Adapter |
createAdapter(MuleEvent event,
String verifier)
Create a new adapter using the specified verifier and insert it into the pool.
|
protected abstract org.apache.commons.pool.KeyedPoolableObjectFactory<String,OAuth2Adapter> |
createPoolFactory(OAuth2Manager<OAuth2Adapter> oauthManager,
ObjectStore<Serializable> objectStore)
Returns the concrete instance of
KeyedPoolableObjectFactory that's going to be
in charge of creating the objects in the pool |
void |
destroyAccessToken(String userId,
OAuth2Adapter connector)
Destroy an access token
|
void |
dispose()
if
Disposable , then
defaultUnauthorizedConnector
is disposed |
void |
fetchAccessToken(OAuth2Adapter adapter,
String redirectUri)
Makes an http call to the adapter's accessTokenUrl and extracts the access
token, which is then set into the adapter
|
protected abstract void |
fetchCallbackParameters(OAuth2Adapter adapter,
String response)
Extracts any custom parameters from the OAuth response and sets them
accordingly on the adapter
|
ObjectStore<Serializable> |
getAccessTokenObjectStore()
Retrieves accessTokenObjectStore
|
org.apache.commons.pool.KeyedPoolableObjectFactory<String,OAuth2Adapter> |
getAccessTokenPoolFactory()
Retrieves accessTokenPoolFactory
|
String |
getApplicationName()
Retrieves applicationName
|
String |
getConsumerKey() |
String |
getConsumerSecret() |
String |
getDefaultAccessTokenId() |
OAuth2Adapter |
getDefaultUnauthorizedConnector()
Retrieves defaultUnauthorizedConnector
|
FlowConstruct |
getFlowConstruct()
Retrieves flowConstruct
|
protected abstract Logger |
getLogger() |
MuleContext |
getMuleContext()
Returns the mule context
|
String |
getName()
Gets the name of the object
|
OnNoTokenPolicy |
getOnNoTokenPolicy() |
<T> ProcessTemplate<T,OAuth2Adapter> |
getProcessTemplate() |
String |
getScope()
Retrieves scope
|
void |
hasBeenAuthorized(OAuth2Adapter adapter)
Validates that there's an access token for the given adapter.
|
void |
initialise()
Method used to perform any initialisation work.
|
protected abstract OAuth2Adapter |
instantiateAdapter()
Creates a concrete instance of the OAuth2Adapter that corresponds with this
OAuthManager
|
boolean |
isCapableOf(ModuleCapability capability)
Returns true if this module implements such capability
|
void |
postAuth(OAuth2Adapter adapter,
String accessTokenId)
Calls the
org.mule.security.oauth.OAuth2Connector.postAuth() on the
adapter. |
void |
refreshAccessToken(OAuth2Adapter adapter,
String accessTokenId)
if refresh token is available, then it makes an http call to refresh the
access token.
|
protected Set<Class<? extends Exception>> |
refreshAccessTokenOn() |
void |
releaseAccessToken(String userId,
OAuth2Adapter connector)
Return an access token to the pool
|
MuleEvent |
restoreAuthorizationEvent(String eventId)
Recovers a MuleEvent from the object store.
|
void |
setAccessTokenObjectStore(ObjectStore<Serializable> value)
Sets accessTokenObjectStore
|
protected void |
setAccessTokenPool(org.apache.commons.pool.impl.GenericKeyedObjectPool<String,OAuth2Adapter> accessTokenPool) |
void |
setAccessTokenUrl(String value)
Sets accessTokenUrl
|
void |
setApplicationName(String value)
Sets applicationName
|
void |
setAuthorizationUrl(String value)
Sets authorizationUrl
|
void |
setConsumerKey(String value)
Sets consumerKey
|
void |
setConsumerSecret(String value)
Sets consumerSecret
|
protected abstract void |
setCustomProperties(OAuth2Adapter adapter)
Populates the adapter with custom properties not accessible from the base
interface.
|
void |
setDefaultAccessTokenId(String defaultAccessTokenId) |
protected void |
setDefaultUnauthorizedConnector(OAuth2Adapter defaultUnauthorizedConnector) |
void |
setFlowConstruct(FlowConstruct flowConstruct) |
void |
setHttpUtil(HttpUtil httpUtil) |
void |
setMuleContext(MuleContext muleContext) |
void |
setName(String name)
Sets the name of the object
|
void |
setOauthResponseParser(OAuthResponseParser oauthResponseParser) |
void |
setOnNoTokenPolicy(OnNoTokenPolicy policy) |
void |
setRefreshTokenManager(RefreshTokenManager refreshTokenManager) |
void |
setScope(String value)
Sets scope
|
void |
start()
if
Startable , then
defaultUnauthorizedConnector
is started |
void |
stop()
if
Stoppable , then
defaultUnauthorizedConnector
is stopped |
void |
storeAuthorizationEvent(MuleEvent event)
This method is expected to receive the
MuleEvent corresponding to
the execution of an OAuth2 authorize processor. |
getAsync, getConnector, getDomain, getLocalPort, getPath, getRemotePort, setAsync, setConnector, setDomain, setLocalPort, setPath, setRemotePort
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAsync, getConnector, getDomain, getLocalPort, getPath, getRemotePort, setAsync, setConnector, setDomain, setLocalPort, setPath, setRemotePort
public static final String ACCESS_TOKEN_URL
public static final String AUTHORIZATION_URL
protected MuleContext muleContext
protected FlowConstruct flowConstruct
protected abstract Logger getLogger()
protected abstract OAuth2Adapter instantiateAdapter()
OAuth2Adapter
protected abstract org.apache.commons.pool.KeyedPoolableObjectFactory<String,OAuth2Adapter> createPoolFactory(OAuth2Manager<OAuth2Adapter> oauthManager, ObjectStore<Serializable> objectStore)
KeyedPoolableObjectFactory
that's going to be
in charge of creating the objects in the pooloauthManager
- the OAuthManager that will manage the created objectsobjectStore
- an instance of ObjectStore
that
will be responsible for storing instances of
OAuthState
KeyedPoolableObjectFactory
protected abstract void setCustomProperties(OAuth2Adapter adapter)
adapter
- an instance of OAuth2Adapter
protected abstract void fetchCallbackParameters(OAuth2Adapter adapter, String response)
adapter
- the adapter on which the custom parameters will be set onresponse
- the response obatined from the OAuth providerpublic final void initialise() throws InitialisationException
Initialisable
InitialisationException
should be thrown,
causing the Mule instance to shutdown. If the error is recoverable, say by
retrying to connect, a RecoverableException
should be thrown.
There is no guarantee that by throwing a Recoverable exception that the Mule
instance will not shut down.initialise
in interface Initialisable
initialise
in class DefaultHttpCallbackAdapter
InitialisationException
- if a fatal error occurs causing the Mule instance to shutdownRecoverableException
- if an error occurs that can be recovered frompublic final void start() throws MuleException
Startable
, then
defaultUnauthorizedConnector
is startedstart
in interface Startable
MuleException
public final void stop() throws MuleException
Stoppable
, then
defaultUnauthorizedConnector
is stoppedstop
in interface Stoppable
MuleException
public final void dispose()
Disposable
, then
defaultUnauthorizedConnector
is disposeddispose
in interface Disposable
public final OAuth2Adapter createAdapter(MuleEvent event, String verifier) throws Exception
createAdapter
in interface OAuth2Manager<OAuth2Adapter>
verifier
- OAuth verifierException
- If the access token cannot be retrievedpublic final OAuth2Adapter acquireAccessToken(String accessTokenId) throws Exception
acquireAccessToken
in interface OAuth2Manager<OAuth2Adapter>
accessTokenId
- User identification used to borrow the access tokenException
- If the access token cannot be retrievedpublic final void releaseAccessToken(String userId, OAuth2Adapter connector) throws Exception
releaseAccessToken
in interface OAuth2Manager<OAuth2Adapter>
userId
- User identification used to borrow the access tokenconnector
- Authorized connector to be returned to the poolException
- If the access token cannot be returnedpublic final void destroyAccessToken(String userId, OAuth2Adapter connector) throws Exception
destroyAccessToken
in interface OAuth2Manager<OAuth2Adapter>
userId
- User identification used to borrow the access tokenconnector
- Authorized connector to the destroyedException
- If the access token could not be destroyed.public final String buildAuthorizeUrl(Map<String,String> extraParameters, String authorizationUrl, String redirectUri)
buildAuthorizeUrl
in interface OAuth2Manager<OAuth2Adapter>
extraParameters
- a map with non-standard query-param value pairsauthorizationUrl
- the url of the authorization endpoint per OAuth
specificationredirectUri
- the uri of the redirection endpointpublic final void fetchAccessToken(OAuth2Adapter adapter, String redirectUri) throws org.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException
fetchAccessToken
in interface OAuth2Manager<OAuth2Adapter>
adapter
- the connector's adapterredirectUri
- the redirection URIorg.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException
public final void hasBeenAuthorized(OAuth2Adapter adapter) throws org.mule.common.security.oauth.exception.NotAuthorizedException
hasBeenAuthorized
in interface OAuth2Manager<OAuth2Adapter>
adapter
- the adapter which authorization you want to testorg.mule.common.security.oauth.exception.NotAuthorizedException
- if no access token available for this adapterpublic final void refreshAccessToken(OAuth2Adapter adapter, String accessTokenId) throws org.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException
org.mule.security.oauth.OAuth2Manager.postAuth(OAuth2Adapter, String)
is
invokedrefreshAccessToken
in interface OAuth2Manager<OAuth2Adapter>
adapter
- the connector's adapteraccessTokenId
- the id of the token you're trying to refreshorg.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException
public void storeAuthorizationEvent(MuleEvent event) throws Exception
MuleEvent
corresponding to
the execution of an OAuth2 authorize processor. The event will be persisted in
this manager's object store following these rules:
String
that is then set as payload. Failure to
do this will result in exceptionSerializable
then an exception
will be thrown.org.mule.security.oauth.OAuthProperties.AUTHORIZATION_EVENT_KEY_TEMPLATE
storeAuthorizationEvent
in interface OAuth2Manager<OAuth2Adapter>
event
- a mule eventException
public MuleEvent restoreAuthorizationEvent(String eventId) throws ObjectStoreException, ObjectDoesNotExistException
org.mule.security.oauth.OAuthProperties.AUTHORIZATION_EVENT_KEY_TEMPLATE
restoreAuthorizationEvent
in interface OAuth2Manager<OAuth2Adapter>
eventId
- the id of the event to be restoredMuleEvent
ObjectStoreException
- if there was an error accessing the object storeObjectDoesNotExistException
- if there's no entry for the event idpublic void postAuth(OAuth2Adapter adapter, String accessTokenId) throws Exception
org.mule.security.oauth.OAuth2Connector.postAuth()
on the
adapter. If it fails due to access token expiration and accessTokenId is not
null, then the token is refresh and the operation is re-attempted. If token
refreshment fails or if accessTokenId is null, then the original exception is
thrownpostAuth
in interface OAuth2Manager<OAuth2Adapter>
adapter
- the connector adapteraccessTokenId
- the id of the accessToken to be usedException
public final boolean isCapableOf(ModuleCapability capability)
isCapableOf
in interface Capabilities
capability
- The capability to test forpublic <T> ProcessTemplate<T,OAuth2Adapter> getProcessTemplate()
getProcessTemplate
in interface ProcessAdapter<OAuth2Adapter>
getProcessTemplate
in interface OAuth2Manager<OAuth2Adapter>
public OAuth2Adapter getDefaultUnauthorizedConnector()
getDefaultUnauthorizedConnector
in interface OAuth2Manager<OAuth2Adapter>
public void setApplicationName(String value)
value
- Value to setpublic String getApplicationName()
public void setScope(String value)
value
- Value to setpublic String getScope()
public final MuleContext getMuleContext()
getMuleContext
in interface OAuth2Manager<OAuth2Adapter>
public final void setMuleContext(MuleContext muleContext)
setMuleContext
in interface MuleContextAware
public FlowConstruct getFlowConstruct()
public void setFlowConstruct(FlowConstruct flowConstruct)
public ObjectStore<Serializable> getAccessTokenObjectStore()
public void setAccessTokenObjectStore(ObjectStore<Serializable> value)
value
- Value to setpublic org.apache.commons.pool.KeyedPoolableObjectFactory<String,OAuth2Adapter> getAccessTokenPoolFactory()
getAccessTokenPoolFactory
in interface OAuth2Manager<OAuth2Adapter>
public void setHttpUtil(HttpUtil httpUtil)
public void setOauthResponseParser(OAuthResponseParser oauthResponseParser)
public void setAuthorizationUrl(String value)
value
- Value to setpublic void setAccessTokenUrl(String value)
value
- Value to setpublic void setConsumerKey(String value)
value
- Value to setpublic void setConsumerSecret(String value)
value
- Value to setprotected void setDefaultUnauthorizedConnector(OAuth2Adapter defaultUnauthorizedConnector)
public String getConsumerKey()
public String getConsumerSecret()
public String getName()
NamedObject
getName
in interface NamedObject
public void setName(String name)
NameableObject
setName
in interface NameableObject
name
- the name of the objectpublic OnNoTokenPolicy getOnNoTokenPolicy()
getOnNoTokenPolicy
in interface OnNoTokenPolicyAware
OnNoTokenPolicy
that specifies the behavior to take when token is not setpublic void setOnNoTokenPolicy(OnNoTokenPolicy policy)
setOnNoTokenPolicy
in interface OnNoTokenPolicyAware
public String getDefaultAccessTokenId()
getDefaultAccessTokenId
in interface OAuth2Manager<OAuth2Adapter>
public void setDefaultAccessTokenId(String defaultAccessTokenId)
public void setRefreshTokenManager(RefreshTokenManager refreshTokenManager)
protected void setAccessTokenPool(org.apache.commons.pool.impl.GenericKeyedObjectPool<String,OAuth2Adapter> accessTokenPool)
Copyright © 2003–2016 MuleSoft, Inc.. All rights reserved.