Skip to content

Commit

Permalink
Azure#622: Shutdown ADAL auth executors
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Mar 31, 2016
1 parent 49a0c03 commit 711df83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.microsoft.rest.credentials.TokenCredentials;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
Expand Down Expand Up @@ -103,14 +104,17 @@ 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(),
new ClientCredential(this.getClientId(), this.getSecret()),
null).get();
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
} finally {
executor.shutdown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
Expand Down Expand Up @@ -146,14 +147,17 @@ 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(),
this.getClientId(),
null, null).get();
} catch (Exception e) {
throw new IOException(e.getMessage(), e);
} finally {
executor.shutdown();
}
}
}

0 comments on commit 711df83

Please sign in to comment.