Skip to content

1.6 release #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bdab9bd
Update acquireToken interactive public api Id. Update error setting l…
Feb 29, 2020
5fb34ec
support for national cloud integ tesing + arlington tests (#190)
SomkaPe Mar 2, 2020
4e66ed8
Merge pull request #189 from AzureAD/sagonzal/telemetryBug
sangonzal Mar 3, 2020
ba87a8a
Pesomka/comp gov (#194)
SomkaPe Mar 18, 2020
9583cb6
Pesomka/comp gov (#195)
SomkaPe Mar 18, 2020
96575d8
update key vault version
SomkaPe Mar 18, 2020
4fea88b
Update pom.xml
SomkaPe Mar 18, 2020
49ca000
Update DeviceCodeIT.java
SomkaPe Mar 18, 2020
9c84702
Minor typo fix
Avery-Dunn Mar 18, 2020
2eb3fe8
authority Path validation (#202)
SomkaPe Apr 7, 2020
5ac91a5
Fix spelling mistake in AuthenticationErrorMessage
sangonzal Apr 16, 2020
15377ac
Update cache miss log level
Apr 17, 2020
840199f
Merge pull request #215 from AzureAD/sangonzal/fix-spelling-mistake
sangonzal Apr 17, 2020
18e310f
Include MsalServiceException in log error
Apr 21, 2020
1edd2cf
Merge pull request #216 from AzureAD/sagonzal/update-cache-miss-log-l…
sangonzal Apr 22, 2020
bf9ad41
Add client-capabilities optional parameter
Avery-Dunn Apr 30, 2020
2da4bb7
Add tests for client-capabilities
Avery-Dunn Apr 30, 2020
e7d38b8
Better iterator handling
Avery-Dunn Apr 30, 2020
771c12b
Update Nimbus SDK version (#229)
Avery-Dunn May 5, 2020
99dcb7e
Update how successful count is calculated (#225)
sangonzal May 5, 2020
9479deb
Add CodeQL Analysis workflow (#222)
jhutchings1 May 5, 2020
f57d4dd
Fix for private jwt client to rebuild when expired (#221)
Budlee May 5, 2020
5b86ce3
Move CodeQL action (#230)
jhutchings1 May 5, 2020
8a79bc8
support of STS throttling instructions + caching of InteractionRequir…
SomkaPe May 5, 2020
7102501
Refactor claims-and-capabilities test case
Avery-Dunn May 5, 2020
47eb200
Code cleanup
Avery-Dunn May 5, 2020
5378764
Refactor variable to TestConstants
Avery-Dunn May 6, 2020
22d940a
Remove need for null checks
Avery-Dunn May 6, 2020
faa730d
Merge pull request #234 from AzureAD/master
sangonzal May 7, 2020
ddaf080
Refactor claims and capabilities parameters
Avery-Dunn May 13, 2020
d890075
Add claims and capabilities parameters
Avery-Dunn May 13, 2020
b3f4146
Fix capabilities test
Avery-Dunn May 13, 2020
c2f97c3
Handle null exception
Avery-Dunn May 18, 2020
482d2cc
Move client capabilities to application level
Avery-Dunn May 20, 2020
713c497
Improve claims/capabilities test coverage
Avery-Dunn May 20, 2020
122789f
Disable claims/capabilities test
Avery-Dunn May 21, 2020
2091cb8
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
Avery-Dunn May 21, 2020
a297942
Fix merge conflict
Avery-Dunn May 21, 2020
3af478d
Deprecate claims parameter and refactor into claimsChallenge
Avery-Dunn May 22, 2020
9edf87c
Add client capabilities to token endpoint request
Avery-Dunn May 26, 2020
2fd7db4
Merge pull request #226 from AzureAD/avdunn/claims-and-capabilities
Avery-Dunn May 26, 2020
06fe229
Enable device code flow for ADFS 2019
Avery-Dunn May 29, 2020
a662ad5
Re-add exception throw when B2C is used with device code flow
Avery-Dunn Jun 1, 2020
5c23462
Refactor for clarity and better code practices
Avery-Dunn Jun 1, 2020
7b41d7d
Refactor for clarity and better code practices
Avery-Dunn Jun 2, 2020
57238cb
Refactor for clarity and better code practices
Avery-Dunn Jun 2, 2020
df4e339
Merge pull request #241 from AzureAD/avdunn/adfs-devicecode
Avery-Dunn Jun 2, 2020
6deb186
compatibility with jackson 2.6.7 and json-smart 1.3.1 (#242)
SomkaPe Jun 3, 2020
21f253e
using certificate from Key Vault for unit testing (#243)
SomkaPe Jun 3, 2020
b8e1551
1.6 release (#244)
SomkaPe Jun 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Quick links:
The library supports the following Java environments:
- Java 8 (or higher)

Current version - 1.5.0
Current version - 1.6.0

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 All @@ -28,13 +28,13 @@ Find [the latest package in the Maven repository](https://mvnrepository.com/arti
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.5.0</version>
<version>1.6.0</version>
</dependency>
```
### Gradle

```
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.5.0'
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.6.0'
```

## Usage
Expand Down
20 changes: 0 additions & 20 deletions build/credscan-exclude.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
{
"tool": "Credential Scanner",
"suppressions": [
{
"file": "test-certificate.pfx",
"_justification": "test self signed certificate to test signing from the library. this certificate is not associated with any tenant"
},
{
"placeholder": "client_secret",
"_justification" : "credential used for testing. not associated with any tenant"
},
{
"placeholder": "ClientPassword",
"_justification" : "credential used for testing. not associated with any tenant"
},
{
"placeholder": "B2C_CONFIDENTIAL_CLIENT_APP_SECRET",
"_justification" : "Not a credential, just the identifier of the secret exposed by test lab API"
},
{
"placeholder": "MSIDLABB2C-MSAapp-AppSecret",
"_justification" : "Not a credential, just the identifier of the secret exposed by test lab API"
}
]
}
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 1.6.0
=============
- Client capabilities support
- Enable device code flow for ADFS2019
- Fix dependency issues with jackson 2.6.7 and json-smart 1.3.1

Version 1.5.0
=============
- Support of server side throttling instructions
Expand Down
1 change: 0 additions & 1 deletion lombok.config

This file was deleted.

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>1.5.0</version>
<version>1.6.0</version>
<packaging>jar</packaging>
<name>msal4j</name>
<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -27,7 +29,22 @@ public void acquireTokenWithAuthorizationCode_ManagedUser(String environment){
cfg = new Config(environment);

User user = labUserProvider.getDefaultUser(cfg.azureEnvironment);
assertAcquireTokenAAD(user);
assertAcquireTokenAAD(user, null);
}

//TODO: Re-enable test once list of claims/capabilities and their expected behavior is known
//@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenWithAuthorizationCode_ManagedUserWithClaimsAndCapabilities(String environment){
cfg = new Config(environment);

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

Map<String, Set<String>> claimsAndCapabilities = new HashMap<>();

claimsAndCapabilities.put("claims", Collections.singleton(TestConstants.CLAIMS));
claimsAndCapabilities.put("clientCapabilities", TestConstants.CLIENT_CAPABILITIES_EMPTY);

assertAcquireTokenAAD(user, claimsAndCapabilities);
}

@Test
Expand All @@ -41,7 +58,7 @@ public void acquireTokenWithAuthorizationCode_ADFSv2019_Federated(String environ
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2019);
assertAcquireTokenAAD(user);
assertAcquireTokenAAD(user, null);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
Expand All @@ -50,23 +67,23 @@ public void acquireTokenWithAuthorizationCode_ADFSv4_Federated(String environmen

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_4);

assertAcquireTokenAAD(user);
assertAcquireTokenAAD(user, null);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenWithAuthorizationCode_ADFSv3_Federated(String environment){
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_3);
assertAcquireTokenAAD(user);
assertAcquireTokenAAD(user, null);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
public void acquireTokenWithAuthorizationCode_ADFSv2_Federated(String environment){
cfg = new Config(environment);

User user = labUserProvider.getFederatedAdfsUser(cfg.azureEnvironment, FederationProvider.ADFS_2);
assertAcquireTokenAAD(user);
assertAcquireTokenAAD(user, null);
}

@Test(dataProvider = "environments", dataProviderClass = EnvironmentsProvider.class)
Expand Down Expand Up @@ -119,7 +136,7 @@ private void assertAcquireTokenADFS2019(User user){
throw new RuntimeException(ex.getMessage());
}

String authCode = acquireAuthorizationCodeAutomated(user, pca);
String authCode = acquireAuthorizationCodeAutomated(user, pca, null);
IAuthenticationResult result = acquireTokenAuthorizationCodeFlow(
pca,
authCode,
Expand All @@ -131,19 +148,24 @@ private void assertAcquireTokenADFS2019(User user){
Assert.assertEquals(user.getUpn(), result.account().username());
}

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

PublicClientApplication pca;
Set<String> clientCapabilities = null;
if (parameters != null) {
clientCapabilities = parameters.getOrDefault("clientCapabilities", null);
}
try {
pca = PublicClientApplication.builder(
user.getAppId()).
authority(cfg.organizationsAuthority()).
build();
pca = PublicClientApplication.builder(
user.getAppId()).
authority(cfg.organizationsAuthority()).
clientCapabilities(clientCapabilities).
build();
} catch(MalformedURLException ex){
throw new RuntimeException(ex.getMessage());
}

String authCode = acquireAuthorizationCodeAutomated(user, pca);
String authCode = acquireAuthorizationCodeAutomated(user, pca, parameters);
IAuthenticationResult result = acquireTokenAuthorizationCodeFlow(
pca,
authCode,
Expand All @@ -158,7 +180,7 @@ private void assertAcquireTokenAAD(User user){
private void assertAcquireTokenB2C(User user){

String appId = LabService.getSecret(TestConstants.B2C_CONFIDENTIAL_CLIENT_LAB_APP_ID);
String appSecret = LabService.getSecret(TestConstants.B2C_CONFIDENTIAL_CLIENT_APP_SECRET);
String appSecret = LabService.getSecret(TestConstants.B2C_CONFIDENTIAL_CLIENT_APP_SECRETID);

ConfidentialClientApplication cca;
try {
Expand All @@ -171,7 +193,7 @@ private void assertAcquireTokenB2C(User user){
throw new RuntimeException(ex.getMessage());
}

String authCode = acquireAuthorizationCodeAutomated(user, cca);
String authCode = acquireAuthorizationCodeAutomated(user, cca, null);
IAuthenticationResult result = acquireTokenInteractiveB2C(cca, authCode);

Assert.assertNotNull(result);
Expand Down Expand Up @@ -218,7 +240,8 @@ private IAuthenticationResult acquireTokenInteractiveB2C(ConfidentialClientAppli

private String acquireAuthorizationCodeAutomated(
User user,
AbstractClientApplicationBase app){
AbstractClientApplicationBase app,
Map<String, Set<String>> parameters){

BlockingQueue<AuthorizationResult> authorizationCodeQueue = new LinkedBlockingQueue<>();

Expand All @@ -231,7 +254,7 @@ private String acquireAuthorizationCodeAutomated(

AuthorizationResult result = null;
try {
String url = buildAuthenticationCodeURL(app);
String url = buildAuthenticationCodeURL(app, parameters);
seleniumDriver.navigate().to(url);
runSeleniumAutomatedLogin(user, app);

Expand All @@ -256,9 +279,15 @@ private String acquireAuthorizationCodeAutomated(
}
return result.code();
}
private String buildAuthenticationCodeURL(AbstractClientApplicationBase app) {

private String buildAuthenticationCodeURL(AbstractClientApplicationBase app, Map<String, Set<String>> parameters) {
String scope;

String claims = null;
if (parameters != null) {
claims = String.valueOf(parameters.getOrDefault("claims", Collections.singleton("")).toArray()[0]);
}

AuthorityType authorityType= app.authenticationAuthority.authorityType;
if(authorityType == AuthorityType.AAD){
scope = TestConstants.GRAPH_DEFAULT_SCOPE;
Expand All @@ -272,12 +301,13 @@ else if (authorityType == AuthorityType.ADFS){
throw new RuntimeException("Authority type not recognized");
}

AuthorizationRequestUrlParameters parameters =
AuthorizationRequestUrlParameters authParameters =
AuthorizationRequestUrlParameters
.builder(TestConstants.LOCALHOST + httpListener.port(),
Collections.singleton(scope))
.claimsChallenge(claims)
.build();

return app.getAuthorizationRequestUrl(parameters).toString();
return app.getAuthorizationRequestUrl(authParameters).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.aad.msal4j;

import labapi.KeyVaultSecretsProvider;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public class CertificateHelper {
static KeyStore createKeyStore() throws KeyStoreException, NoSuchProviderException {
String os = SystemUtils.OS_NAME;
if(os.contains("Mac")){
return KeyStore.getInstance("KeychainStore");
}
else{
return KeyStore.getInstance("Windows-MY", "SunMSCAPI");
}
}

static IClientCertificate getClientCertificate() throws
KeyStoreException, IOException, NoSuchAlgorithmException,
CertificateException, UnrecoverableKeyException, NoSuchProviderException {

KeyStore keystore = createKeyStore();

keystore.load(null, null);

PrivateKey key = (PrivateKey) keystore.getKey(KeyVaultSecretsProvider.CERTIFICATE_ALIAS, null);
X509Certificate publicCertificate = (X509Certificate) keystore.getCertificate(
KeyVaultSecretsProvider.CERTIFICATE_ALIAS);

return ClientCredentialFactory.createFromCertificate(key, publicCertificate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@

import labapi.AppCredentialProvider;
import labapi.AzureEnvironment;
import labapi.KeyVaultSecretsProvider;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Collections;

import static com.microsoft.aad.msal4j.TestConstants.KEYVAULT_DEFAULT_SCOPE;

@Test
public class ClientCredentialsIT {
private IClientCertificate certificate;

@BeforeClass
void init() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException {
certificate = CertificateHelper.getClientCertificate();
}

@Test
public void acquireTokenClientCredentials_ClientCertificate() throws Exception{
String clientId = "55e7e5af-ca53-482d-9aa3-5cb1cc8eecb5";
IClientCredential credential = getCertificateFromKeyStore();
assertAcquireTokenCommon(clientId, credential);
assertAcquireTokenCommon(clientId, certificate);
}

@Test
Expand All @@ -45,11 +47,10 @@ public void acquireTokenClientCredentials_ClientSecret() throws Exception{
@Test
public void acquireTokenClientCredentials_ClientAssertion() throws Exception{
String clientId = "55e7e5af-ca53-482d-9aa3-5cb1cc8eecb5";
IClientCredential certificateFromKeyStore = getCertificateFromKeyStore();

ClientAssertion clientAssertion = JwtHelper.buildJwt(
clientId,
(ClientCertificate) certificateFromKeyStore,
(ClientCertificate) certificate,
"https://login.microsoftonline.com/common/oauth2/v2.0/token");

IClientCredential credential = ClientCredentialFactory.createFromClientAssertion(
Expand All @@ -72,17 +73,4 @@ private void assertAcquireTokenCommon(String clientId, IClientCredential credent
Assert.assertNotNull(result);
Assert.assertNotNull(result.accessToken());
}

private IClientCredential getCertificateFromKeyStore() throws
NoSuchProviderException, KeyStoreException, IOException, NoSuchAlgorithmException,
CertificateException, UnrecoverableKeyException {
KeyStore keystore = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
keystore.load(null, null);

PrivateKey key = (PrivateKey)keystore.getKey(KeyVaultSecretsProvider.CERTIFICATE_ALIAS, null);
X509Certificate publicCertificate = (X509Certificate)keystore.getCertificate(
KeyVaultSecretsProvider.CERTIFICATE_ALIAS);

return ClientCredentialFactory.createFromCertificate(key, publicCertificate);
}
}
Loading