Class OAuthUtils
java.lang.Object
org.apache.oltu.oauth2.common.utils.OAuthUtils
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]decodeClientAuthenticationHeader(String authenticationHeader) Decodes the Basic Authentication header into a username and passworddecodeForm(String form) Parse a form-urlencoded document.decodeOAuthHeader(String header) static Stringstatic StringencodeAuthorizationBearerHeader(Map<String, Object> entries) Construct an Authorization Bearer headerstatic StringencodeOAuthHeader(Map<String, Object> entries) Construct a WWW-Authenticate headerstatic StringencodeScopes(Set<String> s) static StringTranslates parameters intoapplication/x-www-form-urlencodedStringstatic StringgetAuthHeaderField(String authHeader) static StringgetAuthzMethod(String header) static OAuthProblemExceptionhandleBadContentTypeException(String expectedContentType) static OAuthProblemExceptionhandleMissingParameters(Set<String> missingParams) Creates OAuthProblemException that contains set of missing oauth parametersstatic OAuthProblemExceptionhandleNotAllowedParametersOAuthException(List<String> notAllowedParams) static OAuthProblemExceptionhandleOAuthProblemException(String message) Creates invalid_request exception with given messagestatic booleanhasContentType(String requestContentType, String requiredContentType) static booleanhasEmptyValues(String[] array) static <T> TinstantiateClass(Class<T> clazz) static <T> TinstantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) static booleanstatic booleanisFormEncoded(String contentType) Return true if the given Content-Type header means FORM_ENCODED.static booleanisMultipart(HttpServletRequest request) static StringpercentEncode(Iterable values) Construct a invalid input: '&'-separated list of the given values, percentEncoded.static Stringstatic StringRead data from Input Stream and save it as a String.static StringtoString(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 Details
-
AUTH_SCHEME
- See Also:
-
MULTIPART
- See Also:
-
-
Constructor Details
-
OAuthUtils
public OAuthUtils()
-
-
Method Details
-
format
public static String format(Collection<? extends Map.Entry<String, Object>> parameters, String encoding) Translates parameters intoapplication/x-www-form-urlencodedString- Parameters:
parameters- parameters to encodeencoding- The name of a supported character encoding.- Returns:
- Translated string
-
saveStreamAsString
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
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
Creates invalid_request exception with given message- Parameters:
message- error message- Returns:
- OAuthException
-
handleMissingParameters
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
-
handleNotAllowedParametersOAuthException
public static OAuthProblemException handleNotAllowedParametersOAuthException(List<String> notAllowedParams) -
decodeForm
Parse a form-urlencoded document. -
isFormEncoded
Return true if the given Content-Type header means FORM_ENCODED. -
decodePercent
-
percentEncode
Construct a invalid input: '&'-separated list of the given values, percentEncoded. -
percentEncode
-
instantiateClass
- Throws:
OAuthSystemException
-
instantiateClassWithParameters
public static <T> T instantiateClassWithParameters(Class<T> clazz, Class<?>[] paramsTypes, Object[] paramValues) throws OAuthSystemException - Throws:
OAuthSystemException
-
getAuthHeaderField
-
decodeOAuthHeader
-
decodeClientAuthenticationHeader
Decodes the Basic Authentication header into a username and password -
encodeOAuthHeader
Construct a WWW-Authenticate header -
encodeAuthorizationBearerHeader
Construct an Authorization Bearer header -
isEmpty
-
hasEmptyValues
-
getAuthzMethod
-
decodeScopes
-
encodeScopes
-
isMultipart
-
hasContentType
-