Skip to content

Commit e4ba498

Browse files
committed
Merge pull request Azure#908 from jianghaolu/master
Azure#622: Shutdown ADAL auth executors
2 parents 5a6f236 + 711df83 commit e4ba498

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.microsoft.rest.credentials.TokenCredentials;
1414

1515
import java.io.IOException;
16+
import java.util.concurrent.ExecutorService;
1617
import java.util.concurrent.Executors;
1718

1819
/**
@@ -103,14 +104,17 @@ public void refreshToken() throws IOException {
103104

104105
private void acquireAccessToken() throws IOException {
105106
String authorityUrl = this.getEnvironment().getAuthenticationEndpoint() + this.getDomain();
106-
AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor());
107+
ExecutorService executor = Executors.newSingleThreadExecutor();
108+
AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor);
107109
try {
108110
authenticationResult = context.acquireToken(
109111
this.getEnvironment().getTokenAudience(),
110112
new ClientCredential(this.getClientId(), this.getSecret()),
111113
null).get();
112114
} catch (Exception e) {
113115
throw new IOException(e.getMessage(), e);
116+
} finally {
117+
executor.shutdown();
114118
}
115119
}
116120
}

azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.io.IOException;
1515
import java.util.Date;
16+
import java.util.concurrent.ExecutorService;
1617
import java.util.concurrent.Executors;
1718

1819
/**
@@ -146,14 +147,17 @@ private void acquireAccessToken() throws IOException {
146147

147148
private void acquireAccessTokenFromRefreshToken() throws IOException {
148149
String authorityUrl = this.getEnvironment().getAuthenticationEndpoint() + this.getDomain();
149-
AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor());
150+
ExecutorService executor = Executors.newSingleThreadExecutor();
151+
AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor);
150152
try {
151153
authenticationResult = context.acquireTokenByRefreshToken(
152154
authenticationResult.getRefreshToken(),
153155
this.getClientId(),
154156
null, null).get();
155157
} catch (Exception e) {
156158
throw new IOException(e.getMessage(), e);
159+
} finally {
160+
executor.shutdown();
157161
}
158162
}
159163
}

0 commit comments

Comments
 (0)