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 Stringbase64Encode(byte[] b)static byte[]decodeBase64(String s)static booleanequals(byte[] a, byte[] b)Determine whether the given arrays contain the same sequence of bytes.static booleanequals(String x, String y)Determine whether the given strings contain the same sequence of characters.static StringgetBaseString(OAuthMessage message)protected StringgetConsumerSecret()protected abstract StringgetSignature(String baseString)Compute the signature for the given base string.protected StringgetSignature(OAuthMessage message)StringgetTokenSecret()protected voidinitialize(String name, OAuthAccessor accessor)protected abstract booleanisValid(String signature, String baseString)Decide whether the signature is valid.static OAuthSignatureMethodnewMethod(String name, OAuthAccessor accessor)The factory for signature methods.static OAuthSignatureMethodnewSigner(OAuthMessage message, OAuthAccessor accessor)protected static StringnormalizeParameters(Collection<? extends Map.Entry<String,String>> parameters)protected static StringnormalizeUrl(String url)static voidregisterMethodClass(String name, Class<?> clazz)Subsequently, newMethod(name) will attempt to instantiate the given class, with no constructor parameters.protected voidsetConsumerSecret(String consumerSecret)voidsetTokenSecret(String tokenSecret)voidsign(OAuthMessage message)Add a signature to the message.static voidunregisterMethod(String name)Subsequently, newMethod(name) will fail.voidvalidate(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:
IOExceptionURISyntaxException
-
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:
IOExceptionOAuthException
-
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:
URISyntaxExceptionOAuthProblemException- the signature is invalidIOExceptionOAuthException
-
-