Skip to content

Commit

Permalink
Merge pull request #547 from christav/dev
Browse files Browse the repository at this point in the history
Fixed token manager cache poisoning bug
  • Loading branch information
Chris Tavares committed Dec 13, 2012
2 parents ba4b981 + 3125ece commit 26b12f8
Showing 1 changed file with 9 additions and 15 deletions.
Expand Up @@ -89,22 +89,16 @@ public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory,
*/
public String getAccessToken() throws ServiceException, URISyntaxException {
Date now = dateFactory.getDate();
OAuthTokenResponse oAuth2TokenResponse = null;
if (this.activeToken == null || now.after(this.activeToken.getExpiresUtc())) {
OAuthTokenResponse oAuth2TokenResponse = contract.getAccessToken(acsBaseUri, clientId, clientSecret, scope);
Date expiresUtc = new Date(now.getTime() + oAuth2TokenResponse.getExpiresIn() * Timer.ONE_SECOND / 2);

if (this.activeToken == null) {
this.activeToken = new ActiveToken();
}
else if (now.before(this.activeToken.getExpiresUtc())) {
return this.activeToken.getAccessToken();
}

oAuth2TokenResponse = contract.getAccessToken(acsBaseUri, clientId, clientSecret, scope);
Date expiresUtc = new Date(now.getTime() + oAuth2TokenResponse.getExpiresIn() * Timer.ONE_SECOND / 2);
ActiveToken newToken = new ActiveToken();
newToken.setAccessToken(oAuth2TokenResponse.getAccessToken());
newToken.setExpiresUtc(expiresUtc);

this.activeToken.setAccessToken(oAuth2TokenResponse.getAccessToken());
this.activeToken.setExpiresUtc(expiresUtc);

return oAuth2TokenResponse.getAccessToken();
this.activeToken = newToken;
}
return this.activeToken.getAccessToken();
}

}

0 comments on commit 26b12f8

Please sign in to comment.