Skip to content

Commit 22e4113

Browse files
authored
Merge pull request #78 from AzureAD/dev
0.5.0-preview release
2 parents 89988f3 + 5232f53 commit 22e4113

File tree

185 files changed

+1888
-4401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+1888
-4401
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
`master` branch | `dev` branch | Reference Docs
44
--------------------|-----------------|---------------
5-
[![Build status](https://identitydivision.visualstudio.com/IDDP/_apis/build/status/CI/Java/MSAL%20Java%20CI%20Build?branchName=master)](https://identitydivision.visualstudio.com/IDDP/_build/latest?definitionId=762) | [![Build status](https://identitydivision.visualstudio.com/IDDP/_apis/build/status/CI/Java/MSAL%20Java%20CI%20Build?branchName=dev)](https://identitydivision.visualstudio.com/IDDP/_build/latest?definitionId=762)| [![Javadocs](http://javadoc.io/badge/com.microsoft.azure/adal4j.svg)](http://javadoc.io/doc/com.microsoft.azure/adal4j)
5+
[![Build status](https://identitydivision.visualstudio.com/IDDP/_apis/build/status/CI/Java/MSAL%20Java%20CI%20Build?branchName=master)](https://identitydivision.visualstudio.com/IDDP/_build/latest?definitionId=762) | [![Build status](https://identitydivision.visualstudio.com/IDDP/_apis/build/status/CI/Java/MSAL%20Java%20CI%20Build?branchName=dev)](https://identitydivision.visualstudio.com/IDDP/_build/latest?definitionId=762)| [![Javadocs](http://javadoc.io/badge/com.microsoft.azure/msal4j.svg)](http://javadoc.io/doc/com.microsoft.azure/msal4j)
66

77
|[Getting Started](https://github.com/AzureAD/microsoft-authentication-library-for-java/wiki)| [Docs](https://aka.ms/aaddev)| [Support](README.md#community-help-and-support)
88
| --- | --- | --- |
@@ -11,7 +11,7 @@ The MSAL library for Java gives your app the ability to begin using the Microsof
1111

1212

1313
## Versions
14-
Current version - 0.4.0-preview
14+
Current version - 0.5.0-preview
1515

1616
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).
1717

@@ -43,4 +43,4 @@ If you find a security issue with our libraries or services please report it to
4343

4444
## We Value and Adhere to the Microsoft Open Source Code of Conduct
4545

46-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
46+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

changelog.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
Version 0.5.0-preview
2+
=============
3+
- Refactored AuthenticationException to MsalServiceException, MsalClientException, MsalInteractionRequiredException
4+
- Added cache lookup to acquireToken by client credentials grant
5+
- Updated Javadoc reference
6+
- Updated license headers
7+
18
Version 0.4.0-preview
29
=============
3-
- Exposing acquire token by refresh token api
10+
- Exposed acquire token by refresh token api
411

512
Version 0.3.0-preview
613
=============

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>0.4.0-preview</version>
6+
<version>0.5.0-preview</version>
77
<packaging>jar</packaging>
88
<name>msal4j</name>
99
<description>
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.aad.msal4j;
5+
6+
import labapi.FederationProvider;
7+
import labapi.LabResponse;
8+
import labapi.LabUserProvider;
9+
import labapi.NationalCloud;
10+
import org.testng.Assert;
11+
import org.testng.annotations.BeforeClass;
12+
import org.testng.annotations.Test;
13+
14+
import java.util.Collections;
15+
import java.util.Set;
16+
17+
public class AcquireTokenSilentIT {
18+
private LabUserProvider labUserProvider;
19+
20+
@BeforeClass
21+
public void setUp() {
22+
labUserProvider = LabUserProvider.getInstance();
23+
}
24+
25+
@Test
26+
public void acquireTokenSilent_OrganizationAuthority_TokenRefreshed() throws Exception {
27+
28+
// When using common, organization, or consumer tenants, cache has no way
29+
// of determining which access token to return therefore token is always refreshed
30+
IPublicClientApplication pca = getPublicClientApplicationWithTokensInCache();
31+
32+
IAccount account = pca.getAccounts().join().iterator().next();
33+
SilentParameters parameters = SilentParameters.builder(
34+
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
35+
account).build();
36+
37+
IAuthenticationResult result = pca.acquireTokenSilently(parameters).get();
38+
39+
Assert.assertNotNull(result);
40+
Assert.assertNotNull(result.accessToken());
41+
Assert.assertNotNull(result.idToken());
42+
}
43+
44+
@Test
45+
public void acquireTokenSilent_LabAuthority_TokenNotRefreshed() throws Exception {
46+
// Access token should be returned from cache, and not using refresh token
47+
48+
LabResponse labResponse = labUserProvider.getDefaultUser(
49+
NationalCloud.AZURE_CLOUD,
50+
false);
51+
String password = labUserProvider.getUserPassword(labResponse.getUser());
52+
String labAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + labResponse.getUser().getTenantId();
53+
54+
PublicClientApplication pca = new PublicClientApplication.Builder(
55+
labResponse.getAppId()).
56+
authority(labAuthority).
57+
build();
58+
59+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
60+
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
61+
labResponse.getUser().getUpn(),
62+
password.toCharArray())
63+
.build())
64+
.get();
65+
66+
IAccount account = pca.getAccounts().join().iterator().next();
67+
SilentParameters parameters = SilentParameters.builder(
68+
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), account).
69+
build();
70+
71+
IAuthenticationResult acquireSilentResult = pca.acquireTokenSilently(parameters).get();
72+
73+
Assert.assertNotNull(acquireSilentResult.accessToken());
74+
Assert.assertNotNull(result.idToken());
75+
// Check that access and id tokens are coming from cache
76+
Assert.assertEquals(result.accessToken(), acquireSilentResult.accessToken());
77+
Assert.assertEquals(result.idToken(), acquireSilentResult.idToken());
78+
}
79+
80+
@Test
81+
public void acquireTokenSilent_ForceRefresh() throws Exception {
82+
83+
LabResponse labResponse = labUserProvider.getDefaultUser(
84+
NationalCloud.AZURE_CLOUD,
85+
false);
86+
String password = labUserProvider.getUserPassword(labResponse.getUser());
87+
88+
PublicClientApplication pca = new PublicClientApplication.Builder(
89+
labResponse.getAppId()).
90+
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
91+
build();
92+
93+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
94+
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
95+
labResponse.getUser().getUpn(),
96+
password.toCharArray())
97+
.build())
98+
.get();
99+
100+
IAccount account = pca.getAccounts().join().iterator().next();
101+
SilentParameters parameters = SilentParameters.builder(
102+
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), account).
103+
forceRefresh(true).
104+
build();
105+
106+
IAuthenticationResult resultAfterRefresh = pca.acquireTokenSilently(parameters).get();
107+
108+
Assert.assertNotNull(resultAfterRefresh);
109+
Assert.assertNotNull(resultAfterRefresh.accessToken());
110+
Assert.assertNotNull(resultAfterRefresh.idToken());
111+
// Check that new refresh and id tokens are being returned
112+
Assert.assertNotEquals(result.accessToken(), resultAfterRefresh.accessToken());
113+
Assert.assertNotEquals(result.idToken(), resultAfterRefresh.idToken());
114+
}
115+
116+
@Test
117+
public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount() throws Exception {
118+
119+
IPublicClientApplication pca = getPublicClientApplicationWithTokensInCache();
120+
121+
// get lab user for different account
122+
LabResponse labResponse = labUserProvider.getAdfsUser(
123+
FederationProvider.ADFSV4,
124+
true,
125+
false);
126+
String password = labUserProvider.getUserPassword(labResponse.getUser());
127+
128+
// acquire token for different account
129+
pca.acquireToken(UserNamePasswordParameters.
130+
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
131+
labResponse.getUser().getUpn(),
132+
password.toCharArray())
133+
.build())
134+
.get();
135+
136+
Set<IAccount> accounts = pca.getAccounts().join();
137+
IAccount account = accounts.stream().filter(
138+
x -> x.username().equalsIgnoreCase(
139+
labResponse.getUser().getUpn())).findFirst().orElse(null);
140+
141+
SilentParameters parameters = SilentParameters.builder(
142+
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), account).
143+
forceRefresh(true).
144+
build();
145+
146+
IAuthenticationResult result = pca.acquireTokenSilently(parameters).get();
147+
148+
Assert.assertNotNull(result);
149+
Assert.assertNotNull(result.accessToken());
150+
Assert.assertNotNull(result.idToken());
151+
Assert.assertEquals(result.account().username(), labResponse.getUser().getUpn());
152+
}
153+
154+
private IPublicClientApplication getPublicClientApplicationWithTokensInCache()
155+
throws Exception {
156+
LabResponse labResponse = labUserProvider.getDefaultUser(
157+
NationalCloud.AZURE_CLOUD,
158+
false);
159+
String password = labUserProvider.getUserPassword(labResponse.getUser());
160+
161+
PublicClientApplication pca = new PublicClientApplication.Builder(
162+
labResponse.getAppId()).
163+
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
164+
build();
165+
166+
pca.acquireToken(UserNamePasswordParameters.
167+
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
168+
labResponse.getUser().getUpn(),
169+
password.toCharArray())
170+
.build())
171+
.get();
172+
return pca;
173+
}
174+
}

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

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// All rights reserved.
3-
//
4-
// This code is licensed under the MIT License.
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files(the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions :
12-
//
13-
// The above copyright notice and this permission notice shall be included in
14-
// all copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
// THE SOFTWARE.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
233

244
package com.microsoft.aad.msal4j;
255

@@ -41,7 +21,6 @@
4121
import org.testng.util.Strings;
4222

4323
import java.io.UnsupportedEncodingException;
44-
import java.net.MalformedURLException;
4524
import java.net.URI;
4625
import java.net.URLEncoder;
4726
import java.util.Collections;
@@ -247,7 +226,7 @@ private IAuthenticationResult acquireTokenInteractiveAAD(
247226
try {
248227
PublicClientApplication pca = PublicClientApplication.builder(
249228
labResponse.getAppId()).
250-
authority(TestConstants.AUTHORITY_ORGANIZATIONS).
229+
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
251230
build();
252231

253232
result = pca.acquireToken(AuthorizationCodeParameters
@@ -388,7 +367,7 @@ private String buildAuthenticationCodeURL(String appId, AuthorityType authorityT
388367
String authority;
389368
String scope;
390369
if(authorityType == AuthorityType.AAD){
391-
authority = TestConstants.AUTHORITY_ORGANIZATIONS;
370+
authority = TestConstants.ORGANIZATIONS_AUTHORITY;
392371
scope = TestConstants.GRAPH_DEFAULT_SCOPE;
393372
} else {
394373
authority = TestConstants.B2C_AUTHORITY_URL;

src/integrationtest/java/com.microsoft.aad.msal4j/CachePersistenceIntegrationTest.java renamed to src/integrationtest/java/com.microsoft.aad.msal4j/CachePersistenceIT.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
// Copyright (c) Microsoft Corporation.
2-
// All rights reserved.
3-
//
4-
// This code is licensed under the MIT License.
5-
//
6-
// Permission is hereby granted, free of charge, to any person obtaining a copy
7-
// of this software and associated documentation files(the "Software"), to deal
8-
// in the Software without restriction, including without limitation the rights
9-
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10-
// copies of the Software, and to permit persons to whom the Software is
11-
// furnished to do so, subject to the following conditions :
12-
//
13-
// The above copyright notice and this permission notice shall be included in
14-
// all copies or substantial portions of the Software.
15-
//
16-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
// THE SOFTWARE.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
233
package com.microsoft.aad.msal4j;
244

255
import org.testng.Assert;
@@ -28,12 +8,15 @@
288
import java.io.IOException;
299
import java.net.URISyntaxException;
3010

31-
public class CachePersistenceIntegrationTest {
11+
public class CachePersistenceIT {
12+
3213
static class TokenPersistence implements ITokenCacheAccessAspect{
14+
String data;
15+
3316
TokenPersistence(String data){
3417
this.data = data;
3518
}
36-
String data;
19+
3720
@Override
3821
public void beforeCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext){
3922
iTokenCacheAccessContext.tokenCache().deserialize(data);
@@ -44,6 +27,7 @@ public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext)
4427
data = iTokenCacheAccessContext.tokenCache().serialize();
4528
}
4629
}
30+
4731
@Test
4832
public void cacheDeserializationSerializationTest() throws IOException, URISyntaxException {
4933
String dataToInitCache = TestHelper.readResource(this.getClass(), "/cache_data/serialized_cache.json");

0 commit comments

Comments
 (0)