net.smartam.leeloo.common.utils
Class OAuthUtils

java.lang.Object
  extended by net.smartam.leeloo.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/

Author:
Maciej Machulak, Lukasz Moren

Field Summary
static String AUTH_SCHEME
           
static String MULTIPART
           
 
Constructor Summary
OAuthUtils()
           
 
Method Summary
static Map<String,String> 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 encodeOAuthHeader(Map<String,String> entries)
          Construct a WWW-Authenticate or Authorization header with the OAuth challenge/credentials
static String encodeScopes(Set<String> s)
           
static String format(Collection<? extends Map.Entry<String,String>> parameters, String encoding)
          Translates parameters into application/x-www-form-urlencoded String
static String getAuthHeaderField(String authHeader)
           
static String getAuthzMethod(String header)
           
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 Object instantiateClass(Class clazz)
           
static Object instantiateClassWithParameters(Class 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(javax.servlet.http.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

OAuthUtils

public OAuthUtils()
Method Detail

format

public static String format(Collection<? extends Map.Entry<String,String>> 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

saveStreamAsString

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

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

handleNotAllowedParametersOAuthException

public static OAuthProblemException handleNotAllowedParametersOAuthException(List<String> notAllowedParams)

decodeForm

public static Map<String,String> 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)

instantiateClass

public static Object instantiateClass(Class clazz)
                               throws OAuthSystemException
Throws:
OAuthSystemException

instantiateClassWithParameters

public static Object instantiateClassWithParameters(Class clazz,
                                                    Class[] paramsTypes,
                                                    Object[] paramValues)
                                             throws OAuthSystemException
Throws:
OAuthSystemException

getAuthHeaderField

public static String getAuthHeaderField(String authHeader)

decodeOAuthHeader

public static Map<String,String> decodeOAuthHeader(String header)

encodeOAuthHeader

public static String encodeOAuthHeader(Map<String,String> entries)
Construct a WWW-Authenticate or Authorization header with the OAuth challenge/credentials


isEmpty

public static boolean isEmpty(String value)

hasEmptyValues

public static boolean hasEmptyValues(String[] array)

getAuthzMethod

public static String getAuthzMethod(String header)

decodeScopes

public static Set<String> decodeScopes(String s)

encodeScopes

public static String encodeScopes(Set<String> s)

isMultipart

public static boolean isMultipart(javax.servlet.http.HttpServletRequest request)

hasContentType

public static boolean hasContentType(String requestContentType,
                                     String requiredContentType)


Copyright © 2010. All Rights Reserved.