Class OAuthUtils
- java.lang.Object
-
- org.apache.oltu.oauth2.common.utils.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: http://oauth.googlecode.com/svn/code/java/core/
-
-
Field Summary
Fields Modifier and Type Field Description static String
AUTH_SCHEME
static String
MULTIPART
-
Constructor Summary
Constructors Constructor Description OAuthUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]
decodeClientAuthenticationHeader(String authenticationHeader)
Decodes the Basic Authentication header into a username and passwordstatic Map<String,Object>
decodeForm(String form)
Parse a form-urlencoded document.static Map<String,String>
decodeOAuthHeader(String header)
static String
decodePercent(String s)
static Set<String>
decodeScopes(String s)
static String
encodeAuthorizationBearerHeader(Map<String,Object> entries)
Construct an Authorization Bearer headerstatic String
encodeOAuthHeader(Map<String,Object> entries)
Construct a WWW-Authenticate headerstatic String
encodeScopes(Set<String> s)
static String
format(Collection<? extends Map.Entry<String,Object>> parameters, String encoding)
Translates parameters intoapplication/x-www-form-urlencoded
Stringstatic 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 parametersstatic OAuthProblemException
handleNotAllowedParametersOAuthException(List<String> notAllowedParams)
static OAuthProblemException
handleOAuthProblemException(String message)
Creates invalid_request exception with given messagestatic 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.
-
-
-
Field Detail
-
AUTH_SCHEME
public static final String AUTH_SCHEME
- See Also:
- Constant Field Values
-
MULTIPART
public static final String MULTIPART
- See Also:
- Constant Field Values
-
-
Method Detail
-
format
public static String format(Collection<? extends Map.Entry<String,Object>> parameters, String encoding)
Translates parameters intoapplication/x-www-form-urlencoded
String- Parameters:
parameters
- parameters to encodeencoding
- The name of a supported character encoding.- Returns:
- Translated string
-
saveStreamAsString
public static String saveStreamAsString(InputStream is) throws IOException
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
-
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.- Parameters:
is
- input stream to be saved as stringdefaultCharset
- 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_VALUEIOException
- if an error occurs reading the input stream
-
handleOAuthProblemException
public static OAuthProblemException handleOAuthProblemException(String message)
Creates invalid_request exception with given message- Parameters:
message
- error message- Returns:
- OAuthException
-
handleMissingParameters
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
-
handleBadContentTypeException
public static OAuthProblemException handleBadContentTypeException(String expectedContentType)
-
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.
-
percentEncode
public static String percentEncode(Iterable values)
Construct a &-separated list of the given values, percentEncoded.
-
instantiateClass
public static <T> T instantiateClass(Class<T> clazz) throws OAuthSystemException
- Throws:
OAuthSystemException
-
instantiateClassWithParameters
public static <T> T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) throws OAuthSystemException
- Throws:
OAuthSystemException
-
decodeClientAuthenticationHeader
public static String[] decodeClientAuthenticationHeader(String authenticationHeader)
Decodes the Basic Authentication header into a username and password
-
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)
-
isMultipart
public static boolean isMultipart(HttpServletRequest request)
-
-