com.dyuproject.oauth
Class Signature

java.lang.Object
  extended by com.dyuproject.oauth.Signature

public abstract class Signature
extends Object

Signature - for signing and verification of oauth requests

Author:
David Yu
Date created:
May 30, 2009

Nested Class Summary
static interface Signature.Listener
          Listens on the encoding of every single oauth and request parameter.
 
Field Summary
static Signature HMACSHA1
          "HMAC-SHA1" signature.
static Signature PLAINTEXT
          "PLAINTEXT" signature.
static String[] REQUIRED_OAUTH_HEADERS_TO_SIGN
          The default headers to sign - Constants.OAUTH_CONSUMER_KEY, Constants.OAUTH_NONCE, Constants.OAUTH_TIMESTAMP, Constants.OAUTH_SIGNATURE_METHOD
 
Constructor Summary
Signature()
           
 
Method Summary
static String decode(String value)
          Decodes the string via the oauth encoding Constants.ENCODING; The spec is RFC3986 which is basically a standard for URI encoding.
static String encode(String value)
          Encodes the string via the oauth encoding Constants.ENCODING; The spec is RFC3986 which is basically a standard for URI encoding.
abstract  void generate(UrlEncodedParameterMap params, String consumerSecret, Token token, String httpMethod, Signature.Listener listener, StringBuilder oauthBuffer, StringBuilder requestBuffer)
          Generates a signature and puts it on the params based from the given params, consumer secret and token.
static Signature get(String method)
          Gets a signature based from the given method name.
static String getBase(UrlEncodedParameterMap params, String method)
          Gets the computed base string to be signed - based from the given params and http method.
protected  String getBaseAndPutDefaults(UrlEncodedParameterMap params, String httpMethod, Signature.Listener listener, StringBuilder oauthBuffer, StringBuilder requestBuffer)
           
static String getKey(String consumerSecret, String secret)
          Gets the computed key based from the given secret keys.
static String getMacSignature(String secretKey, String base, String algorithm)
          Gets the computed mac signature from the given secret key, base string and algorithm.
abstract  String getMethod()
          Gets the method name of the signature used.
 int hashCode()
           
static void register(Signature sig)
          Registers a custom signature.
abstract  String sign(String consumerSecret, String tokenSecret, String base)
          Returns the signature string based from the given consumer secret, token secret and base string.
abstract  boolean verify(String consumerSecret, String tokenSecret, String method, UrlEncodedParameterMap params)
          Verifies whether the params and method generates the same exact signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REQUIRED_OAUTH_HEADERS_TO_SIGN

public static final String[] REQUIRED_OAUTH_HEADERS_TO_SIGN
The default headers to sign - Constants.OAUTH_CONSUMER_KEY, Constants.OAUTH_NONCE, Constants.OAUTH_TIMESTAMP, Constants.OAUTH_SIGNATURE_METHOD


PLAINTEXT

public static final Signature PLAINTEXT
"PLAINTEXT" signature.


HMACSHA1

public static final Signature HMACSHA1
"HMAC-SHA1" signature.

Constructor Detail

Signature

public Signature()
Method Detail

register

public static void register(Signature sig)
Registers a custom signature.


get

public static Signature get(String method)
Gets a signature based from the given method name.


encode

public static String encode(String value)
Encodes the string via the oauth encoding Constants.ENCODING; The spec is RFC3986 which is basically a standard for URI encoding.


decode

public static String decode(String value)
Decodes the string via the oauth encoding Constants.ENCODING; The spec is RFC3986 which is basically a standard for URI encoding.


getKey

public static String getKey(String consumerSecret,
                            String secret)
Gets the computed key based from the given secret keys.


getBase

public static String getBase(UrlEncodedParameterMap params,
                             String method)
Gets the computed base string to be signed - based from the given params and http method.


getMacSignature

public static String getMacSignature(String secretKey,
                                     String base,
                                     String algorithm)
Gets the computed mac signature from the given secret key, base string and algorithm.


getMethod

public abstract String getMethod()
Gets the method name of the signature used.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

getBaseAndPutDefaults

protected final String getBaseAndPutDefaults(UrlEncodedParameterMap params,
                                             String httpMethod,
                                             Signature.Listener listener,
                                             StringBuilder oauthBuffer,
                                             StringBuilder requestBuffer)

sign

public abstract String sign(String consumerSecret,
                            String tokenSecret,
                            String base)
Returns the signature string based from the given consumer secret, token secret and base string.


verify

public abstract boolean verify(String consumerSecret,
                               String tokenSecret,
                               String method,
                               UrlEncodedParameterMap params)
Verifies whether the params and method generates the same exact signature.


generate

public abstract void generate(UrlEncodedParameterMap params,
                              String consumerSecret,
                              Token token,
                              String httpMethod,
                              Signature.Listener listener,
                              StringBuilder oauthBuffer,
                              StringBuilder requestBuffer)
Generates a signature and puts it on the params based from the given params, consumer secret and token. The given listener will be able to listen on the encoding of each parameter.



Copyright © 2008-2013. All Rights Reserved.