net.oauth.signature
Class OAuthSignatureMethod

java.lang.Object
  extended by net.oauth.signature.OAuthSignatureMethod
Direct Known Subclasses:
RSA_SHA1

public abstract class OAuthSignatureMethod
extends java.lang.Object

A pair of algorithms for computing and verifying an OAuth digital signature.

Static methods of this class implement a registry of signature methods. It's pre-populated with the standard OAuth algorithms. Appliations can replace them or add new ones.

Author:
John Kristian

Field Summary
static java.lang.String _ACCESSOR
           
 
Constructor Summary
OAuthSignatureMethod()
           
 
Method Summary
static java.lang.String base64Encode(byte[] b)
           
static byte[] decodeBase64(java.lang.String s)
           
static boolean equals(byte[] a, byte[] b)
          Determine whether the given arrays contain the same sequence of bytes.
static boolean equals(java.lang.String x, java.lang.String y)
          Determine whether the given strings contain the same sequence of characters.
static java.lang.String getBaseString(OAuthMessage message)
           
protected  java.lang.String getConsumerSecret()
           
protected  java.lang.String getSignature(OAuthMessage message)
           
protected abstract  java.lang.String getSignature(java.lang.String baseString)
          Compute the signature for the given base string.
 java.lang.String getTokenSecret()
           
protected  void initialize(java.lang.String name, OAuthAccessor accessor)
           
protected abstract  boolean isValid(java.lang.String signature, java.lang.String baseString)
          Decide whether the signature is valid.
static OAuthSignatureMethod newMethod(java.lang.String name, OAuthAccessor accessor)
          The factory for signature methods.
static OAuthSignatureMethod newSigner(OAuthMessage message, OAuthAccessor accessor)
           
protected static java.lang.String normalizeParameters(java.util.Collection<? extends java.util.Map.Entry> parameters)
           
protected static java.lang.String normalizeUrl(java.lang.String url)
           
static void registerMethodClass(java.lang.String name, java.lang.Class clazz)
          Subsequently, newMethod(name) will attempt to instantiate the given class, with no constructor parameters.
protected  void setConsumerSecret(java.lang.String consumerSecret)
           
 void setTokenSecret(java.lang.String tokenSecret)
           
 void sign(OAuthMessage message)
          Add a signature to the message.
static void unregisterMethod(java.lang.String name)
          Subsequently, newMethod(name) will fail.
 void validate(OAuthMessage message)
          Check whether the message has a valid signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ACCESSOR

public static final java.lang.String _ACCESSOR
See Also:
Constant Field Values
Constructor Detail

OAuthSignatureMethod

public OAuthSignatureMethod()
Method Detail

sign

public void sign(OAuthMessage message)
          throws OAuthException,
                 java.io.IOException,
                 java.net.URISyntaxException
Add a signature to the message.

Throws:
java.net.URISyntaxException
java.io.IOException
OAuthException

validate

public void validate(OAuthMessage message)
              throws java.io.IOException,
                     OAuthException,
                     java.net.URISyntaxException
Check whether the message has a valid signature.

Throws:
java.net.URISyntaxException
OAuthProblemException - the signature is invalid
java.io.IOException
OAuthException

getSignature

protected java.lang.String getSignature(OAuthMessage message)
                                 throws OAuthException,
                                        java.io.IOException,
                                        java.net.URISyntaxException
Throws:
OAuthException
java.io.IOException
java.net.URISyntaxException

initialize

protected void initialize(java.lang.String name,
                          OAuthAccessor accessor)
                   throws OAuthException
Throws:
OAuthException

getSignature

protected abstract java.lang.String getSignature(java.lang.String baseString)
                                          throws OAuthException
Compute the signature for the given base string.

Throws:
OAuthException

isValid

protected abstract boolean isValid(java.lang.String signature,
                                   java.lang.String baseString)
                            throws OAuthException
Decide whether the signature is valid.

Throws:
OAuthException

getConsumerSecret

protected java.lang.String getConsumerSecret()

setConsumerSecret

protected void setConsumerSecret(java.lang.String consumerSecret)

getTokenSecret

public java.lang.String getTokenSecret()

setTokenSecret

public void setTokenSecret(java.lang.String tokenSecret)

getBaseString

public static java.lang.String getBaseString(OAuthMessage message)
                                      throws java.io.IOException,
                                             java.net.URISyntaxException
Throws:
java.io.IOException
java.net.URISyntaxException

normalizeUrl

protected static java.lang.String normalizeUrl(java.lang.String url)
                                        throws java.net.URISyntaxException
Throws:
java.net.URISyntaxException

normalizeParameters

protected static java.lang.String normalizeParameters(java.util.Collection<? extends java.util.Map.Entry> parameters)
                                               throws java.io.IOException
Throws:
java.io.IOException

equals

public static boolean equals(java.lang.String x,
                             java.lang.String y)
Determine whether the given strings contain the same sequence of characters. The implementation discourages a timing attack.


equals

public static boolean equals(byte[] a,
                             byte[] b)
Determine whether the given arrays contain the same sequence of bytes. The implementation discourages a timing attack.


decodeBase64

public static byte[] decodeBase64(java.lang.String s)

base64Encode

public static java.lang.String base64Encode(byte[] b)

newSigner

public static OAuthSignatureMethod newSigner(OAuthMessage message,
                                             OAuthAccessor accessor)
                                      throws java.io.IOException,
                                             OAuthException
Throws:
java.io.IOException
OAuthException

newMethod

public static OAuthSignatureMethod newMethod(java.lang.String name,
                                             OAuthAccessor accessor)
                                      throws OAuthException
The factory for signature methods.

Throws:
OAuthException

registerMethodClass

public static void registerMethodClass(java.lang.String name,
                                       java.lang.Class clazz)
Subsequently, newMethod(name) will attempt to instantiate the given class, with no constructor parameters.


unregisterMethod

public static void unregisterMethod(java.lang.String name)
Subsequently, newMethod(name) will fail.



Copyright © 2009. All Rights Reserved.