Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #28 from christav/fix-token-manager-385

Fixed token manager cache poisoning bug
  • Loading branch information...
commit 3125ece7d0e2a25b690612f18129cf45b74daafc 2 parents ba4b981 + 8ffec2f
@christav christav authored
View
24 ...-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java
@@ -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();
}
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.