Skip to content

Commit

Permalink
Merge pull request #78 from AzureAD/dev
Browse files Browse the repository at this point in the history
0.5.0-preview release
  • Loading branch information
sangonzal authored Jul 11, 2019
2 parents 89988f3 + 5232f53 commit 22e4113
Show file tree
Hide file tree
Showing 185 changed files with 1,888 additions and 4,401 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
| --- | --- | --- |
Expand All @@ -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).

Expand Down Expand Up @@ -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.
9 changes: 8 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Version 0.5.0-preview
=============
- Refactored AuthenticationException to MsalServiceException, MsalClientException, MsalInteractionRequiredException
- Added cache lookup to acquireToken by client credentials grant
- Updated Javadoc reference
- Updated license headers

Version 0.4.0-preview
=============
- Exposing acquire token by refresh token api
- Exposed acquire token by refresh token api

Version 0.3.0-preview
=============
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>0.4.0-preview</version>
<version>0.5.0-preview</version>
<packaging>jar</packaging>
<name>msal4j</name>
<description>
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.aad.msal4j;

Expand All @@ -41,7 +21,6 @@
import org.testng.util.Strings;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Collections;
Expand Down Expand Up @@ -247,7 +226,7 @@ private IAuthenticationResult acquireTokenInteractiveAAD(
try {
PublicClientApplication pca = PublicClientApplication.builder(
labResponse.getAppId()).
authority(TestConstants.AUTHORITY_ORGANIZATIONS).
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
build();

result = pca.acquireToken(AuthorizationCodeParameters
Expand Down Expand Up @@ -388,7 +367,7 @@ private String buildAuthenticationCodeURL(String appId, AuthorityType authorityT
String authority;
String scope;
if(authorityType == AuthorityType.AAD){
authority = TestConstants.AUTHORITY_ORGANIZATIONS;
authority = TestConstants.ORGANIZATIONS_AUTHORITY;
scope = TestConstants.GRAPH_DEFAULT_SCOPE;
} else {
authority = TestConstants.B2C_AUTHORITY_URL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;

import org.testng.Assert;
Expand All @@ -28,12 +8,15 @@
import java.io.IOException;
import java.net.URISyntaxException;

public class CachePersistenceIntegrationTest {
public class CachePersistenceIT {

static class TokenPersistence implements ITokenCacheAccessAspect{
String data;

TokenPersistence(String data){
this.data = data;
}
String data;

@Override
public void beforeCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext){
iTokenCacheAccessContext.tokenCache().deserialize(data);
Expand All @@ -44,6 +27,7 @@ public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext)
data = iTokenCacheAccessContext.tokenCache().serialize();
}
}

@Test
public void cacheDeserializationSerializationTest() throws IOException, URISyntaxException {
String dataToInitCache = TestHelper.readResource(this.getClass(), "/cache_data/serialized_cache.json");
Expand Down
Loading

0 comments on commit 22e4113

Please sign in to comment.