Skip to content

Commit 51d1fff

Browse files
committed
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentication-library-for-java into avdunn/tenant-override-fix
2 parents 0874c4c + 95b5efc commit 51d1fff

11 files changed

+70
-114
lines changed

msal4j-sdk/pom.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
<artifactId>slf4j-api</artifactId>
4949
<version>1.7.36</version>
5050
</dependency>
51+
<dependency>
52+
<groupId>org.slf4j</groupId>
53+
<artifactId>slf4j-simple</artifactId>
54+
<version>1.6.2</version>
55+
<scope>test</scope>
56+
</dependency>
5157
<dependency>
5258
<groupId>org.projectlombok</groupId>
5359
<artifactId>lombok</artifactId>
@@ -57,7 +63,7 @@
5763
<dependency>
5864
<groupId>com.fasterxml.jackson.core</groupId>
5965
<artifactId>jackson-databind</artifactId>
60-
<version>2.13.4.2</version>
66+
<version>2.18.1</version>
6167
</dependency>
6268

6369
<!-- test dependencies -->

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenInteractiveIT.java

+8-31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.junit.jupiter.params.provider.MethodSource;
1616
import static org.junit.jupiter.api.Assertions.assertEquals;
1717
import static org.junit.jupiter.api.Assertions.assertNotEquals;
18-
import static org.junit.jupiter.api.Assertions.assertNotNull;
1918

2019
import java.net.MalformedURLException;
2120
import java.net.URI;
@@ -53,7 +52,7 @@ void acquireTokenInteractive_ManagedUser(String environment) {
5352
cfg = new Config(environment);
5453

5554
User user = labUserProvider.getDefaultUser(cfg.azureEnvironment);
56-
assertAcquireTokenCommon(user, cfg.organizationsAuthority(), cfg.graphDefaultScope());
55+
assertAcquireTokenCommon(user, cfg.commonAuthority(), cfg.graphDefaultScope());
5756
}
5857

5958
@Test()
@@ -146,27 +145,19 @@ void acquireTokenInteractive_Ciam() {
146145
throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage());
147146
}
148147

149-
assertTokenResultNotNull(result);
148+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
150149
assertEquals(user.getUpn(), result.account().username());
151150
}
152151

153152
private void assertAcquireTokenCommon(User user, String authority, String scope) {
154-
PublicClientApplication pca;
155-
try {
156-
pca = PublicClientApplication.builder(
157-
user.getAppId()).
158-
authority(authority).
159-
build();
160-
} catch (MalformedURLException ex) {
161-
throw new RuntimeException(ex.getMessage());
162-
}
153+
PublicClientApplication pca = IntegrationTestHelper.createPublicApp(user.getAppId(), authority);
163154

164155
IAuthenticationResult result = acquireTokenInteractive(
165156
user,
166157
pca,
167158
scope);
168159

169-
assertTokenResultNotNull(result);
160+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
170161
assertEquals(user.getUpn(), result.account().username());
171162
}
172163

@@ -183,23 +174,15 @@ private void assertAcquireTokenB2C(User user, String authority) {
183174
}
184175

185176
IAuthenticationResult result = acquireTokenInteractive(user, pca, user.getAppId());
186-
assertTokenResultNotNull(result);
177+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
187178
}
188179

189180
private void assertAcquireTokenInstanceAware(User user) {
190-
PublicClientApplication pca;
191-
try {
192-
pca = PublicClientApplication.builder(
193-
user.getAppId()).
194-
authority(cfg.organizationsAuthority()).
195-
build();
196-
} catch (MalformedURLException ex) {
197-
throw new RuntimeException(ex.getMessage());
198-
}
181+
PublicClientApplication pca = IntegrationTestHelper.createPublicApp(user.getAppId(), TestConstants.MICROSOFT_AUTHORITY_HOST + user.getTenantID());
199182

200183
IAuthenticationResult result = acquireTokenInteractive_instanceAware(user, pca, cfg.graphDefaultScope());
201184

202-
assertTokenResultNotNull(result);
185+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
203186
assertEquals(user.getUpn(), result.account().username());
204187

205188
//This test is using a client app with the login.microsoftonline.com config to get tokens for a login.microsoftonline.us user,
@@ -253,7 +236,7 @@ public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext)
253236
build();
254237

