@@ -71,10 +71,6 @@ public class OAuthSignatureCalculator implements SignatureCalculator {
7171
7272 protected final RequestToken userAuth ;
7373
74- protected final Long testTimestamp ;
75-
76- protected final String testNonce ;
77-
7874 /**
7975 * @param consumerAuth Consumer key to use for signature calculation
8076 * @param userAuth Request/access token to use for signature calculation
@@ -83,26 +79,13 @@ public OAuthSignatureCalculator(ConsumerKey consumerAuth, RequestToken userAuth)
8379 mac = new ThreadSafeHMAC (consumerAuth , userAuth );
8480 this .consumerAuth = consumerAuth ;
8581 this .userAuth = userAuth ;
86- this .testTimestamp = 0L ;
87- this .testNonce = null ;
88- random = new Random (System .identityHashCode (this ) + System .currentTimeMillis ());
89- }
90-
91- OAuthSignatureCalculator (ConsumerKey consumerAuth , RequestToken userAuth , Long testTimestamp , String testNonce ) {
92- mac = new ThreadSafeHMAC (consumerAuth , userAuth );
93- this .consumerAuth = consumerAuth ;
94- this .userAuth = userAuth ;
95- this .testTimestamp = testTimestamp ;
96- this .testNonce = testNonce ;
9782 random = new Random (System .identityHashCode (this ) + System .currentTimeMillis ());
9883 }
9984
100-
101- //@Override // silly 1.5; doesn't allow this for interfaces
102-
85+ @ Override
10386 public void calculateAndAddSignature (Request request , RequestBuilderBase <?> requestBuilder ) {
104- String nonce = ( this . testNonce != null ) ? this . testNonce : generateNonce ();
105- long timestamp = ( this . testTimestamp > 0L ) ? this . testTimestamp : System . currentTimeMillis () / 1000L ;
87+ String nonce = generateNonce ();
88+ long timestamp = generateTimestamp () ;
10689 String signature = calculateSignature (request .getMethod (), request .getUri (), timestamp , nonce , request .getFormParams (), request .getQueryParams ());
10790 String headerValue = constructAuthHeader (signature , nonce , timestamp );
10891 requestBuilder .setHeader (HEADER_AUTHORIZATION , headerValue );
@@ -202,13 +185,17 @@ public String constructAuthHeader(String signature, String nonce, long oauthTime
202185 return sb .toString ();
203186 }
204187
205- private synchronized String generateNonce () {
188+ protected synchronized String generateNonce () {
206189 random .nextBytes (nonceBuffer );
207190 // let's use base64 encoding over hex, slightly more compact than hex or decimals
208191 return Base64 .encode (nonceBuffer );
209192// return String.valueOf(Math.abs(random.nextLong()));
210193 }
211194
195+ protected long generateTimestamp () {
196+ return System .currentTimeMillis () / 1000L ;
197+ }
198+
212199 /**
213200 * Container for parameters used for calculating OAuth signature.
214201 * About the only confusing aspect is that of whether entries are to be sorted
@@ -265,8 +252,7 @@ public String value() {
265252 return value ;
266253 }
267254
268- //@Override // silly 1.5; doesn't allow this for interfaces
269-
255+ @ Override
270256 public int compareTo (Parameter other ) {
271257 int diff = key .compareTo (other .key );
272258 if (diff == 0 ) {
0 commit comments