org.mule.security.oauth
Interface OAuth2Manager<C extends OAuth2Adapter>

Type Parameters:
C - Actual connector object that represents a connection
All Superinterfaces:
HttpCallbackAdapter, NamedObject, OnNoTokenPolicyAware, ProcessAdapter<OAuth2Adapter>
All Known Implementing Classes:
BaseOAuth2Manager

public interface OAuth2Manager<C extends OAuth2Adapter>
extends HttpCallbackAdapter, ProcessAdapter<OAuth2Adapter>, OnNoTokenPolicyAware, NamedObject

Wrapper around org.mule.api.annotations.oauth.OAuth2 annotated class that will infuse it with access token management capabilities.

It can receive a PoolingProfile which is a configuration object used to define the OAuth access tokens pooling parameters.


Method Summary
 C 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
 C createAdapter(String verifier)
          Create a new adapter using the specified verifier and insert it into the pool.
 void destroyAccessToken(String userId, C connector)
          Destroy an access token
 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
 org.apache.commons.pool.KeyedPoolableObjectFactory<String,OAuth2Adapter> getAccessTokenPoolFactory()
          Retrieves accessTokenPoolFactory
 String getDefaultAccessTokenId()
           
 C getDefaultUnauthorizedConnector()
          Retrieve default unauthorized connector
 MuleContext getMuleContext()
          Returns the mule context
<T> ProcessTemplate<T,OAuth2Adapter>
getProcessTemplate()
           
 void hasBeenAuthorized(OAuth2Adapter adapter)
          Validates that there's an access token for the given adapter.
 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.
 void releaseAccessToken(String userId, C connector)
          Return an access token to the pool
 MuleEvent restoreAuthorizationEvent(String eventId)
          Recovers a MuleEvent from the object store.
 void storeAuthorizationEvent(MuleEvent event)
          This method is expected to receive the MuleEvent corresponding to the execution of an OAuth2 authorize processor.
 
Methods inherited from interface org.mule.security.oauth.callback.HttpCallbackAdapter
getAsync, getConnector, getDomain, getLocalPort, getPath, getRemotePort, setAsync, setConnector, setDomain, setLocalPort, setPath, setRemotePort
 
Methods inherited from interface org.mule.security.oauth.OnNoTokenPolicyAware
getOnNoTokenPolicy, setOnNoTokenPolicy
 
Methods inherited from interface org.mule.api.NamedObject
getName
 

Method Detail

createAdapter

C createAdapter(String verifier)
                                      throws Exception
Create a new adapter using the specified verifier and insert it into the pool. This adapter will be already initialized and started

Parameters:
verifier - OAuth verifier
Returns:
A newly created connector
Throws:
Exception - If the access token cannot be retrieved

acquireAccessToken

C acquireAccessToken(String accessTokenId)
                                           throws Exception
Borrow an access token from the pool

Parameters:
accessTokenId - User identification used to borrow the access token
Returns:
An existing authorized connector
Throws:
Exception - If the access token cannot be retrieved

releaseAccessToken

void releaseAccessToken(String userId,
                        C connector)
                        throws Exception
Return an access token to the pool

Parameters:
userId - User identification used to borrow the access token
connector - Authorized connector to be returned to the pool
Throws:
Exception - If the access token cannot be returned

destroyAccessToken

void destroyAccessToken(String userId,
                        C connector)
                        throws Exception
Destroy an access token

Parameters:
userId - User identification used to borrow the access token
connector - Authorized connector to the destroyed
Throws:
Exception - If the access token could not be destroyed.

getDefaultUnauthorizedConnector

C getDefaultUnauthorizedConnector()
Retrieve default unauthorized connector


getAccessTokenPoolFactory

org.apache.commons.pool.KeyedPoolableObjectFactory<String,OAuth2Adapter> getAccessTokenPoolFactory()
Retrieves accessTokenPoolFactory


buildAuthorizeUrl

String buildAuthorizeUrl(Map<String,String> extraParameters,
                         String authorizationUrl,
                         String redirectUri)
Generates the full URL of an authorization endpoint including query params

Parameters:
extraParameters - a map with non-standard query-param value pairs
authorizationUrl - the url of the authorization endpoint per OAuth specification
redirectUri - the uri of the redirection endpoint
Returns:
the authorization URL as a String

refreshAccessToken

void refreshAccessToken(OAuth2Adapter adapter,
                        String accessTokenId)
                        throws org.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException
if refresh token is available, then it makes an http call to refresh the access token. All newly obtained tokens are set into the adapter. After the token has been refreshed, org.mule.security.oauth.OAuth2Manager.postAuth(OAuth2Adapter, String) is invoked

Parameters:
adapter - the connector's adapter
accessTokenId - the id of the token you're trying to refresh
Throws:
org.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException
IllegalArgumentException - if accessTokenId is null

fetchAccessToken

void fetchAccessToken(OAuth2Adapter adapter,
                      String redirectUri)
                      throws org.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException
Makes an http call to the adapter's accessTokenUrl and extracts the access token, which is then set into the adapter

Parameters:
adapter - the connector's adapter
redirectUri - the redirection URI
Throws:
org.mule.common.security.oauth.exception.UnableToAcquireAccessTokenException

getMuleContext

MuleContext getMuleContext()
Returns the mule context


hasBeenAuthorized

void hasBeenAuthorized(OAuth2Adapter adapter)
                       throws org.mule.common.security.oauth.exception.NotAuthorizedException
Validates that there's an access token for the given adapter.

Parameters:
adapter - the adapter which authorization you want to test
Throws:
org.mule.common.security.oauth.exception.NotAuthorizedException - if no access token available for this adapter

storeAuthorizationEvent

void storeAuthorizationEvent(MuleEvent event)
                             throws Exception
This method is expected to receive the MuleEvent corresponding to the execution of an OAuth2 authorize processor. The event will be persisted in this manager's object store following these rules:

Parameters:
event - a mule event
Throws:
Exception

restoreAuthorizationEvent

MuleEvent restoreAuthorizationEvent(String eventId)
                                    throws ObjectStoreException,
                                           ObjectDoesNotExistException
Recovers a MuleEvent from the object store. The key that is fetched comes from replacing the given eventId into the template on org.mule.security.oauth.OAuthProperties.AUTHORIZATION_EVENT_KEY_TEMPLATE

Parameters:
eventId - the id of the event to be restored
Returns:
a MuleEvent
Throws:
ObjectStoreException - if there was an error accessing the object store
ObjectDoesNotExistException - if there's no entry for the event id

getProcessTemplate

<T> ProcessTemplate<T,OAuth2Adapter> getProcessTemplate()
Specified by:
getProcessTemplate in interface ProcessAdapter<OAuth2Adapter>

getDefaultAccessTokenId

String getDefaultAccessTokenId()

postAuth

void postAuth(OAuth2Adapter adapter,
              String accessTokenId)
              throws Exception
Calls the 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 thrown

Parameters:
adapter - the connector adapter
accessTokenId - the id of the accessToken to be used
Throws:
Exception


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.