Added bunch of javadocs and restricted some visibility.
No functional changes
This commit is contained in:
1 parent
aad8dac580
commit
59f16bfdda
35 files changed
+393
-64
No files matched your search
@@ -7,15 +7,23 @@ import org.apache.commons.codec.binary.*;
|
||||
import org.scribe.exceptions.*;
|
||||
import org.scribe.utils.*;
|
||||
|
||||
/**
|
||||
* HMAC-SHA1 implementation of {@SignatureService}
|
||||
*
|
||||
* @author Pablo Fernandez
|
||||
*
|
||||
*/
|
||||
public class HMACSha1SignatureService implements SignatureService
|
||||
{
|
||||
|
||||
private static final String EMPTY_STRING = "";
|
||||
private static final String CARRIAGE_RETURN = "\r\n";
|
||||
private static final String UTF8 = "UTF-8";
|
||||
private static final String HMAC_SHA1 = "HmacSHA1";
|
||||
private static final String METHOD = "HMAC-SHA1";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getSignature(String baseString, String apiSecret, String tokenSecret)
|
||||
{
|
||||
try
|
||||
@@ -39,6 +47,9 @@ public class HMACSha1SignatureService implements SignatureService
|
||||
return new String(Base64.encodeBase64(bytes)).replace(CARRIAGE_RETURN, EMPTY_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getSignatureMethod()
|
||||
{
|
||||
return METHOD;
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
package org.scribe.services;
|
||||
|
||||
/**
|
||||
* Signs a base string, returning the OAuth signature
|
||||
*
|
||||
* @author Pablo Fernandez
|
||||
*
|
||||
*/
|
||||
public interface SignatureService
|
||||
{
|
||||
/**
|
||||
* Returns the signature
|
||||
*
|
||||
* @param baseString url-encoded string to sign
|
||||
* @param apiSecret api secret for your app
|
||||
* @param tokenSecret token secret (empty string for the request token step)
|
||||
*
|
||||
* @return signature
|
||||
*/
|
||||
public String getSignature(String baseString, String apiSecret, String tokenSecret);
|
||||
|
||||
/**
|
||||
* Returns the signature method/algorithm
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getSignatureMethod();
|
||||
}
|
||||
@@ -1,9 +1,25 @@
|
||||
package org.scribe.services;
|
||||
|
||||
/**
|
||||
* Unix epoch timestamp generator.
|
||||
*
|
||||
* This class is useful for stubbing in tests.
|
||||
*
|
||||
* @author Pablo Fernandez
|
||||
*/
|
||||
public interface TimestampService
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns the unix epoch timestamp in seconds
|
||||
*
|
||||
* @return timestamp
|
||||
*/
|
||||
public String getTimestampInSeconds();
|
||||
|
||||
/**
|
||||
* Returns a nonce (unique value for each request)
|
||||
*
|
||||
* @return nonce
|
||||
*/
|
||||
public String getNonce();
|
||||
}
|
||||
@@ -2,22 +2,35 @@ package org.scribe.services;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Implementation of {@link TimestampService} using plain java classes.
|
||||
*
|
||||
* @author Pablo Fernandez
|
||||
*/
|
||||
public class TimestampServiceImpl implements TimestampService
|
||||
{
|
||||
|
||||
private Timer timer;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public TimestampServiceImpl()
|
||||
{
|
||||
timer = new Timer();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getNonce()
|
||||
{
|
||||
Long ts = getTs();
|
||||
return String.valueOf(ts + timer.getRandomInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public String getTimestampInSeconds()
|
||||
{
|
||||
return String.valueOf(getTs());
|
||||
@@ -33,14 +46,19 @@ public class TimestampServiceImpl implements TimestampService
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class that uses {@link System} for generating the timestamps.
|
||||
*
|
||||
* @author Pablo Fernandez
|
||||
*/
|
||||
static class Timer
|
||||
{
|
||||
public Long getMilis()
|
||||
Long getMilis()
|
||||
{
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Integer getRandomInteger()
|
||||
Integer getRandomInteger()
|
||||
{
|
||||
return new Random().nextInt();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user