Class OAuthHandler
- java.lang.Object
-
- org.apache.synapse.endpoints.auth.oauth.OAuthHandler
-
- All Implemented Interfaces:
AuthHandler
- Direct Known Subclasses:
AuthorizationCodeHandler
,ClientCredentialsHandler
,PasswordCredentialsHandler
public abstract class OAuthHandler extends Object implements AuthHandler
This abstract class is to be used by OAuth handlers This class checks validity of tokens, request for tokens and add tokens to in-memory cache
-
-
Field Summary
Fields Modifier and Type Field Description protected int
connectionRequestTimeout
protected int
connectionTimeout
protected int
socketTimeout
-
Constructor Summary
Constructors Modifier Constructor Description protected
OAuthHandler(String tokenApiUrl, String clientId, String clientSecret, String authMode, int connectionTimeout, int connectionRequestTimeout, int socketTimeout)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract String
buildTokenRequestPayload(MessageContext messageContext)
Return the request payload relevant to the OAuth handler.String
getAuthMode()
String
getAuthType()
Gets the auth handler type of the instance.String
getClientId()
Return the client id relevant to the OAuth Handler.String
getClientSecret()
Return the client secret relevant to the OAuth Handler.int
getConnectionRequestTimeout()
int
getConnectionTimeout()
Map<String,String>
getCustomHeadersMap()
protected String
getEncodedCredentials(MessageContext messageContext)
Return the base 64 encoded clientId:clientSecret relevant to the OAuth handler.protected abstract int
getHash(MessageContext messageContext)
protected String
getRequestParametersAsString(MessageContext messageContext)
Return the request parameters as a string.Map<String,String>
getRequestParametersMap()
protected Map<String,String>
getResolvedCustomHeadersMap(Map<String,String> customHeadersMap, MessageContext messageContext)
This method will resolve the dynamic expressions used in custom headers and return a new map containing the resolved expressions.int
getSocketTimeout()
String
getTokenUrl()
Return the token server url relevant to the OAuth handler.void
removeTokenFromCache(MessageContext messageContext)
Method to remove the token from the cache when the token is invalid.void
removeTokensFromCache()
Method to remove the token from the cache when the endpoint is destroyed.org.apache.axiom.om.OMElement
serializeOAuthConfiguration(org.apache.axiom.om.OMFactory omFactory)
This method returns an OMElement containing the OAuth configuration.protected abstract org.apache.axiom.om.OMElement
serializeSpecificOAuthConfigs(org.apache.axiom.om.OMFactory omFactory)
Return the OMElement for OAuth configuration relevant to the OAuth handler.void
setAuthHeader(MessageContext messageContext)
This method will set the Authorization header with the relevant auth token.void
setCustomHeaders(Map<String,String> customHeadersMap)
void
setRequestParameters(Map<String,String> requestParameters)
Method to set the request parameter map.
-
-
-
Method Detail
-
getAuthType
public String getAuthType()
Description copied from interface:AuthHandler
Gets the auth handler type of the instance.- Specified by:
getAuthType
in interfaceAuthHandler
-
setAuthHeader
public void setAuthHeader(MessageContext messageContext) throws AuthException
Description copied from interface:AuthHandler
This method will set the Authorization header with the relevant auth token.- Specified by:
setAuthHeader
in interfaceAuthHandler
- Parameters:
messageContext
- Message context to which the token needs to be set- Throws:
AuthException
- In the event of errors when generating new token
-
removeTokenFromCache
public void removeTokenFromCache(MessageContext messageContext) throws AuthException
Method to remove the token from the cache when the token is invalid.- Throws:
AuthException
-
removeTokensFromCache
public void removeTokensFromCache()
Method to remove the token from the cache when the endpoint is destroyed.
-
getTokenUrl
public String getTokenUrl()
Return the token server url relevant to the OAuth handler.- Returns:
- String Token server url
-
getClientId
public String getClientId()
Return the client id relevant to the OAuth Handler.- Returns:
- String client id
-
getClientSecret
public String getClientSecret()
Return the client secret relevant to the OAuth Handler.- Returns:
- String client secret
-
buildTokenRequestPayload
protected abstract String buildTokenRequestPayload(MessageContext messageContext) throws AuthException
Return the request payload relevant to the OAuth handler.- Returns:
- String payload
- Throws:
AuthException
-
serializeSpecificOAuthConfigs
protected abstract org.apache.axiom.om.OMElement serializeSpecificOAuthConfigs(org.apache.axiom.om.OMFactory omFactory)
Return the OMElement for OAuth configuration relevant to the OAuth handler.- Returns:
- OMElement OAuth configuration
-
serializeOAuthConfiguration
public org.apache.axiom.om.OMElement serializeOAuthConfiguration(org.apache.axiom.om.OMFactory omFactory)
This method returns an OMElement containing the OAuth configuration.- Returns:
- OMElement OAuth configuration
-
getEncodedCredentials
protected String getEncodedCredentials(MessageContext messageContext) throws AuthException
Return the base 64 encoded clientId:clientSecret relevant to the OAuth handler.- Parameters:
messageContext
- Message Context of the request which will be used to resolve dynamic expressions- Returns:
- String payload
- Throws:
AuthException
- In the event of errors when resolving the dynamic expressions
-
getRequestParametersAsString
protected String getRequestParametersAsString(MessageContext messageContext) throws AuthException
Return the request parameters as a string.- Returns:
- String request parameters
- Throws:
AuthException
-
setRequestParameters
public void setRequestParameters(Map<String,String> requestParameters)
Method to set the request parameter map.- Parameters:
requestParameters
- the request parameter map
-
getAuthMode
public String getAuthMode()
-
getResolvedCustomHeadersMap
protected Map<String,String> getResolvedCustomHeadersMap(Map<String,String> customHeadersMap, MessageContext messageContext) throws AuthException
This method will resolve the dynamic expressions used in custom headers and return a new map containing the resolved expressions.- Parameters:
customHeadersMap
- The custom headers mapmessageContext
- Message Context of the request which will be used to resolve dynamic expressions- Returns:
- Map
Resolved custom headers - Throws:
AuthException
-
getConnectionTimeout
public int getConnectionTimeout()
-
getConnectionRequestTimeout
public int getConnectionRequestTimeout()
-
getSocketTimeout
public int getSocketTimeout()
-
getHash
protected abstract int getHash(MessageContext messageContext) throws AuthException
- Throws:
AuthException
-
-