255238
IAuthenticationResult result = acquireTokenInteractive(user, publicCloudPca, TestConstants.USER_READ_SCOPE);
256-
assertTokenResultNotNull(result);
239+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
257240
assertEquals(user.getHomeUPN(), result.account().username());
258241

259242
publicCloudPca.removeAccount(publicCloudPca.getAccounts().join().iterator().next()).join();
@@ -291,12 +274,6 @@ private IAuthenticationResult acquireTokenInteractive(
291274
return result;
292275
}
293276

294-
private void assertTokenResultNotNull(IAuthenticationResult result) {
295-
assertNotNull(result);
296-
assertNotNull(result.accessToken());
297-
assertNotNull(result.idToken());
298-
}
299-
300277
private IAuthenticationResult acquireTokenInteractive_instanceAware(
301278
User user,
302279
PublicClientApplication pca,

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java

+6-28
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.junit.jupiter.params.ParameterizedTest;
1515
import org.junit.jupiter.params.provider.MethodSource;
1616
import static org.junit.jupiter.api.Assertions.assertEquals;
17-
import static org.junit.jupiter.api.Assertions.assertNotNull;
1817

1918
import java.net.MalformedURLException;
2019
import java.net.URI;
@@ -114,17 +113,15 @@ public void acquireTokenWithAuthorizationCode_CiamCud() throws Exception {
114113
.build())
115114
.get();
116115

117-
assertNotNull(result);
118-
assertNotNull(result.accessToken());
119-
assertNotNull(result.idToken());
116+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
120117
assertEquals(user.getUpn(), result.account().username());
121118

122119
IAuthenticationResult resultSilent = pca.acquireTokenSilently(SilentParameters
123120
.builder(Collections.singleton("user.read"), result.account())
124121
.build())
125122
.get();
126123

127-
assertNotNull(resultSilent);
124+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
128125
assertEquals(resultSilent.accessToken(), result.accessToken());
129126
assertEquals(resultSilent.account().username(), result.account().username());
130127
}
@@ -146,38 +143,21 @@ private void assertAcquireTokenADFS2019(User user) {
146143
authCode,
147144
Collections.singleton(TestConstants.ADFS_SCOPE));
148145

149-
assertNotNull(result);
150-
assertNotNull(result.accessToken());
151-
assertNotNull(result.idToken());
146+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
152147
assertEquals(user.getUpn(), result.account().username());
153148
}
154149

155150
private void assertAcquireTokenAAD(User user, Map<String, Set<String>> parameters) {
156151

157-
PublicClientApplication pca;
158-
Set<String> clientCapabilities = null;
159-
if (parameters != null) {
160-
clientCapabilities = parameters.getOrDefault("clientCapabilities", null);
161-
}
162-
try {
163-
pca = PublicClientApplication.builder(
164-
user.getAppId()).
165-
authority(cfg.organizationsAuthority()).
166-
clientCapabilities(clientCapabilities).
167-
build();
168-
} catch (MalformedURLException ex) {
169-
throw new RuntimeException(ex.getMessage());
170-
}
152+
PublicClientApplication pca = IntegrationTestHelper.createPublicApp(user.getAppId(), cfg.commonAuthority());
171153

172154
String authCode = acquireAuthorizationCodeAutomated(user, pca, parameters);
173155
IAuthenticationResult result = acquireTokenAuthorizationCodeFlow(
174156
pca,
175157
authCode,
176158
Collections.singleton(cfg.graphDefaultScope()));
177159

178-
assertNotNull(result);
179-
assertNotNull(result.accessToken());
180-
assertNotNull(result.idToken());
160+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
181161
assertEquals(user.getUpn(), result.account().username());
182162
}
183163

@@ -200,9 +180,7 @@ private void assertAcquireTokenB2C(User user) {
200180
String authCode = acquireAuthorizationCodeAutomated(user, cca, null);
201181
IAuthenticationResult result = acquireTokenInteractiveB2C(cca, authCode);
202182

203-
assertNotNull(result);
204-
assertNotNull(result.accessToken());
205-
assertNotNull(result.idToken());
183+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
206184
}
207185

