Skip to content

Commit

Permalink
Merge pull request Azure#908 from jianghaolu/master
Browse files Browse the repository at this point in the history
Azure#622: Shutdown ADAL auth executors
  • Loading branch information
jianghaolu committed Apr 1, 2016
2 parents 5a6f236 + 711df83 commit e4ba498
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 e4ba498

Please sign in to comment.