Skip to content

Commit a8ab857

Browse files
committed
Fix merge conflicts
1 parent e82075a commit a8ab857

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
class AadInstanceDiscoveryProvider {
2020

21-
private final static String DEFAULT_TRUSTED_HOST = "login.microsoftonline.com";
22-
private final static String AUTHORIZE_ENDPOINT_TEMPLATE = "https://{host}/{tenant}/oauth2/v2.0/authorize";
23-
private final static String INSTANCE_DISCOVERY_ENDPOINT_TEMPLATE = "https://{host}:{port}/common/discovery/instance";
24-
private final static String INSTANCE_DISCOVERY_REQUEST_PARAMETERS_TEMPLATE = "?api-version=1.1&authorization_endpoint={authorizeEndpoint}";
25-
private final static String HOST_TEMPLATE_WITH_REGION = "{region}.login.microsoft.com";
26-
private final static String SOVEREIGN_HOST_TEMPLATE_WITH_REGION = "{region}.{host}";
27-
private final static String REGION_NAME = "REGION_NAME";
28-
private final static int PORT_NOT_SET = -1;
21+
private static final String DEFAULT_TRUSTED_HOST = "login.microsoftonline.com";
22+
private static final String AUTHORIZE_ENDPOINT_TEMPLATE = "https://{host}/{tenant}/oauth2/v2.0/authorize";
23+
private static final String INSTANCE_DISCOVERY_ENDPOINT_TEMPLATE = "https://{host}:{port}/common/discovery/instance";
24+
private static final String INSTANCE_DISCOVERY_REQUEST_PARAMETERS_TEMPLATE = "?api-version=1.1&authorization_endpoint={authorizeEndpoint}";
25+
private static final String HOST_TEMPLATE_WITH_REGION = "{region}.login.microsoft.com";
26+
private static final String SOVEREIGN_HOST_TEMPLATE_WITH_REGION = "{region}.{host}";
27+
private static final String REGION_NAME = "REGION_NAME";
28+
private static final int PORT_NOT_SET = -1;
2929

3030
// For information of the current api-version refer: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service#versioning
3131
private static final String DEFAULT_API_VERSION = "2020-06-01";
@@ -64,8 +64,8 @@ static InstanceDiscoveryMetadataEntry getMetadataEntry(URL authorityUrl,
6464
ServiceBundle serviceBundle) {
6565
String host = authorityUrl.getHost();
6666

67-
//If instanceDiscovery flag set to false, cache a basic instance metadata entry to skip future lookups
68-
if (!msalRequest.application().instanceDiscovery()) {
67+
//If instanceDiscovery flag set to false OR this is a managed identity scenario, cache a basic instance metadata entry to skip this and future lookups
68+
if (msalRequest.application() instanceof ManagedIdentityApplication || !((AbstractClientApplicationBase) msalRequest.application()).instanceDiscovery()) {
6969
if (cache.get(host) == null) {
7070
log.debug("Instance discovery set to false, caching a default entry.");
7171
cacheInstanceDiscoveryMetadata(host);
@@ -74,8 +74,8 @@ static InstanceDiscoveryMetadataEntry getMetadataEntry(URL authorityUrl,
7474
}
7575

7676
//If a region was set by an app developer or previously found through autodetection, adjust the authority host to use it
77-
if (shouldUseRegionalEndpoint(msalRequest) && msalRequest.application().azureRegion() != null) {
78-
host = getRegionalizedHost(authorityUrl.getHost(), msalRequest.application().azureRegion());
77+
if (shouldUseRegionalEndpoint(msalRequest) && ((AbstractClientApplicationBase) msalRequest.application()).azureRegion() != null) {
78+
host = getRegionalizedHost(authorityUrl.getHost(), ((AbstractClientApplicationBase) msalRequest.application()).azureRegion());
7979
}
8080

8181
//If there is no cached instance metadata, do instance discovery cache the result
@@ -90,18 +90,18 @@ static InstanceDiscoveryMetadataEntry getMetadataEntry(URL authorityUrl,
9090

9191
//If region autodetection is enabled and a specific region was not already set, set the application's
9292
// region to the discovered region so that future requests can skip the IMDS endpoint call
93-
if (msalRequest.application().azureRegion() == null
94-
&& msalRequest.application().autoDetectRegion()
93+
if (((AbstractClientApplicationBase) msalRequest.application()).azureRegion() == null
94+
&& ((AbstractClientApplicationBase) msalRequest.application()).autoDetectRegion()
9595
&& detectedRegion != null) {
9696
log.debug(String.format("Region autodetection found %s, this region will be used for future calls.", detectedRegion));
9797

98-
msalRequest.application().azureRegion = detectedRegion;
99-
host = getRegionalizedHost(authorityUrl.getHost(), msalRequest.application().azureRegion());
98+
((AbstractClientApplicationBase) msalRequest.application()).azureRegion = detectedRegion;
99+
host = getRegionalizedHost(authorityUrl.getHost(), ((AbstractClientApplicationBase) msalRequest.application()).azureRegion());
100100
}
101101

102102
cacheRegionInstanceMetadata(authorityUrl.getHost(), host);
103103
serviceBundle.getServerSideTelemetry().getCurrentRequest().regionOutcome(
104-
determineRegionOutcome(detectedRegion, msalRequest.application().azureRegion(), msalRequest.application().autoDetectRegion()));
104+
determineRegionOutcome(detectedRegion, ((AbstractClientApplicationBase) msalRequest.application()).azureRegion(), ((AbstractClientApplicationBase) msalRequest.application()).autoDetectRegion()));
105105
}
106106

107107
doInstanceDiscoveryAndCache(authorityUrl, validateAuthority, msalRequest, serviceBundle);

0 commit comments

Comments
 (0)