Package net.oauth.signature
Class OAuthSignatureMethod
- java.lang.Object
-
- net.oauth.signature.OAuthSignatureMethod
-
- Direct Known Subclasses:
RSA_SHA1
public abstract class OAuthSignatureMethod extends 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
-
-
Constructor Summary
Constructors Constructor Description OAuthSignatureMethod()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static String
base64Encode(byte[] b)
static byte[]
decodeBase64(String s)
static boolean
equals(byte[] a, byte[] b)
Determine whether the given arrays contain the same sequence of bytes.static boolean
equals(String x, String y)
Determine whether the given strings contain the same sequence of characters.static String
getBaseString(OAuthMessage message)
protected String
getConsumerSecret()
protected abstract String
getSignature(String baseString)
Compute the signature for the given base string.protected String
getSignature(OAuthMessage message)
String
getTokenSecret()
protected void
initialize(String name, OAuthAccessor accessor)
protected abstract boolean
isValid(String signature, String baseString)
Decide whether the signature is valid.static OAuthSignatureMethod
newMethod(String name, OAuthAccessor accessor)
The factory for signature methods.static OAuthSignatureMethod
newSigner(OAuthMessage message, OAuthAccessor accessor)
protected static String
normalizeParameters(Collection<? extends Map.Entry<String,String>> parameters)
protected static String
normalizeUrl(String url)
static void
registerMethodClass(String name, Class<?> clazz)
Subsequently, newMethod(name) will attempt to instantiate the given class, with no constructor parameters.protected void
setConsumerSecret(String consumerSecret)
void
setTokenSecret(String tokenSecret)
void
sign(OAuthMessage message)
Add a signature to the message.static void
unregisterMethod(String name)
Subsequently, newMethod(name) will fail.void
validate(OAuthMessage message)
Check whether the message has a valid signature.
-
-
-
Field Detail
-
_ACCESSOR
public static final String _ACCESSOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
base64Encode
public static String base64Encode(byte[] b)
-
decodeBase64
public static byte[] decodeBase64(String s)
-
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.
-
equals
public static boolean equals(String x, String y)
Determine whether the given strings contain the same sequence of characters. The implementation discourages a timing attack.
-
getBaseString
public static String getBaseString(OAuthMessage message) throws IOException, URISyntaxException
- Throws:
IOException
URISyntaxException
-
newMethod
public static OAuthSignatureMethod newMethod(String name, OAuthAccessor accessor) throws OAuthException
The factory for signature methods.- Throws:
OAuthException
-
newSigner
public static OAuthSignatureMethod newSigner(OAuthMessage message, OAuthAccessor accessor) throws IOException, OAuthException
- Throws:
IOException
OAuthException
-
normalizeParameters
protected static String normalizeParameters(Collection<? extends Map.Entry<String,String>> parameters) throws IOException
- Throws:
IOException
-
normalizeUrl
protected static String normalizeUrl(String url) throws URISyntaxException
- Throws:
URISyntaxException
-
registerMethodClass
public static void registerMethodClass(String name, Class<?> clazz)
Subsequently, newMethod(name) will attempt to instantiate the given class, with no constructor parameters.
-
unregisterMethod
public static void unregisterMethod(String name)
Subsequently, newMethod(name) will fail.
-
getConsumerSecret
protected String getConsumerSecret()
-
getSignature
protected String getSignature(OAuthMessage message) throws OAuthException, IOException, URISyntaxException
-
getSignature
protected abstract String getSignature(String baseString) throws OAuthException
Compute the signature for the given base string.- Throws:
OAuthException
-
getTokenSecret
public String getTokenSecret()
-
initialize
protected void initialize(String name, OAuthAccessor accessor) throws OAuthException
- Throws:
OAuthException
-
isValid
protected abstract boolean isValid(String signature, String baseString) throws OAuthException
Decide whether the signature is valid.- Throws:
OAuthException
-
setConsumerSecret
protected void setConsumerSecret(String consumerSecret)
-
setTokenSecret
public void setTokenSecret(String tokenSecret)
-
sign
public void sign(OAuthMessage message) throws OAuthException, IOException, URISyntaxException
Add a signature to the message.
-
validate
public void validate(OAuthMessage message) throws IOException, OAuthException, URISyntaxException
Check whether the message has a valid signature.- Throws:
URISyntaxException
OAuthProblemException
- the signature is invalidIOException
OAuthException
-
-