Class OAuthUtils

  • public final class OAuthUtils
    extends Object
    Common OAuth Utils class.

    Some methods based on the Utils class from OAuth V1.0a library available at:

    • Constructor Detail

      • OAuthUtils

        public OAuthUtils()
    • Method Detail

      • format

        public static String format​(Collection<? extends Map.Entry<String,​Object>> parameters,
                                    String encoding)
        Translates parameters into application/x-www-form-urlencoded String
        parameters - parameters to encode
        encoding - The name of a supported character encoding.
        Translated string
      • saveStreamAsString

        public static String saveStreamAsString​(InputStream is)
                                         throws IOException
        Read data from Input Stream and save it as a String.
        is - InputStream to be read
        String that was read from the stream
      • toString

        public static String toString​(InputStream is,
                                      String defaultCharset)
                               throws IOException
        Get the entity content as a String, using the provided default character set if none is found in the entity. If defaultCharset is null, the default "UTF-8" is used.
        is - input stream to be saved as string
        defaultCharset - character set to be applied if none found in the entity
        the entity content as a String
        IllegalArgumentException - if entity is null or if content length > Integer.MAX_VALUE
        IOException - if an error occurs reading the input stream
      • handleOAuthProblemException

        public static OAuthProblemException handleOAuthProblemException​(String message)
        Creates invalid_request exception with given message
        message - error message
      • handleMissingParameters

        public static OAuthProblemException handleMissingParameters​(Set<String> missingParams)
        Creates OAuthProblemException that contains set of missing oauth parameters
        missingParams - missing oauth parameters
        OAuthProblemException with user friendly message about missing oauth parameters
      • handleNotAllowedParametersOAuthException

        public static OAuthProblemException handleNotAllowedParametersOAuthException​(List<String> notAllowedParams)
      • decodeForm

        public static Map<String,​Object> decodeForm​(String form)
        Parse a form-urlencoded document.
      • isFormEncoded

        public static boolean isFormEncoded​(String contentType)
        Return true if the given Content-Type header means FORM_ENCODED.
      • decodePercent

        public static String decodePercent​(String s)
      • percentEncode

        public static String percentEncode​(Iterable values)
        Construct a &-separated list of the given values, percentEncoded.
      • percentEncode

        public static String percentEncode​(String s)
      • getAuthHeaderField

        public static String getAuthHeaderField​(String authHeader)
      • decodeClientAuthenticationHeader

        public static String[] decodeClientAuthenticationHeader​(String authenticationHeader)
        Decodes the Basic Authentication header into a username and password
        authenticationHeader - String containing the encoded header value. e.g. "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
        a String if the header could be decoded into a non null username and password or null.
      • encodeOAuthHeader

        public static String encodeOAuthHeader​(Map<String,​Object> entries)
        Construct a WWW-Authenticate header
      • encodeAuthorizationBearerHeader

        public static String encodeAuthorizationBearerHeader​(Map<String,​Object> entries)
        Construct an Authorization Bearer header
      • isEmpty

        public static boolean isEmpty​(String value)
      • hasEmptyValues

        public static boolean hasEmptyValues​(String[] array)
      • getAuthzMethod

        public static String getAuthzMethod​(String header)
      • hasContentType

        public static boolean hasContentType​(String requestContentType,
                                             String requiredContentType)