208186
private IAuthenticationResult acquireTokenAuthorizationCodeFlow(

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/Config.java

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public class Config {
1414
private String organizationsAuthority;
1515
private String tenantSpecificAuthority;
16+
private String commonAuthority;
1617
private String graphDefaultScope;
1718
AppCredentialProvider appProvider;
1819
private String tenant;
@@ -25,6 +26,7 @@ public class Config {
2526
switch (azureEnvironment) {
2627
case AzureEnvironment.AZURE:
2728
organizationsAuthority = TestConstants.ORGANIZATIONS_AUTHORITY;
29+
commonAuthority = TestConstants.COMMON_AUTHORITY;
2830
tenantSpecificAuthority = TestConstants.TENANT_SPECIFIC_AUTHORITY;
2931
graphDefaultScope = TestConstants.GRAPH_DEFAULT_SCOPE;
3032
appProvider = new AppCredentialProvider(azureEnvironment);
@@ -33,6 +35,7 @@ public class Config {
3335
case AzureEnvironment.AZURE_US_GOVERNMENT:
3436
organizationsAuthority = TestConstants.ARLINGTON_ORGANIZATIONS_AUTHORITY;
3537
tenantSpecificAuthority = TestConstants.ARLINGTON_TENANT_SPECIFIC_AUTHORITY;
38+
commonAuthority = TestConstants.ARLINGTON_COMMON_AUTHORITY;
3639
graphDefaultScope = TestConstants.ARLINGTON_GRAPH_DEFAULT_SCOPE;
3740
appProvider = new AppCredentialProvider(azureEnvironment);
3841
tenant = TestConstants.ARLINGTON_AUTHORITY_TENANT;

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.junit.jupiter.params.provider.MethodSource;
1717
import org.junit.jupiter.api.BeforeAll;
1818
import org.junit.jupiter.api.AfterAll;
19-
import static org.junit.jupiter.api.Assertions.assertFalse;
2019
import static org.junit.jupiter.api.Assertions.assertNotNull;
2120
import java.util.Collections;
2221
import java.util.function.Consumer;
@@ -41,10 +40,7 @@ void DeviceCodeFlowADTest(String environment) throws Exception {
4140

4241
User user = labUserProvider.getDefaultUser(cfg.azureEnvironment);
4342

44-
PublicClientApplication pca = PublicClientApplication.builder(
45-
user.getAppId()).
46-
authority(cfg.tenantSpecificAuthority()).
47-
build();
43+
PublicClientApplication pca = IntegrationTestHelper.createPublicApp(user.getAppId(), cfg.commonAuthority());
4844

4945
Consumer<DeviceCode> deviceCodeConsumer = (DeviceCode deviceCode) -> runAutomatedDeviceCodeFlow(deviceCode, user);
5046

@@ -54,8 +50,7 @@ void DeviceCodeFlowADTest(String environment) throws Exception {
5450
.build())
5551
.get();
5652

57-
assertNotNull(result);
58-
assertNotNull(result.accessToken());
53+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
5954
}
6055

6156
@Test()
@@ -78,19 +73,15 @@ void DeviceCodeFlowADFSv2019Test() throws Exception {
7873
.build())
7974
.get();
8075

81-
assertNotNull(result);
82-
assertNotNull(result.accessToken());
76+
IntegrationTestHelper.assertAccessAndIdTokensNotNull(result);
8377
}
8478

8579
@Test()
8680
void DeviceCodeFlowMSATest() throws Exception {
8781

8882
User user = labUserProvider.getMSAUser();
8983

90-
PublicClientApplication pca = PublicClientApplication.builder(
91-
user.getAppId()).
92-
authority(TestConstants.CONSUMERS_AUTHORITY).
93-
build();
84+
PublicClientApplication pca = IntegrationTestHelper.createPublicApp(user.getAppId(), TestConstants.CONSUMERS_AUTHORITY);
9485

9586
Consumer<DeviceCode> deviceCodeConsumer = (DeviceCode deviceCode) -> {
9687
runAutomatedDeviceCodeFlow(deviceCode, user);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.aad.msal4j;
5+
6+
import java.net.MalformedURLException;
7+
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
10+
class IntegrationTestHelper {
11+
12+
static PublicClientApplication createPublicApp(String appID, String authority) {
13+
try {
14+
return PublicClientApplication.builder(
15+
appID).
16+
authority(authority).
17+
build();
18+
} catch (MalformedURLException e) {
19+
throw new RuntimeException(e);
20+
}
21+
}
22+
23+
static void assertAccessAndIdTokensNotNull(IAuthenticationResult result) {
24+
assertNotNull(result);
25+
assertNotNull(result.accessToken());
26+
assertNotNull(result.idToken());
27+
}
28+
}

msal4j-sdk/src/integrationtest/java/com.microsoft.aad.msal4j/TestConstants.java

+1-15
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
package com.microsoft.aad.msal4j;
55

6-
import java.util.Collections;
7-
import java.util.HashSet;
8-
import java.util.Set;
9-
106
public class TestConstants {
117
public final static String KEYVAULT_DEFAULT_SCOPE = "https://vault.azure.net/.default";
128
public final static String MSIDLAB_DEFAULT_SCOPE = "https://request.msidlab.com/.default";
@@ -34,15 +30,9 @@ public class TestConstants {
3430
public final static String TENANT_SPECIFIC_AUTHORITY = MICROSOFT_AUTHORITY_HOST + MICROSOFT_AUTHORITY_TENANT;
3531
public final static String REGIONAL_MICROSOFT_AUTHORITY_BASIC_HOST_WESTUS = "westus.login.microsoft.com";
3632

37-
public final static String REGIONAL_MICROSOFT_AUTHORITY_BASIC_HOST_EASTUS = "eastus.login.microsoft.com";
38-
39-
// public final static String CIAM_AUTHORITY = MICROSOFT_AUTHORITY_HOST + "msidlabciam1.onmicrosoft.com";
40-
public final static String CIAM_AUTHORITY = "https://msidlabciam1.ciamlogin.com/" + "msidlabciam1.onmicrosoft.com";
41-
42-
public final static String CIAM_TEST_AUTHORITY = "https://contoso0781.ciamlogin.com/6babcaad-604b-40ac-a9d7-9fd97c0b779f/v2.0/.well-known/openid-configuration?dc=ESTS-PUB-EUS-AZ1-FD000-TEST1&ciamhost=true";
43-
4433
public final static String ARLINGTON_ORGANIZATIONS_AUTHORITY = ARLINGTON_MICROSOFT_AUTHORITY_HOST + "organizations/";
4534
public final static String ARLINGTON_TENANT_SPECIFIC_AUTHORITY = ARLINGTON_MICROSOFT_AUTHORITY_HOST + ARLINGTON_AUTHORITY_TENANT;
35+
public final static String ARLINGTON_COMMON_AUTHORITY = ARLINGTON_MICROSOFT_AUTHORITY_HOST + "common/";
4636
public final static String ARLINGTON_GRAPH_DEFAULT_SCOPE = "https://graph.microsoft.us/.default";
4737

4838
public final static String B2C_AUTHORITY = "https://msidlabb2c.b2clogin.com/msidlabb2c.onmicrosoft.com/";
@@ -63,9 +53,5 @@ public class TestConstants {
6353
public final static String ADFS_SCOPE = USER_READ_SCOPE;
6454
public final static String ADFS_APP_ID = "PublicClientId";
6555

66-
public final static String CLAIMS = "{\"id_token\":{\"auth_time\":{\"essential\":true}}}";
67-
public final static Set<String> CLIENT_CAPABILITIES_EMPTY = new HashSet<>(Collections.emptySet());
6856
public final static String AUTHORITY_PUBLIC_TENANT_SPECIFIC = "https://login.microsoftonline.com/" + MICROSOFT_AUTHORITY_TENANT;
69-
70-
public final static String DEFAULT_ACCESS_TOKEN = "defaultAccessToken";
7157
}

0 commit comments

Comments
 (0)