From f2cce2ea887d99fad596fdaf17ba926a2b0ad358 Mon Sep 17 00:00:00 2001 From: Matt Mitchell Date: Tue, 13 Sep 2016 10:44:08 -0700 Subject: [PATCH] A couple fixes Update SDK to 0.9.4 Token expiration was incorrectly calculated (API is named a bit oddly) --- pom.xml | 2 +- .../azure/AzureManagementServiceDelegate.java | 2 +- .../azure/util/AccessToken.java | 7 ++++++- .../azure/util/TokenCache.java | 11 +++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index f78b6ff..eb88eb5 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ UTF-8 UTF-8 2.5.4 - 0.8.0 + 0.9.4 diff --git a/src/main/java/com/microsoftopentechnologies/azure/AzureManagementServiceDelegate.java b/src/main/java/com/microsoftopentechnologies/azure/AzureManagementServiceDelegate.java index 11dc260..b795f89 100644 --- a/src/main/java/com/microsoftopentechnologies/azure/AzureManagementServiceDelegate.java +++ b/src/main/java/com/microsoftopentechnologies/azure/AzureManagementServiceDelegate.java @@ -189,7 +189,7 @@ public class AzureManagementServiceDelegate { } // Deployment .... - properties.setMode(DeploymentMode.INCREMENTAL); + properties.setMode(DeploymentMode.Incremental); properties.setTemplate(tmp.toString()); final String deploymentName = String.valueOf(ts); diff --git a/src/main/java/com/microsoftopentechnologies/azure/util/AccessToken.java b/src/main/java/com/microsoftopentechnologies/azure/util/AccessToken.java index 0b236f8..dbb3392 100644 --- a/src/main/java/com/microsoftopentechnologies/azure/util/AccessToken.java +++ b/src/main/java/com/microsoftopentechnologies/azure/util/AccessToken.java @@ -42,7 +42,8 @@ public class AccessToken implements Serializable { this.subscriptionId = subscriptionId; this.serviceManagementUrl = serviceManagementUrl; this.token = authres.getAccessToken(); - this.expiration = authres.getExpiresOn(); + // In the 0.9.4 version of the SDK, expiresOn is the number of ms till expire + this.expiration = System.currentTimeMillis() + authres.getExpiresOn(); } public Configuration getConfiguration() throws AzureCloudException { @@ -67,6 +68,10 @@ public class AccessToken implements Serializable { return expiration < System.currentTimeMillis(); } + public String getToken() { + return token; + } + @Override public String toString() { return token; diff --git a/src/main/java/com/microsoftopentechnologies/azure/util/TokenCache.java b/src/main/java/com/microsoftopentechnologies/azure/util/TokenCache.java index d223906..33cca83 100644 --- a/src/main/java/com/microsoftopentechnologies/azure/util/TokenCache.java +++ b/src/main/java/com/microsoftopentechnologies/azure/util/TokenCache.java @@ -189,8 +189,6 @@ public class TokenCache { private AccessToken getNewToken() throws AzureCloudException { LOGGER.log(Level.INFO, "Retrieve new access token"); - // reset configuration instance: renew token - Configuration.setInstance(null); final ExecutorService service = Executors.newFixedThreadPool(1); @@ -220,11 +218,12 @@ public class TokenCache { throw new AzureCloudException("Authentication result was null"); } - LOGGER.log(Level.INFO, - "Authentication result:\n\taccess token: {0}\n\tExpires On: {1}", - new Object[] { authres.getAccessToken(), new Date(authres.getExpiresOn()) }); - final AccessToken token = new AccessToken(subscriptionId, serviceManagementURL, authres); + + LOGGER.log(Level.INFO, + "Authentication result:\n\taccess token: {0}\n\tExpires In: {1}{2}", + new Object[] { token.getToken(), token.getExpirationDate()}); + writeTokenFile(token); return token; }