-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from AzureAD/dev
0.5.0-preview release
- Loading branch information
Showing
185 changed files
with
1,888 additions
and
4,401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
`master` branch | `dev` branch | Reference Docs | ||
--------------------|-----------------|--------------- | ||
[![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) | ||
[![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) | ||
|
||
|[Getting Started](https://github.com/AzureAD/microsoft-authentication-library-for-java/wiki)| [Docs](https://aka.ms/aaddev)| [Support](README.md#community-help-and-support) | ||
| --- | --- | --- | | ||
|
@@ -11,7 +11,7 @@ The MSAL library for Java gives your app the ability to begin using the Microsof | |
|
||
|
||
## Versions | ||
Current version - 0.4.0-preview | ||
Current version - 0.5.0-preview | ||
|
||
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). | ||
|
||
|
@@ -43,4 +43,4 @@ If you find a security issue with our libraries or services please report it to | |
|
||
## We Value and Adhere to the Microsoft Open Source Code of Conduct | ||
|
||
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. | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
src/integrationtest/java/com.microsoft.aad.msal4j/AcquireTokenSilentIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.aad.msal4j; | ||
|
||
import labapi.FederationProvider; | ||
import labapi.LabResponse; | ||
import labapi.LabUserProvider; | ||
import labapi.NationalCloud; | ||
import org.testng.Assert; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class AcquireTokenSilentIT { | ||
private LabUserProvider labUserProvider; | ||
|
||
@BeforeClass | ||
public void setUp() { | ||
labUserProvider = LabUserProvider.getInstance(); | ||
} | ||
|
||
@Test | ||
public void acquireTokenSilent_OrganizationAuthority_TokenRefreshed() throws Exception { | ||
|
||
// When using common, organization, or consumer tenants, cache has no way | ||
// of determining which access token to return therefore token is always refreshed | ||
IPublicClientApplication pca = getPublicClientApplicationWithTokensInCache(); | ||
|
||
IAccount account = pca.getAccounts().join().iterator().next(); | ||
SilentParameters parameters = SilentParameters.builder( | ||
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), | ||
account).build(); | ||
|
||
IAuthenticationResult result = pca.acquireTokenSilently(parameters).get(); | ||
|
||
Assert.assertNotNull(result); | ||
Assert.assertNotNull(result.accessToken()); | ||
Assert.assertNotNull(result.idToken()); | ||
} | ||
|
||
@Test | ||
public void acquireTokenSilent_LabAuthority_TokenNotRefreshed() throws Exception { | ||
// Access token should be returned from cache, and not using refresh token | ||
|
||
LabResponse labResponse = labUserProvider.getDefaultUser( | ||
NationalCloud.AZURE_CLOUD, | ||
false); | ||
String password = labUserProvider.getUserPassword(labResponse.getUser()); | ||
String labAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + labResponse.getUser().getTenantId(); | ||
|
||
PublicClientApplication pca = new PublicClientApplication.Builder( | ||
labResponse.getAppId()). | ||
authority(labAuthority). | ||
build(); | ||
|
||
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters. | ||
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), | ||
labResponse.getUser().getUpn(), | ||
password.toCharArray()) | ||
.build()) | ||
.get(); | ||
|
||
IAccount account = pca.getAccounts().join().iterator().next(); | ||
SilentParameters parameters = SilentParameters.builder( | ||
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), account). | ||
build(); | ||
|
||
IAuthenticationResult acquireSilentResult = pca.acquireTokenSilently(parameters).get(); | ||
|
||
Assert.assertNotNull(acquireSilentResult.accessToken()); | ||
Assert.assertNotNull(result.idToken()); | ||
// Check that access and id tokens are coming from cache | ||
Assert.assertEquals(result.accessToken(), acquireSilentResult.accessToken()); | ||
Assert.assertEquals(result.idToken(), acquireSilentResult.idToken()); | ||
} | ||
|
||
@Test | ||
public void acquireTokenSilent_ForceRefresh() throws Exception { | ||
|
||
LabResponse labResponse = labUserProvider.getDefaultUser( | ||
NationalCloud.AZURE_CLOUD, | ||
false); | ||
String password = labUserProvider.getUserPassword(labResponse.getUser()); | ||
|
||
PublicClientApplication pca = new PublicClientApplication.Builder( | ||
labResponse.getAppId()). | ||
authority(TestConstants.ORGANIZATIONS_AUTHORITY). | ||
build(); | ||
|
||
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters. | ||
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), | ||
labResponse.getUser().getUpn(), | ||
password.toCharArray()) | ||
.build()) | ||
.get(); | ||
|
||
IAccount account = pca.getAccounts().join().iterator().next(); | ||
SilentParameters parameters = SilentParameters.builder( | ||
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), account). | ||
forceRefresh(true). | ||
build(); | ||
|
||
IAuthenticationResult resultAfterRefresh = pca.acquireTokenSilently(parameters).get(); | ||
|
||
Assert.assertNotNull(resultAfterRefresh); | ||
Assert.assertNotNull(resultAfterRefresh.accessToken()); | ||
Assert.assertNotNull(resultAfterRefresh.idToken()); | ||
// Check that new refresh and id tokens are being returned | ||
Assert.assertNotEquals(result.accessToken(), resultAfterRefresh.accessToken()); | ||
Assert.assertNotEquals(result.idToken(), resultAfterRefresh.idToken()); | ||
} | ||
|
||
@Test | ||
public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount() throws Exception { | ||
|
||
IPublicClientApplication pca = getPublicClientApplicationWithTokensInCache(); | ||
|
||
// get lab user for different account | ||
LabResponse labResponse = labUserProvider.getAdfsUser( | ||
FederationProvider.ADFSV4, | ||
true, | ||
false); | ||
String password = labUserProvider.getUserPassword(labResponse.getUser()); | ||
|
||
// acquire token for different account | ||
pca.acquireToken(UserNamePasswordParameters. | ||
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), | ||
labResponse.getUser().getUpn(), | ||
password.toCharArray()) | ||
.build()) | ||
.get(); | ||
|
||
Set<IAccount> accounts = pca.getAccounts().join(); | ||
IAccount account = accounts.stream().filter( | ||
x -> x.username().equalsIgnoreCase( | ||
labResponse.getUser().getUpn())).findFirst().orElse(null); | ||
|
||
SilentParameters parameters = SilentParameters.builder( | ||
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), account). | ||
forceRefresh(true). | ||
build(); | ||
|
||
IAuthenticationResult result = pca.acquireTokenSilently(parameters).get(); | ||
|
||
Assert.assertNotNull(result); | ||
Assert.assertNotNull(result.accessToken()); | ||
Assert.assertNotNull(result.idToken()); | ||
Assert.assertEquals(result.account().username(), labResponse.getUser().getUpn()); | ||
} | ||
|
||
private IPublicClientApplication getPublicClientApplicationWithTokensInCache() | ||
throws Exception { | ||
LabResponse labResponse = labUserProvider.getDefaultUser( | ||
NationalCloud.AZURE_CLOUD, | ||
false); | ||
String password = labUserProvider.getUserPassword(labResponse.getUser()); | ||
|
||
PublicClientApplication pca = new PublicClientApplication.Builder( | ||
labResponse.getAppId()). | ||
authority(TestConstants.ORGANIZATIONS_AUTHORITY). | ||
build(); | ||
|
||
pca.acquireToken(UserNamePasswordParameters. | ||
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE), | ||
labResponse.getUser().getUpn(), | ||
password.toCharArray()) | ||
.build()) | ||
.get(); | ||
return pca; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.