fix for build #102

This commit is contained in:
fmartelli 2015-09-04 15:45:48 +02:00
parent 9df1a3997b
commit 7e104410fb
2 changed files with 7 additions and 10 deletions

View File

@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
public class AccessToken implements Serializable {
@ -36,14 +35,14 @@ public class AccessToken implements Serializable {
private final String token;
private final Date expiration;
private final long expiration;
AccessToken(
final String subscriptionId, final String serviceManagementUrl, final AuthenticationResult authres) {
this.subscriptionId = subscriptionId;
this.serviceManagementUrl = serviceManagementUrl;
this.token = authres.getAccessToken();
this.expiration = authres.getExpiresOnDate();
this.expiration = authres.getExpiresOn();
}
public Configuration getConfiguration() throws AzureCloudException {
@ -61,14 +60,11 @@ public class AccessToken implements Serializable {
}
public Date getExpirationDate() {
return expiration;
return new Date(expiration);
}
public boolean isExpiring() {
final Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MINUTE, 5);
return expiration.before(cal.getTime());
return expiration < System.currentTimeMillis();
}
@Override

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -119,7 +120,7 @@ public class TokenCache {
synchronized (tsafe) {
AccessToken token = readTokenFile();
if (token == null || token.isExpiring()) {
LOGGER.log(Level.INFO, "Token is no longer valid ({0})",
LOGGER.log(Level.INFO, "Token is no longer valid ({0})",
token == null ? null : token.getExpirationDate());
clear();
token = getNewToken();
@ -221,7 +222,7 @@ public class TokenCache {
LOGGER.log(Level.INFO,
"Authentication result:\n\taccess token: {0}\n\tExpires On: {1}",
new Object[] { authres.getAccessToken(), authres.getExpiresOnDate() });
new Object[] { authres.getAccessToken(), new Date(authres.getExpiresOn()) });
final AccessToken token = new AccessToken(subscriptionId, serviceManagementURL, authres);
writeTokenFile(token);