Skip to content

Commit 6ddb120

Browse files
authored
Add disable instance discovery (Azure#33225)
Add method for disabling AAD instance discovery. Fixes Azure#27888 # All SDK Contribution checklist: - [x] **The pull request does not introduce [breaking changes]** - [x] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [x] **I have read the [contribution guidelines](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md).** ## [General Guidelines and Best Practices](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md#developer-guide) - [x] Title of the pull request is clear and informative. - [x] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### [Testing Guidelines](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md#building-and-unit-testing) - [x] Pull request includes test coverage for the included changes.
1 parent 27ba1ab commit 6ddb120

File tree

12 files changed

+66
-12
lines changed

12 files changed

+66
-12
lines changed

eng/versioning/external_dependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ com.microsoft.azure:azure-mgmt-resources;1.3.0
197197
com.microsoft.azure:azure-mgmt-search;1.24.1
198198
com.microsoft.azure:azure-mgmt-storage;1.3.0
199199
com.microsoft.azure:azure-storage;8.0.0
200-
com.microsoft.azure:msal4j;1.13.3
200+
com.microsoft.azure:msal4j;1.13.4
201201
com.microsoft.azure:msal4j-persistence-extension;1.1.0
202202
com.sun.activation:jakarta.activation;1.2.2
203203
io.opentelemetry:opentelemetry-api;1.20.0

sdk/eventhubs/microsoft-azure-eventhubs-eph/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>com.microsoft.azure</groupId>
6666
<artifactId>msal4j</artifactId>
67-
<version>1.13.3</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
67+
<version>1.13.4</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
6868
<scope>test</scope>
6969
</dependency>
7070
<dependency>

sdk/eventhubs/microsoft-azure-eventhubs-extensions/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<dependency>
6969
<groupId>com.microsoft.azure</groupId>
7070
<artifactId>msal4j</artifactId>
71-
<version>1.13.3</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
71+
<version>1.13.4</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
7272
<scope>test</scope>
7373
</dependency>
7474
<dependency>

sdk/eventhubs/microsoft-azure-eventhubs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<dependency>
7878
<groupId>com.microsoft.azure</groupId>
7979
<artifactId>msal4j</artifactId>
80-
<version>1.13.3</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
80+
<version>1.13.4</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
8181
<scope>test</scope>
8282
</dependency>
8383
<dependency>

sdk/identity/azure-identity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
### Features Added
1818
- Added support to configure `clientOptions`, `httpLogOptions`, `retryPolicy`, `retryOptions` and `addPolicy` on Identity credentials.
19+
- Added support to disable instance discovery on AAD credentials.
1920

2021
## 1.7.3 (2023-01-06)
2122

sdk/identity/azure-identity/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>com.microsoft.azure</groupId>
4545
<artifactId>msal4j</artifactId>
46-
<version>1.13.3</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
46+
<version>1.13.4</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
4747
</dependency>
4848
<dependency>
4949
<groupId>com.microsoft.azure</groupId>
@@ -122,7 +122,7 @@
122122
<rules>
123123
<bannedDependencies>
124124
<includes>
125-
<include>com.microsoft.azure:msal4j:[1.13.3]</include> <!-- {x-include-update;com.microsoft.azure:msal4j;external_dependency} -->
125+
<include>com.microsoft.azure:msal4j:[1.13.4]</include> <!-- {x-include-update;com.microsoft.azure:msal4j;external_dependency} -->
126126
<include>com.microsoft.azure:msal4j-persistence-extension:[1.1.0]</include> <!-- {x-include-update;com.microsoft.azure:msal4j-persistence-extension;external_dependency} -->
127127
<include>net.java.dev.jna:jna-platform:[5.6.0]</include> <!-- {x-include-update;net.java.dev.jna:jna-platform;external_dependency} -->
128128
<include>org.linguafranca.pwdb:KeePassJava2:[2.1.4]</include> <!-- {x-include-update;org.linguafranca.pwdb:KeePassJava2;external_dependency} -->

sdk/identity/azure-identity/src/main/java/com/azure/identity/AadCredentialBuilderBase.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,16 @@ public T additionallyAllowedTenants(List<String> additionallyAllowedTenants) {
107107
identityClientOptions.setAdditionallyAllowedTenants(IdentityUtil.resolveAdditionalTenants(additionallyAllowedTenants));
108108
return (T) this;
109109
}
110+
111+
/**
112+
* Disables instance discovery.
113+
*
114+
* @return An updated instance of this builder with instance discovery disabled.
115+
*/
116+
@SuppressWarnings("unchecked")
117+
118+
public T disableInstanceDiscovery() {
119+
this.identityClientOptions.disableInstanceDisovery();
120+
return (T) this;
121+
}
110122
}

sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ public Mono<MsalToken> authenticateWithIntelliJ(TokenRequestContext request) {
218218
ConfidentialClientApplication.Builder applicationBuilder =
219219
ConfidentialClientApplication.builder(spDetails.get("client"),
220220
ClientCredentialFactory.createFromSecret(spDetails.get("key")))
221-
.authority(authorityUrl);
221+
.authority(authorityUrl)
222+
.instanceDiscovery(options.getInstanceDiscovery());
222223

223224
// If http pipeline is available, then it should override the proxy options if any configured.
224225
if (httpPipelineAdapter != null) {

sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClientBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ ConfidentialClientApplication getConfidentialClient() {
206206
ConfidentialClientApplication.Builder applicationBuilder =
207207
ConfidentialClientApplication.builder(clientId, credential);
208208
try {
209-
applicationBuilder = applicationBuilder.authority(authorityUrl);
209+
applicationBuilder = applicationBuilder.authority(authorityUrl).instanceDiscovery(options.getInstanceDiscovery());
210210
} catch (MalformedURLException e) {
211211
throw LOGGER.logExceptionAsWarning(new IllegalStateException(e));
212212
}
@@ -260,7 +260,7 @@ PublicClientApplication getPublicClient(boolean sharedTokenCacheCredential) {
260260
+ tenantId;
261261
PublicClientApplication.Builder builder = PublicClientApplication.builder(clientId);
262262
try {
263-
builder = builder.authority(authorityUrl);
263+
builder = builder.authority(authorityUrl).instanceDiscovery(options.getInstanceDiscovery());
264264
} catch (MalformedURLException e) {
265265
throw LOGGER.logExceptionAsWarning(new IllegalStateException(e));
266266
}

sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClientOptions.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public final class IdentityClientOptions implements Cloneable {
6868
private RetryPolicy retryPolicy;
6969
private List<HttpPipelinePolicy> perCallPolicies;
7070
private List<HttpPipelinePolicy> perRetryPolicies;
71+
private boolean instanceDiscovery;
7172

7273
/**
7374
* Creates an instance of IdentityClientOptions with default settings.
@@ -83,6 +84,7 @@ public IdentityClientOptions() {
8384
additionallyAllowedTenants = new HashSet<>();
8485
regionalAuthority = RegionalAuthority.fromString(
8586
configuration.get(Configuration.PROPERTY_AZURE_REGIONAL_AUTHORITY_NAME));
87+
instanceDiscovery = true;
8688
}
8789

8890
/**
@@ -654,6 +656,25 @@ IdentityClientOptions setPerRetryPolicies(List<HttpPipelinePolicy> perRetryPolic
654656
return this;
655657
}
656658

659+
/**
660+
* Disable instance discovery. Instance discovery is acquiring metadata about an authority from https://login.microsoft.com
661+
* to validate that authority. This may need to be disabled in private cloud or ADFS scenarios.
662+
*
663+
* @return the updated client options
664+
*/
665+
public IdentityClientOptions disableInstanceDisovery() {
666+
this.instanceDiscovery = false;
667+
return this;
668+
}
669+
670+
/**
671+
* Gets the instance discovery policy.
672+
* @return boolean indicating if instance discovery is enabled.
673+
*/
674+
public boolean getInstanceDiscovery() {
675+
return this.instanceDiscovery;
676+
}
677+
657678
/**
658679
* Loads the details from the specified Configuration Store.
659680
*/
@@ -669,7 +690,7 @@ private void loadFromConfiguration(Configuration configuration) {
669690
}
670691

671692
public IdentityClientOptions clone() {
672-
return new IdentityClientOptions()
693+
IdentityClientOptions clone = new IdentityClientOptions()
673694
.setAdditionallyAllowedTenants(this.additionallyAllowedTenants)
674695
.setAllowUnencryptedCache(this.allowUnencryptedCache)
675696
.setHttpClient(this.httpClient)
@@ -697,5 +718,9 @@ public IdentityClientOptions clone() {
697718
.setRetryPolicy(this.retryPolicy)
698719
.setPerCallPolicies(this.perCallPolicies)
699720
.setPerRetryPolicies(this.perRetryPolicies);
721+
if (!getInstanceDiscovery()) {
722+
clone.disableInstanceDisovery();
723+
}
724+
return clone;
700725
}
701726
}

0 commit comments

Comments
 (0)