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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OAuthHandler(String tokenApiUrl, String clientId, String clientSecret, String authMode)
-
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.Map<String,String>
getCustomHeadersMap()
protected String
getEncodedCredentials(MessageContext messageContext)
Return the base 64 encoded clientId:clientSecret relevant to the OAuth handler.protected String
getRequestParametersAsString(MessageContext messageContext)
Return the request parameters as a string.Map<String,String>
getRequestParametersMap()
String
getTokenUrl()
Return the token server url relevant to the OAuth handler.void
removeTokenFromCache()
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()
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()
-
-