Class OAuthUtils


  • public class OAuthUtils
    extends Object
    Helper class to build OAuth handlers using the synapse configuration of the endpoints.
    • Constructor Detail

      • OAuthUtils

        public OAuthUtils()
    • Method Detail

      • getSpecificOAuthHandler

        public static OAuthHandler getSpecificOAuthHandler​(org.apache.axiom.om.OMElement oauthElement)
        This method will return an OAuthHandler instance depending on the oauth configs.
        Parameters:
        oauthElement - Element containing OAuth configs
        Returns:
        OAuthHandler object
      • getChildValue

        public static String getChildValue​(org.apache.axiom.om.OMElement parentElement,
                                           String childName)
        Method to get the value inside a child element.
        Parameters:
        parentElement - Parent OMElement
        childName - name of the child
        Returns:
        String containing the value of the child
      • getRandomOAuthHandlerID

        public static String getRandomOAuthHandlerID()
        Method to generate a random id for each OAuth handler.
        Returns:
        String containing random id
      • retryOnOAuthFailure

        public static boolean retryOnOAuthFailure​(OAuthConfiguredHTTPEndpoint httpEndpoint,
                                                  MessageContext synapseInMsgCtx,
                                                  MessageContext synapseOutMsgCtx)
        Method to check whether retry is needed.
        Parameters:
        httpEndpoint - OAuth Configured HTTP Endpoint related to the message context
        synapseInMsgCtx - MessageContext that has been received
        synapseOutMsgCtx - Corresponding outgoing Synapse MessageContext for the above received MessageContext
        Returns:
        true if the call needs to be retried
      • resolveExpression

        public static String resolveExpression​(String value,
                                               MessageContext messageContext)
                                        throws AuthException
        This method evaluate the value as an expression or return the value.
        Parameters:
        value - String parameter value
        messageContext - MessageContext of the request
        Returns:
        evaluated String value or the passed value itself
        Throws:
        AuthException
      • append401HTTPSC

        public static void append401HTTPSC​(MessageContext synCtx)
        Method to append 401 status code to NON_ERROR_HTTP_STATUS_CODES property.
        Parameters:
        synCtx - MessageContext of the request
      • createOMElementWithValue

        public static org.apache.axiom.om.OMElement createOMElementWithValue​(org.apache.axiom.om.OMFactory omFactory,
                                                                             String elementName,
                                                                             String elementValue)
        This method returns an OMElement containing the elementValue encapsulated by the elementName.
        Parameters:
        elementName - Name of the OMElement
        elementValue - Value of the OMElement
        Returns:
        OMElement containing the value encapsulated by the elementName
      • createOMRequestParams

        public static org.apache.axiom.om.OMElement createOMRequestParams​(org.apache.axiom.om.OMFactory omFactory,
                                                                          Map<String,​String> requestParametersMap)
        Create an OMElement for request parameter map.
        Parameters:
        requestParametersMap - input parameter map.
        Returns:
        OMElement of parameter map.