Skip to content

Commit 770dbc7

Browse files
authored
Merge pull request #420 from AzureAD/dev
Release 1.11.0
2 parents 050d188 + 3e42121 commit 770dbc7

33 files changed

+211
-89
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@
2424

2525
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2626
hs_err_pid*
27+
28+
# Lombok
29+
target/*

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Quick links:
1616
The library supports the following Java environments:
1717
- Java 8 (or higher)
1818

19-
Current version - 1.10.1
19+
Current version - 1.11.0
2020

2121
You can find the changes for each version in the [change log](https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/master/changelog.txt).
2222

@@ -28,13 +28,13 @@ Find [the latest package in the Maven repository](https://mvnrepository.com/arti
2828
<dependency>
2929
<groupId>com.microsoft.azure</groupId>
3030
<artifactId>msal4j</artifactId>
31-
<version>1.10.1</version>
31+
<version>1.11.0</version>
3232
</dependency>
3333
```
3434
### Gradle
3535

3636
```
37-
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.10.1'
37+
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.11.0'
3838
```
3939

4040
## Usage

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 1.11.0
2+
=============
3+
- Adds ability to override authority in AcquireToken calls
4+
- Fixes issue where authority port was being dropped from URLs
5+
16
Version 1.10.1
27
=============
38
- Improved behavior when using regional authorities

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.microsoft.azure</groupId>
55
<artifactId>msal4j</artifactId>
6-
<version>1.10.1</version>
6+
<version>1.11.0</version>
77
<packaging>jar</packaging>
88
<name>msal4j</name>
99
<description>

src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenSilentIT.java

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void acquireTokenSilent_ForceRefresh(String environment) throws Exception
8383
assertResultNotNull(resultAfterRefresh);
8484

8585
// Check that new refresh and id tokens are being returned
86-
assertResultRefreshed(result, resultAfterRefresh);
86+
assertTokensAreNotEqual(result, resultAfterRefresh);
8787
}
8888

8989
@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
@@ -135,7 +135,7 @@ public void acquireTokenSilent_ADFS2019(String environment) throws Exception{
135135
IAuthenticationResult resultAfterRefresh = acquireTokenSilently(pca, account, TestConstants.ADFS_SCOPE, true);
136136
assertResultNotNull(resultAfterRefresh);
137137

138-
assertResultRefreshed(result, resultAfterRefresh);
138+
assertTokensAreNotEqual(result, resultAfterRefresh);
139139
}
140140

141141
// Commented out due to unclear B2C behavior causing occasional errors
@@ -158,7 +158,7 @@ public void acquireTokenSilent_B2C() throws Exception{
158158
IAuthenticationResult resultAfterRefresh = acquireTokenSilently(pca, account, TestConstants.B2C_READ_SCOPE, true);
159159
assertResultNotNull(resultAfterRefresh);
160160

161-
assertResultRefreshed(result, resultAfterRefresh);
161+
assertTokensAreNotEqual(result, resultAfterRefresh);
162162
}
163163

164164

@@ -261,7 +261,38 @@ public void acquireTokenSilent_WithRefreshOn(String environment) throws Exceptio
261261
resultSilentWithRefreshOn = acquireTokenSilently(pca, resultOriginal.account(), cfg.graphDefaultScope(), false);
262262
//Current time is after refreshOn, so token should be refreshed
263263
Assert.assertNotNull(resultSilentWithRefreshOn);
264-
assertResultRefreshed(resultSilent, resultSilentWithRefreshOn);
264+
assertTokensAreNotEqual(resultSilent, resultSilentWithRefreshOn);
265+
}
266+
267+
@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
268+
public void acquireTokenSilent_TenantAsParameter(String environment) throws Exception {
269+
cfg = new Config(environment);
270+
271+
User user = labUserProvider.getDefaultUser(environment);
272+
273+
PublicClientApplication pca = PublicClientApplication.builder(
274+
user.getAppId()).
275+
authority(cfg.organizationsAuthority()).
276+
build();
277+
278+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
279+
builder(Collections.singleton(cfg.graphDefaultScope()),
280+
user.getUpn(),
281+
user.getPassword().toCharArray())
282+
.build()).get();
283+
assertResultNotNull(result);
284+
285+
IAccount account = pca.getAccounts().join().iterator().next();
286+
IAuthenticationResult silentResult = acquireTokenSilently(pca, account, cfg.graphDefaultScope(), false);
287+
assertResultNotNull(silentResult);
288+
assertTokensAreEqual(result, silentResult);
289+
290+
IAuthenticationResult resultWithTenantParam = pca.acquireTokenSilently(SilentParameters.
291+
builder(Collections.singleton(cfg.graphDefaultScope()), account).
292+
tenant(cfg.tenant()).
293+
build()).get();
294+
assertResultNotNull(resultWithTenantParam);
295+
assertTokensAreNotEqual(result, resultWithTenantParam);
265296
}
266297

267298
private IConfidentialClientApplication getConfidentialClientApplications() throws Exception{
@@ -335,13 +366,13 @@ private void assertResultNotNull(IAuthenticationResult result) {
335366
Assert.assertNotNull(result.idToken());
336367
}
337368

338-
private void assertResultRefreshed(IAuthenticationResult result, IAuthenticationResult resultAfterRefresh) {
339-
Assert.assertNotEquals(result.accessToken(), resultAfterRefresh.accessToken());
340-
Assert.assertNotEquals(result.idToken(), resultAfterRefresh.idToken());
369+
private void assertTokensAreNotEqual(IAuthenticationResult result, IAuthenticationResult secondResult) {
370+
Assert.assertNotEquals(result.accessToken(), secondResult.accessToken());
371+
Assert.assertNotEquals(result.idToken(), secondResult.idToken());
341372
}
342373

343-
private void assertTokensAreEqual(IAuthenticationResult result, IAuthenticationResult resultAfterRefresh) {
344-
Assert.assertEquals(result.accessToken(), resultAfterRefresh.accessToken());
345-
Assert.assertEquals(result.idToken(), resultAfterRefresh.idToken());
374+
private void assertTokensAreEqual(IAuthenticationResult result, IAuthenticationResult secondResult) {
375+
Assert.assertEquals(result.accessToken(), secondResult.accessToken());
376+
Assert.assertEquals(result.idToken(), secondResult.idToken());
346377
}
347378
}

src/integrationtest/java/com.microsoft.aad.msal4j/ApacheHttpClientAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class ApacheHttpClientAdapter implements IHttpClient {
2424

25-
private CloseableHttpClient httpClient;
25+
private final CloseableHttpClient httpClient;
2626

2727
ApacheHttpClientAdapter(){
2828
this.httpClient = HttpClients.createDefault();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class Config {
1515
private String tenantSpecificAuthority;
1616
private String graphDefaultScope;
1717
AppCredentialProvider appProvider;
18+
private String tenant;
1819

1920
String azureEnvironment;
2021

@@ -27,12 +28,14 @@ public class Config {
2728
tenantSpecificAuthority = TestConstants.TENANT_SPECIFIC_AUTHORITY;
2829
graphDefaultScope = TestConstants.GRAPH_DEFAULT_SCOPE;
2930
appProvider = new AppCredentialProvider(azureEnvironment);
31+
tenant = TestConstants.MICROSOFT_AUTHORITY_TENANT;
3032
break;
3133
case AzureEnvironment.AZURE_US_GOVERNMENT :
3234
organizationsAuthority = TestConstants.ARLINGTON_ORGANIZATIONS_AUTHORITY;
3335
tenantSpecificAuthority = TestConstants.ARLINGTON_TENANT_SPECIFIC_AUTHORITY;
3436
graphDefaultScope = TestConstants.ARLINGTON_GRAPH_DEFAULT_SCOPE;
3537
appProvider = new AppCredentialProvider(azureEnvironment);
38+
tenant = TestConstants.ARLINGTON_AUTHORITY_TENANT;
3639
break;
3740
default:
3841
throw new UnsupportedOperationException("Azure Environment - " + azureEnvironment + " unsupported");

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public class DeviceCodeIT {
2626
private LabUserProvider labUserProvider;
2727
private WebDriver seleniumDriver;
2828

29-
private Config cfg;
30-
3129
@BeforeClass
3230
public void setUp(){
3331
labUserProvider = LabUserProvider.getInstance();
@@ -36,7 +34,7 @@ public void setUp(){
3634

3735
@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
3836
public void DeviceCodeFlowADTest(String environment) throws Exception {
39-
cfg = new Config(environment);
37+
Config cfg = new Config(environment);
4038

4139
User user = labUserProvider.getDefaultUser(cfg.azureEnvironment);
4240

@@ -56,7 +54,7 @@ public void DeviceCodeFlowADTest(String environment) throws Exception {
5654
.get();
5755

5856
Assert.assertNotNull(result);
59-
Assert.assertTrue(!Strings.isNullOrEmpty(result.accessToken()));
57+
Assert.assertFalse(Strings.isNullOrEmpty(result.accessToken()));
6058
}
6159

6260
@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)

src/integrationtest/java/com.microsoft.aad.msal4j/HttpClientIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package com.microsoft.aad.msal4j;
55

66
import labapi.LabUserProvider;
7-
import labapi.AzureEnvironment;
87
import labapi.User;
98
import org.testng.Assert;
109
import org.testng.annotations.BeforeClass;

src/integrationtest/java/com.microsoft.aad.msal4j/OAuthRequestValidationUnitT.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public void oAuthRequest_for_acquireTokenByClientCertificate() throws Exception
3131
}
3232

3333
Map<String, String> queryParams = splitQuery(query);
34-
Assert.assertEquals(7, queryParams.size());
34+
Assert.assertEquals(queryParams.size(), 7);
3535

3636
// validate Authorization Grants query params
37-
Assert.assertEquals(GRANT_TYPE_JWT, queryParams.get("grant_type"));
38-
Assert.assertEquals(JWT, queryParams.get("assertion"));
37+
Assert.assertEquals(queryParams.get("grant_type"), GRANT_TYPE_JWT);
38+
Assert.assertEquals(queryParams.get("assertion"), JWT);
3939

4040
// validate Client Authentication query params
4141
Assert.assertFalse(StringUtils.isEmpty(queryParams.get("client_assertion")));
@@ -51,10 +51,10 @@ public void oAuthRequest_for_acquireTokenByClientCertificate() throws Exception
5151
Assert.assertTrue(scopes.contains(AbstractMsalAuthorizationGrant.SCOPE_PROFILE));
5252
Assert.assertTrue(scopes.contains(AbstractMsalAuthorizationGrant.SCOPE_OFFLINE_ACCESS));
5353

54-
Assert.assertEquals(CLIENT_ASSERTION_TYPE_JWT, queryParams.get("client_assertion_type"));
55-
Assert.assertEquals(ON_BEHALF_OF_USE_JWT, queryParams.get("requested_token_use"));
54+
Assert.assertEquals(queryParams.get("client_assertion_type"), CLIENT_ASSERTION_TYPE_JWT);
55+
Assert.assertEquals(queryParams.get("requested_token_use"), ON_BEHALF_OF_USE_JWT);
5656

57-
Assert.assertEquals(CLIENT_INFO_VALUE, queryParams.get("client_info"));
57+
Assert.assertEquals(queryParams.get("client_info"), CLIENT_INFO_VALUE);
5858
}
5959

6060
@Test
@@ -83,18 +83,18 @@ public void oAuthRequest_for_acquireTokenByClientAssertion() throws Exception {
8383

8484
Map<String, String> queryParams = splitQuery(query);
8585

86-
Assert.assertEquals(5, queryParams.size());
86+
Assert.assertEquals(queryParams.size(), 5);
8787

8888
// validate Authorization Grants query params
89-
Assert.assertEquals(CLIENT_CREDENTIALS_GRANT_TYPE, queryParams.get("grant_type"));
89+
Assert.assertEquals(queryParams.get("grant_type"), CLIENT_CREDENTIALS_GRANT_TYPE);
9090

9191
// validate Client Authentication query params
9292
Assert.assertTrue(StringUtils.isNotEmpty(queryParams.get("client_assertion")));
93-
Assert.assertEquals(CLIENT_ASSERTION_TYPE_JWT, queryParams.get("client_assertion_type"));
93+
Assert.assertEquals(queryParams.get("client_assertion_type"), CLIENT_ASSERTION_TYPE_JWT);
9494

9595
// to do validate scopes
96-
Assert.assertEquals("https://SomeResource.azure.net openid profile offline_access", queryParams.get("scope"));
96+
Assert.assertEquals(queryParams.get("scope"), "https://SomeResource.azure.net openid profile offline_access");
9797

98-
Assert.assertEquals(CLIENT_INFO_VALUE, queryParams.get("client_info"));
98+
Assert.assertEquals(queryParams.get("client_info"), CLIENT_INFO_VALUE);
9999
}
100100
}

src/integrationtest/java/com.microsoft.aad.msal4j/OkHttpClientAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class OkHttpClientAdapter implements IHttpClient{
1717

18-
private OkHttpClient client;
18+
private final OkHttpClient client;
1919

2020
OkHttpClientAdapter(){
2121
this.client = new OkHttpClient();

src/integrationtest/java/com.microsoft.aad.msal4j/RefreshTokenIT.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
package com.microsoft.aad.msal4j;
55

66
import labapi.LabUserProvider;
7-
import labapi.AzureEnvironment;
87
import labapi.User;
98
import org.testng.Assert;
10-
import org.testng.annotations.BeforeTest;
119
import org.testng.annotations.Test;
1210

1311
import java.util.Collections;

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ public class TestConstants {
1717
public final static String B2C_CONFIDENTIAL_CLIENT_LAB_APP_ID = "MSIDLABB2C-MSAapp-AppID";
1818

1919
public final static String MICROSOFT_AUTHORITY_HOST = "https://login.microsoftonline.com/";
20+
public final static String MICROSOFT_AUTHORITY_HOST_WITH_PORT = "https://login.microsoftonline.com:443/";
2021
public final static String ARLINGTON_MICROSOFT_AUTHORITY_HOST = "https://login.microsoftonline.us/";
22+
public final static String MICROSOFT_AUTHORITY_TENANT = "msidlab4.onmicrosoft.com";
23+
public final static String ARLINGTON_AUTHORITY_TENANT = "arlmsidlab1.onmicrosoft.us";
2124

2225
public final static String ORGANIZATIONS_AUTHORITY = MICROSOFT_AUTHORITY_HOST + "organizations/";
2326
public final static String COMMON_AUTHORITY = MICROSOFT_AUTHORITY_HOST + "common/";
27+
public final static String COMMON_AUTHORITY_WITH_PORT = MICROSOFT_AUTHORITY_HOST_WITH_PORT + "msidlab4.onmicrosoft.com";
2428
public final static String MICROSOFT_AUTHORITY = MICROSOFT_AUTHORITY_HOST + "microsoft.onmicrosoft.com";
25-
public final static String TENANT_SPECIFIC_AUTHORITY = MICROSOFT_AUTHORITY_HOST + "msidlab4.onmicrosoft.com";
29+
public final static String TENANT_SPECIFIC_AUTHORITY = MICROSOFT_AUTHORITY_HOST + MICROSOFT_AUTHORITY_TENANT;
2630

2731
public final static String ARLINGTON_ORGANIZATIONS_AUTHORITY = ARLINGTON_MICROSOFT_AUTHORITY_HOST + "organizations/";
2832
public final static String ARLINGTON_COMMON_AUTHORITY = ARLINGTON_MICROSOFT_AUTHORITY_HOST + "common/";
29-
public final static String ARLINGTON_TENANT_SPECIFIC_AUTHORITY = ARLINGTON_MICROSOFT_AUTHORITY_HOST + "arlmsidlab1.onmicrosoft.us";
33+
public final static String ARLINGTON_TENANT_SPECIFIC_AUTHORITY = ARLINGTON_MICROSOFT_AUTHORITY_HOST + ARLINGTON_AUTHORITY_TENANT;
3034
public final static String ARLINGTON_GRAPH_DEFAULT_SCOPE = "https://graph.microsoft.us/.default";
3135

3236

@@ -48,11 +52,11 @@ public class TestConstants {
4852
public final static String ADFS_APP_ID = "PublicClientId";
4953

5054
public final static String CLAIMS = "{\"id_token\":{\"auth_time\":{\"essential\":true}}}";
51-
public final static Set<String> CLIENT_CAPABILITIES_EMPTY = new HashSet<String>(Collections.emptySet());
52-
public final static Set<String> CLIENT_CAPABILITIES_LLT = new HashSet<String>(Collections.singletonList("llt"));
55+
public final static Set<String> CLIENT_CAPABILITIES_EMPTY = new HashSet<>(Collections.emptySet());
56+
public final static Set<String> CLIENT_CAPABILITIES_LLT = new HashSet<>(Collections.singletonList("llt"));
5357

5458
// cross cloud b2b settings
55-
public final static String AUTHORITY_ARLINGTON = "https://login.microsoftonline.us/arlmsidlab1.onmicrosoft.us";
59+
public final static String AUTHORITY_ARLINGTON = "https://login.microsoftonline.us/" + ARLINGTON_AUTHORITY_TENANT;
5660
public final static String AUTHORITY_MOONCAKE = "https://login.chinacloudapi.cn/mncmsidlab1.partner.onmschina.cn";
57-
public final static String AUTHORITY_PUBLIC_TENANT_SPECIFIC = "https://login.microsoftonline.com/msidlab4.onmicrosoft.com";
61+
public final static String AUTHORITY_PUBLIC_TENANT_SPECIFIC = "https://login.microsoftonline.com/" + MICROSOFT_AUTHORITY_TENANT;
5862
}

src/integrationtest/java/com.microsoft.aad.msal4j/UsernamePasswordIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ public void acquireTokenWithUsernamePassword_ADFSv2(String environment) throws E
9797
assertAcquireTokenCommonAAD(user);
9898
}
9999

100+
@Test
101+
public void acquireTokenWithUsernamePassword_AuthorityWithPort() throws Exception {
102+
User user = labUserProvider.getDefaultUser();
103+
104+
assertAcquireTokenCommon(
105+
user,
106+
TestConstants.COMMON_AUTHORITY_WITH_PORT,
107+
TestConstants.GRAPH_DEFAULT_SCOPE,
108+
user.getAppId());
109+
}
110+
100111
private void assertAcquireTokenCommonADFS(User user) throws Exception {
101112
assertAcquireTokenCommon(user, TestConstants.ADFS_AUTHORITY, TestConstants.ADFS_SCOPE,
102113
TestConstants.ADFS_APP_ID);

src/integrationtest/java/labapi/KeyVaultSecretsProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
public class KeyVaultSecretsProvider {
1818

19-
private KeyVaultClient keyVaultClient;
20-
private static String CLIENT_ID = "55e7e5af-ca53-482d-9aa3-5cb1cc8eecb5";
19+
private final KeyVaultClient keyVaultClient;
20+
private static final String CLIENT_ID = "55e7e5af-ca53-482d-9aa3-5cb1cc8eecb5";
2121
public static String CERTIFICATE_ALIAS = "MsalJavaAutomationRunner";
2222

23-
private static String WIN_KEYSTORE = "Windows-MY";
24-
private static String KEYSTORE_PROVIDER = "SunMSCAPI";
23+
private static final String WIN_KEYSTORE = "Windows-MY";
24+
private static final String KEYSTORE_PROVIDER = "SunMSCAPI";
2525

26-
private static String MAC_KEYSTORE = "KeychainStore";
26+
private static final String MAC_KEYSTORE = "KeychainStore";
2727

2828
KeyVaultSecretsProvider(){
2929
keyVaultClient = getAuthenticatedKeyVaultClient();

0 commit comments

Comments
 (0)