This project has retired. For details please refer to its Attic page.
OAuthUtils | Apache Oltu - OAuth 2.0
public final class

OAuthUtils

extends Object
java.lang.Object
   ↳ org.apache.oltu.oauth2.common.utils.OAuthUtils

Class Overview

Common OAuth Utils class.

Some methods based on the Utils class from OAuth V1.0a library available at: http://oauth.googlecode.com/svn/code/java/core/

Summary

Constants
String AUTH_SCHEME
String MULTIPART
Public Constructors
OAuthUtils()
Public Methods
static String[] decodeClientAuthenticationHeader(String authenticationHeader)
Decodes the Basic Authentication header into a username and password
static Map<StringObject> decodeForm(String form)
Parse a form-urlencoded document.
static Map<StringString> decodeOAuthHeader(String header)
static String decodePercent(String s)
static Set<String> decodeScopes(String s)
static String encodeAuthorizationBearerHeader(Map<StringObject> entries)
Construct an Authorization Bearer header
static String encodeOAuthHeader(Map<StringObject> entries)
Construct a WWW-Authenticate header
static String encodeScopes(Set<String> s)
static String format(Collection<? extends Entry<StringObject>> parameters, String encoding)
Translates parameters into application/x-www-form-urlencoded String
static String getAuthHeaderField(String authHeader)
static String getAuthzMethod(String header)
static OAuthProblemException handleBadContentTypeException(String expectedContentType)
static OAuthProblemException handleMissingParameters(Set<String> missingParams)
Creates OAuthProblemException that contains set of missing oauth parameters
static OAuthProblemException handleNotAllowedParametersOAuthException(List<String> notAllowedParams)
static OAuthProblemException handleOAuthProblemException(String message)
Creates invalid_request exception with given message
static boolean hasContentType(String requestContentType, String requiredContentType)
static boolean hasEmptyValues(String[] array)
static <T> T instantiateClass(Class<T> clazz)
static <T> T instantiateClassWithParameters(Class<T> clazz, Class[]<?> paramsTypes, Object[] paramValues)
static boolean isEmpty(String value)
static boolean isFormEncoded(String contentType)
Return true if the given Content-Type header means FORM_ENCODED.
static boolean isMultipart(HttpServletRequest request)
static String percentEncode(Iterable values)
Construct a &-separated list of the given values, percentEncoded.
static String percentEncode(String s)
static String saveStreamAsString(InputStream is)
Read data from Input Stream and save it as a String.
static String toString(InputStream is, String defaultCharset)
Get the entity content as a String, using the provided default character set if none is found in the entity.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String AUTH_SCHEME

Constant Value: "Bearer"

public static final String MULTIPART

Constant Value: "multipart/"

Public Constructors

public OAuthUtils ()

Public Methods

public static String[] decodeClientAuthenticationHeader (String authenticationHeader)

Decodes the Basic Authentication header into a username and password

Parameters
authenticationHeader String containing the encoded header value. e.g. "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
Returns
  • a String[] if the header could be decoded into a non null username and password or null.

public static Map<StringObject> decodeForm (String form)

Parse a form-urlencoded document.

public static Map<StringString> decodeOAuthHeader (String header)

public static String decodePercent (String s)

public static Set<String> decodeScopes (String s)

public static String encodeAuthorizationBearerHeader (Map<StringObject> entries)

Construct an Authorization Bearer header

public static String encodeOAuthHeader (Map<StringObject> entries)

Construct a WWW-Authenticate header

public static String encodeScopes (Set<String> s)

public static String format (Collection<? extends Entry<StringObject>> parameters, String encoding)

Translates parameters into application/x-www-form-urlencoded String

Parameters
parameters parameters to encode
encoding The name of a supported character encoding.
Returns
  • Translated string

public static String getAuthHeaderField (String authHeader)

public static String getAuthzMethod (String header)

public static OAuthProblemException handleBadContentTypeException (String expectedContentType)

public static OAuthProblemException handleMissingParameters (Set<String> missingParams)

Creates OAuthProblemException that contains set of missing oauth parameters

Parameters
missingParams missing oauth parameters
Returns
  • OAuthProblemException with user friendly message about missing oauth parameters

public static OAuthProblemException handleNotAllowedParametersOAuthException (List<String> notAllowedParams)

public static OAuthProblemException handleOAuthProblemException (String message)

Creates invalid_request exception with given message

Parameters
message error message
Returns
  • OAuthException

public static boolean hasContentType (String requestContentType, String requiredContentType)

public static boolean hasEmptyValues (String[] array)

public static T instantiateClass (Class<T> clazz)

public static T instantiateClassWithParameters (Class<T> clazz, Class[]<?> paramsTypes, Object[] paramValues)

public static boolean isEmpty (String value)

public static boolean isFormEncoded (String contentType)

Return true if the given Content-Type header means FORM_ENCODED.

public static boolean isMultipart (HttpServletRequest request)

public static String percentEncode (Iterable values)

Construct a &-separated list of the given values, percentEncoded.

public static String percentEncode (String s)

public static String saveStreamAsString (InputStream is)

Read data from Input Stream and save it as a String.

Parameters
is InputStream to be read
Returns
  • String that was read from the stream
Throws
IOException

public static String toString (InputStream is, String defaultCharset)

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.

Parameters
is input stream to be saved as string
defaultCharset character set to be applied if none found in the entity
Returns
  • the entity content as a String
Throws
IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
IOException if an error occurs reading the input stream