Skip to content

Commit 0be9086

Browse files
authored
Merge pull request #122 from AzureAD/dev
0.7.0-preview release
2 parents b639337 + e767eb9 commit 0be9086

Some content is hidden

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

43 files changed

+423
-257
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.6.0-preview
14+
Current version - 0.7.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

@@ -23,13 +23,13 @@ The library is currently in preview. During the preview we reserve the right to
2323
<dependency>
2424
<groupId>com.microsoft.azure</groupId>
2525
<artifactId>msal4j</artifactId>
26-
<version>0.6.0-preview</version>
26+
<version>0.7.0-preview</version>
2727
</dependency>
2828
```
2929
### Gradle
3030

3131
```
32-
compile group: 'com.microsoft.azure', name: 'msal4j', version: '0.6.0-preview'
32+
compile group: 'com.microsoft.azure', name: 'msal4j', version: '0.7.0-preview'
3333
```
3434

3535
## Contribution

changelog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Version 0.7.0-preview
2+
=============
3+
- Added support for ClientAssertions in ClientCredentialFactory
4+
- Renamed AsymmetricKeyCredential to ClientCertificate
5+
- Made Account, IClientApplicationBase, TelemetryConsumer ClientSecret, ClientCertificate, ClientAssertion package-private
6+
- Added IClientSecret, IClientCertificate, IClientAssertion
7+
18
Version 0.6.0-preview
29
=============
310
- Updated TokenCache to be thread safe

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.6.0-preview</version>
6+
<version>0.7.0-preview</version>
77
<packaging>jar</packaging>
88
<name>msal4j</name>
99
<description>

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

Lines changed: 87 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package com.microsoft.aad.msal4j;
55

6+
import labapi.AppIdentityProvider;
67
import labapi.FederationProvider;
78
import labapi.LabResponse;
89
import labapi.LabUserProvider;
@@ -13,6 +14,10 @@
1314

1415
import java.util.Collections;
1516
import java.util.Set;
17+
import java.util.concurrent.ExecutionException;
18+
19+
import static com.microsoft.aad.msal4j.TestConstants.GRAPH_DEFAULT_SCOPE;
20+
import static com.microsoft.aad.msal4j.TestConstants.KEYVAULT_DEFAULT_SCOPE;
1621

1722
public class AcquireTokenSilentIT {
1823
private LabUserProvider labUserProvider;
@@ -51,7 +56,7 @@ public void acquireTokenSilent_LabAuthority_TokenNotRefreshed() throws Exception
5156
String password = labUserProvider.getUserPassword(labResponse.getUser());
5257
String labAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + labResponse.getUser().getTenantId();
5358

54-
PublicClientApplication pca = new PublicClientApplication.Builder(
59+
PublicClientApplication pca = PublicClientApplication.builder(
5560
labResponse.getAppId()).
5661
authority(labAuthority).
5762
build();
@@ -85,7 +90,7 @@ public void acquireTokenSilent_ForceRefresh() throws Exception {
8590
false);
8691
String password = labUserProvider.getUserPassword(labResponse.getUser());
8792

88-
PublicClientApplication pca = new PublicClientApplication.Builder(
93+
PublicClientApplication pca = PublicClientApplication.builder(
8994
labResponse.getAppId()).
9095
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
9196
build();
@@ -151,50 +156,85 @@ public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount() throw
151156
Assert.assertEquals(result.account().username(), labResponse.getUser().getUpn());
152157
}
153158

154-
private IPublicClientApplication getPublicClientApplicationWithTokensInCache()
155-
throws Exception {
159+
@Test
160+
public void acquireTokenSilent_usingCommonAuthority_returnCachedAt() throws Exception {
161+
acquireTokenSilent_returnCachedTokens(TestConstants.ORGANIZATIONS_AUTHORITY);
162+
}
163+
164+
@Test
165+
public void acquireTokenSilent_usingTenantSpecificAuthority_returnCachedAt() throws Exception {
156166
LabResponse labResponse = labUserProvider.getDefaultUser(
157167
NationalCloud.AZURE_CLOUD,
158168
false);
159-
String password = labUserProvider.getUserPassword(labResponse.getUser());
169+
String tenantSpecificAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + labResponse.getUser().getTenantId();
170+
acquireTokenSilent_returnCachedTokens(tenantSpecificAuthority);
171+
}
160172

161-
PublicClientApplication pca = new PublicClientApplication.Builder(
162-
labResponse.getAppId()).
163-
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
164-
build();
173+
@Test
174+
public void acquireTokenSilent_ConfidentialClient_acquireTokenSilent() throws Exception{
165175

166-
pca.acquireToken(UserNamePasswordParameters.
167-
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
168-
labResponse.getUser().getUpn(),
169-
password.toCharArray())
176+
IConfidentialClientApplication cca = getConfidentialClientApplications();
177+
178+
IAuthenticationResult result = cca.acquireToken(ClientCredentialParameters
179+
.builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE))
170180
.build())
171181
.get();
172-
return pca;
182+
183+
Assert.assertNotNull(result);
184+
Assert.assertNotNull(result.accessToken());
185+
186+
String cachedAt = result.accessToken();
187+
188+
result = cca.acquireTokenSilently(SilentParameters
189+
.builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE))
190+
.build())
191+
.get();
192+
193+
Assert.assertNotNull(result);
194+
Assert.assertEquals(result.accessToken(), cachedAt);
173195
}
174196

175-
@Test
176-
private void acquireTokenSilent_usingCommonAuthority_returnCachedAt() throws Exception {
177-
acquireTokenSilent_returnCachedTokens(TestConstants.ORGANIZATIONS_AUTHORITY);
197+
@Test(expectedExceptions = ExecutionException.class)
198+
public void acquireTokenSilent_ConfidentialClient_acquireTokenSilentDifferentScopeThrowsException()
199+
throws Exception {
200+
201+
IConfidentialClientApplication cca = getConfidentialClientApplications();
202+
203+
IAuthenticationResult result = cca.acquireToken(ClientCredentialParameters
204+
.builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE))
205+
.build())
206+
.get();
207+
208+
Assert.assertNotNull(result);
209+
Assert.assertNotNull(result.accessToken());
210+
211+
//Acquiring token for different scope, expect exception to be thrown
212+
cca.acquireTokenSilently(SilentParameters
213+
.builder(Collections.singleton(GRAPH_DEFAULT_SCOPE))
214+
.build())
215+
.get();
178216
}
179217

180-
@Test
181-
private void acquireTokenSilent_usingTenantSpecificAuthority_returnCachedAt() throws Exception {
182-
LabResponse labResponse = labUserProvider.getDefaultUser(
183-
NationalCloud.AZURE_CLOUD,
184-
false);
185-
String tenantSpecificAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + labResponse.getUser().getTenantId();
218+
private IConfidentialClientApplication getConfidentialClientApplications() throws Exception{
219+
AppIdentityProvider appProvider = new AppIdentityProvider();
220+
final String clientId = appProvider.getDefaultLabId();
221+
final String password = appProvider.getDefaultLabPassword();
222+
IClientCredential credential = ClientCredentialFactory.createFromSecret(password);
186223

187-
acquireTokenSilent_returnCachedTokens(tenantSpecificAuthority);
224+
return ConfidentialClientApplication.builder(
225+
clientId, credential).
226+
authority(TestConstants.MICROSOFT_AUTHORITY).
227+
build();
188228
}
189229

190-
void acquireTokenSilent_returnCachedTokens(String authority) throws Exception {
230+
private void acquireTokenSilent_returnCachedTokens(String authority) throws Exception {
191231

192232
LabResponse labResponse = labUserProvider.getDefaultUser(
193233
NationalCloud.AZURE_CLOUD,
194234
false);
195235
String password = labUserProvider.getUserPassword(labResponse.getUser());
196236

197-
PublicClientApplication pca = new PublicClientApplication.Builder(
237+
PublicClientApplication pca = PublicClientApplication.builder(
198238
labResponse.getAppId()).
199239
authority(authority).
200240
build();
@@ -217,4 +257,25 @@ void acquireTokenSilent_returnCachedTokens(String authority) throws Exception {
217257
Assert.assertNotNull(silentAuthResult);
218258
Assert.assertEquals(interactiveAuthResult.accessToken(), silentAuthResult.accessToken());
219259
}
260+
261+
private IPublicClientApplication getPublicClientApplicationWithTokensInCache()
262+
throws Exception {
263+
LabResponse labResponse = labUserProvider.getDefaultUser(
264+
NationalCloud.AZURE_CLOUD,
265+
false);
266+
String password = labUserProvider.getUserPassword(labResponse.getUser());
267+
268+
PublicClientApplication pca = PublicClientApplication.builder(
269+
labResponse.getAppId()).
270+
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
271+
build();
272+
273+
pca.acquireToken(
274+
UserNamePasswordParameters.builder(
275+
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
276+
labResponse.getUser().getUpn(),
277+
password.toCharArray())
278+
.build()).get();
279+
return pca;
280+
}
220281
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private IAuthenticationResult acquireTokenInteractiveB2C(LabResponse labResponse
247247
String authCode) {
248248
IAuthenticationResult result;
249249
try{
250-
IClientCredential credential = ClientCredentialFactory.create("");
250+
IClientCredential credential = ClientCredentialFactory.createFromSecret("");
251251
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(
252252
labResponse.getAppId(),
253253
credential)

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import java.security.cert.X509Certificate;
1919
import java.util.Collections;
2020

21-
import static com.microsoft.aad.msal4j.TestConstants.GRAPH_DEFAULT_SCOPE;
2221
import static com.microsoft.aad.msal4j.TestConstants.KEYVAULT_DEFAULT_SCOPE;
2322

2423
@Test
2524
public class ClientCredentialsIT {
25+
2626
@Test
27-
public void acquireTokenClientCredentials_AsymmetricKeyCredential() throws Exception{
27+
public void acquireTokenClientCredentials_ClientCertificate() throws Exception{
2828
String clientId = "55e7e5af-ca53-482d-9aa3-5cb1cc8eecb5";
2929
IClientCredential credential = getCertificateFromKeyStore();
3030
assertAcquireTokenCommon(clientId, credential);
@@ -35,13 +35,30 @@ public void acquireTokenClientCredentials_ClientSecret() throws Exception{
3535
AppIdentityProvider appProvider = new AppIdentityProvider();
3636
final String clientId = appProvider.getDefaultLabId();
3737
final String password = appProvider.getDefaultLabPassword();
38-
IClientCredential credential = ClientCredentialFactory.create(password);
38+
IClientCredential credential = ClientCredentialFactory.createFromSecret(password);
39+
40+
assertAcquireTokenCommon(clientId, credential);
41+
}
42+
43+
@Test
44+
public void acquireTokenClientCredentials_ClientAssertion() throws Exception{
45+
String clientId = "55e7e5af-ca53-482d-9aa3-5cb1cc8eecb5";
46+
IClientCredential certificateFromKeyStore = getCertificateFromKeyStore();
47+
48+
ClientAssertion clientAssertion = JwtHelper.buildJwt(
49+
clientId,
50+
(ClientCertificate) certificateFromKeyStore,
51+
"https://login.microsoftonline.com/common/oauth2/v2.0/token");
52+
53+
54+
IClientCredential credential = ClientCredentialFactory.createFromClientAssertion(
55+
clientAssertion.assertion());
3956

4057
assertAcquireTokenCommon(clientId, credential);
4158
}
4259

4360
private void assertAcquireTokenCommon(String clientId, IClientCredential credential) throws Exception{
44-
ConfidentialClientApplication cca = new ConfidentialClientApplication.Builder(
61+
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(
4562
clientId, credential).
4663
authority(TestConstants.MICROSOFT_AUTHORITY).
4764
build();
@@ -53,26 +70,8 @@ private void assertAcquireTokenCommon(String clientId, IClientCredential credent
5370

5471
Assert.assertNotNull(result);
5572
Assert.assertNotNull(result.accessToken());
56-
57-
String cachedAt = result.accessToken();
58-
59-
result = cca.acquireTokenSilently(SilentParameters
60-
.builder(Collections.singleton(GRAPH_DEFAULT_SCOPE))
61-
.build())
62-
.get();
63-
64-
Assert.assertNull(result);
65-
66-
result = cca.acquireTokenSilently(SilentParameters
67-
.builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE))
68-
.build())
69-
.get();
70-
71-
Assert.assertNotNull(result);
72-
Assert.assertEquals(result.accessToken(), cachedAt);
7373
}
7474

75-
7675
private IClientCredential getCertificateFromKeyStore() throws
7776
NoSuchProviderException, KeyStoreException, IOException, NoSuchAlgorithmException,
7877
CertificateException, UnrecoverableKeyException {
@@ -84,6 +83,6 @@ private IClientCredential getCertificateFromKeyStore() throws
8483
X509Certificate publicCertificate = (X509Certificate)keystore.getCertificate(
8584
certificateAlias);
8685

87-
return ClientCredentialFactory.create(key, publicCertificate);
86+
return ClientCredentialFactory.createFromCertificate(key, publicCertificate);
8887
}
8988
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void DeviceCodeFlowTest() throws Exception {
4242
false);
4343
labUserProvider.getUserPassword(labResponse.getUser());
4444

45-
PublicClientApplication pca = new PublicClientApplication.Builder(
45+
PublicClientApplication pca = PublicClientApplication.builder(
4646
labResponse.getAppId()).
4747
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
4848
build();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private void assertAcquireTokenCommon(NationalCloud cloud) throws Exception{
4141
false);
4242
String password = labUserProvider.getUserPassword(labResponse.getUser());
4343

44-
PublicClientApplication pca = new PublicClientApplication.Builder(
44+
PublicClientApplication pca = PublicClientApplication.builder(
4545
labResponse.getAppId()).
4646
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
4747
build();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void acquireTokenWithOBO_Managed() throws Exception {
5050
final String password = appProvider.getOboPassword();
5151

5252
ConfidentialClientApplication cca =
53-
ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.create(password)).
53+
ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.createFromSecret(password)).
5454
authority(msidlab4Authority).
5555
build();
5656

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void setUp() throws Exception {
2626
NationalCloud.AZURE_CLOUD,
2727
false);
2828
String password = labUserProvider.getUserPassword(labResponse.getUser());
29-
pca = new PublicClientApplication.Builder(
29+
pca = PublicClientApplication.builder(
3030
labResponse.getAppId()).
3131
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
3232
build();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void singleAccountInCache_RemoveAccountTest() throws Exception {
3030
false);
3131
String password = labUserProvider.getUserPassword(labResponse.getUser());
3232

33-
PublicClientApplication pca = new PublicClientApplication.Builder(
33+
PublicClientApplication pca = PublicClientApplication.builder(
3434
labResponse.getAppId()).
3535
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
3636
build();
@@ -62,7 +62,7 @@ public void twoAccountsInCache_RemoveAccountTest() throws Exception{
6262
false);
6363
String password = labUserProvider.getUserPassword(labResponse1.getUser());
6464

65-
PublicClientApplication pca = new PublicClientApplication.Builder(
65+
PublicClientApplication pca = PublicClientApplication.builder(
6666
labResponse1.getAppId()).
6767
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
6868
build();
@@ -125,7 +125,7 @@ public void twoAccountsInCache_SameUserDifferentTenants_RemoveAccountTest() thro
125125
ITokenCacheAccessAspect persistenceAspect = new TokenPersistence(dataToInitCache);
126126

127127
// acquire tokens for home tenant, and serialize cache
128-
PublicClientApplication pca = new PublicClientApplication.Builder(
128+
PublicClientApplication pca = PublicClientApplication.builder(
129129
labResponse.getAppId()).
130130
authority(TestConstants.ORGANIZATIONS_AUTHORITY)
131131
.setTokenCacheAccessAspect(persistenceAspect)
@@ -141,7 +141,7 @@ public void twoAccountsInCache_SameUserDifferentTenants_RemoveAccountTest() thro
141141
String guestTenantAuthority = TestConstants.MICROSOFT_AUTHORITY_HOST + labResponse.getUser().getTenantId();
142142

143143
// initialize pca with tenant where user is guest, deserialize cache, and acquire second token
144-
PublicClientApplication pca2 = new PublicClientApplication.Builder(
144+
PublicClientApplication pca2 = PublicClientApplication.builder(
145145
labResponse.getAppId()).
146146
authority(guestTenantAuthority).
147147
setTokenCacheAccessAspect(persistenceAspect).

0 commit comments

Comments
 (0)