From 711df8324f56803eb0b229d47f6c36660e871fdb Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 31 Mar 2016 11:41:53 -0700 Subject: [PATCH] Azure/azure-sdk-for-java#622: Shutdown ADAL auth executors --- .../azure/credentials/ApplicationTokenCredentials.java | 6 +++++- .../microsoft/azure/credentials/UserTokenCredentials.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index a50faee9cf16..3e995fb06a08 100644 --- a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -13,6 +13,7 @@ import com.microsoft.rest.credentials.TokenCredentials; import java.io.IOException; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** @@ -103,7 +104,8 @@ public void refreshToken() throws IOException { private void acquireAccessToken() throws IOException { String authorityUrl = this.getEnvironment().getAuthenticationEndpoint() + this.getDomain(); - AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor()); + ExecutorService executor = Executors.newSingleThreadExecutor(); + AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor); try { authenticationResult = context.acquireToken( this.getEnvironment().getTokenAudience(), @@ -111,6 +113,8 @@ private void acquireAccessToken() throws IOException { null).get(); } catch (Exception e) { throw new IOException(e.getMessage(), e); + } finally { + executor.shutdown(); } } } diff --git a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index 995f32fabc4a..af02c07507b7 100644 --- a/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.util.Date; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** @@ -146,7 +147,8 @@ private void acquireAccessToken() throws IOException { private void acquireAccessTokenFromRefreshToken() throws IOException { String authorityUrl = this.getEnvironment().getAuthenticationEndpoint() + this.getDomain(); - AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor()); + ExecutorService executor = Executors.newSingleThreadExecutor(); + AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor); try { authenticationResult = context.acquireTokenByRefreshToken( authenticationResult.getRefreshToken(), @@ -154,6 +156,8 @@ private void acquireAccessTokenFromRefreshToken() throws IOException { null, null).get(); } catch (Exception e) { throw new IOException(e.getMessage(), e); + } finally { + executor.shutdown(); } } }