Skip to content

Commit c778aa0

Browse files
committed
Merge branch 'avdunn/msalruntime-broker' of https://github.com/AzureAD/microsoft-authentication-library-for-java into avdunn/msalruntime-broker
# Conflicts: # msal4j-brokers/pom.xml
2 parents 8c647a8 + b27c81b commit c778aa0

File tree

71 files changed

+1865
-267
lines changed

Some content is hidden

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

71 files changed

+1865
-267
lines changed

README.md

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

33
`main` branch | `dev` branch | Reference Docs
44
--------------------|-----------------|---------------
5-
[![Build status](https://identitydivision.visualstudio.com/IDDP/_apis/build/status/CI/Java/MSAL%20Java%20CI%20Build?branchName=main)](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/com.microsoft.aad.msal4j.svg)](http://javadoc.io/doc/com.microsoft.azure/com.microsoft.aad.msal4j)
5+
[![Build status](https://identitydivision.visualstudio.com/IDDP/_apis/build/status/CI/Java/MSAL%20Java%20CI%20Build?branchName=main)](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)| [MSAL Java reference](https://learn.microsoft.com/en-us/java/api/com.microsoft.aad.msal4j?view=msal-java-latest)
66

77
The Microsoft Authentication Library for Java (MSAL4J) enables applications to integrate with the [Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/). It allows you to sign in users or apps with Microsoft identities (Azure AD, Microsoft accounts and Azure AD B2C accounts) and obtain tokens to call Microsoft APIs such as [Microsoft Graph](https://graph.microsoft.io/) or your own APIs registered with the Microsoft identity platform. It is built using industry standard OAuth2 and OpenID Connect protocols.
88

@@ -16,9 +16,9 @@ Quick links:
1616
The library supports the following Java environments:
1717
- Java 8 (or higher)
1818

19-
Current version - 1.13.2
19+
Current version - 1.13.8
2020

21-
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).
21+
You can find the changes for each version in the [change log](https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/main/msal4j-sdk/changelog.txt).
2222

2323
You can get the com.microsoft.aad.msal4j package through Maven or Gradle.
2424

@@ -28,13 +28,13 @@ Find [the latest package in the Maven repository](https://mvnrepository.com/arti
2828
<dependency>
2929
<groupId>com.microsoft.azure</groupId>
3030
<artifactId>msal4j</artifactId>
31-
<version>1.13.2</version>
31+
<version>1.13.8</version>
3232
</dependency>
3333
```
3434
### Gradle
3535

3636
```gradle
37-
implementation group: 'com.microsoft.azure', name: 'com.microsoft.aad.msal4j', version: '1.13.2'
37+
implementation group: 'com.microsoft.azure', name: 'com.microsoft.aad.msal4j', version: '1.13.8'
3838
```
3939

4040
## Usage

msal4j-brokers/src/main/java/com/microsoft/aad/msal4jbrokers/MsalRuntimeBroker.java

Lines changed: 94 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33

44
package com.microsoft.aad.msal4jbrokers;
55

6-
import com.microsoft.aad.msal4j.IAuthenticationResult;
7-
import com.microsoft.aad.msal4j.IBroker;
8-
import com.microsoft.aad.msal4j.InteractiveRequestParameters;
9-
import com.microsoft.aad.msal4j.PublicClientApplication;
10-
import com.microsoft.aad.msal4j.SilentParameters;
11-
import com.microsoft.aad.msal4j.UserNamePasswordParameters;
12-
import com.microsoft.aad.msal4j.MsalClientException;
13-
import com.microsoft.aad.msal4j.AuthenticationErrorCode;
14-
import com.microsoft.aad.msal4j.IAccount;
6+
import com.microsoft.aad.msal4j.*;
157
import com.microsoft.azure.javamsalruntime.Account;
168
import com.microsoft.azure.javamsalruntime.AuthParameters;
179
import com.microsoft.azure.javamsalruntime.AuthResult;
@@ -28,6 +20,7 @@ public class MsalRuntimeBroker implements IBroker {
2820
private static final Logger LOG = LoggerFactory.getLogger(MsalRuntimeBroker.class);
2921

3022
private static MsalRuntimeInterop interop;
23+
private static Boolean brokerAvailable;
3124

3225
static {
3326
try {
@@ -53,11 +46,20 @@ public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplica
5346
}
5447

5548
try {
56-
AuthParameters authParameters = new AuthParameters
57-
.AuthParametersBuilder(application.clientId(),
49+
AuthParameters.AuthParametersBuilder authParamsBuilder = new AuthParameters.
50+
AuthParametersBuilder(application.clientId(),
5851
application.authority(),
5952
String.join(" ", parameters.scopes()))
60-
.build();
53+
.additionalParameters(parameters.extraQueryParameters());
54+
55+
//If POP auth scheme configured, set parameters to get MSALRuntime to return POP tokens
56+
if (parameters.proofOfPossession() != null) {
57+
authParamsBuilder.popParameters(parameters.proofOfPossession().getHttpMethod().methodName,
58+
parameters.proofOfPossession().getUri(),
59+
parameters.proofOfPossession().getNonce());
60+
}
61+
62+
AuthParameters authParameters = authParamsBuilder.build();
6163

6264
if (accountResult == null) {
6365
return interop.signInSilently(authParameters, application.correlationId())
@@ -68,17 +70,17 @@ public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplica
6870
((AuthResult) authResult).getAccessToken(),
6971
((AuthResult) authResult).getAccount().getAccountId(),
7072
((AuthResult) authResult).getAccount().getClientInfo(),
71-
((AuthResult) authResult).getAccessTokenExpirationTime()));
73+
((AuthResult) authResult).getAccessTokenExpirationTime(),
74+
((AuthResult) authResult).isPopAuthorization()));
7275
} else {
7376
return interop.acquireTokenSilently(authParameters, application.correlationId(), accountResult)
7477
.thenApply(authResult -> parseBrokerAuthResult(application.authority(),
7578
((AuthResult) authResult).getIdToken(),
7679
((AuthResult) authResult).getAccessToken(),
7780
((AuthResult) authResult).getAccount().getAccountId(),
7881
((AuthResult) authResult).getAccount().getClientInfo(),
79-
((AuthResult) authResult).getAccessTokenExpirationTime())
80-
81-
);
82+
((AuthResult) authResult).getAccessTokenExpirationTime(),
83+
((AuthResult) authResult).isPopAuthorization()));
8284
}
8385
} catch (MsalInteropException interopException) {
8486
throw new MsalClientException(interopException.getErrorMessage(), AuthenticationErrorCode.MSALRUNTIME_INTEROP_ERROR);
@@ -88,11 +90,21 @@ public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplica
8890
@Override
8991
public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, InteractiveRequestParameters parameters) {
9092
try {
91-
AuthParameters authParameters = new AuthParameters
92-
.AuthParametersBuilder(application.clientId(),
93+
AuthParameters.AuthParametersBuilder authParamsBuilder = new AuthParameters.
94+
AuthParametersBuilder(application.clientId(),
9395
application.authority(),
9496
String.join(" ", parameters.scopes()))
95-
.build();
97+
.redirectUri(parameters.redirectUri().toString())
98+
.additionalParameters(parameters.extraQueryParameters());
99+
100+
//If POP auth scheme configured, set parameters to get MSALRuntime to return POP tokens
101+
if (parameters.proofOfPossession() != null) {
102+
authParamsBuilder.popParameters(parameters.proofOfPossession().getHttpMethod().methodName,
103+
parameters.proofOfPossession().getUri(),
104+
parameters.proofOfPossession().getNonce());
105+
}
106+
107+
AuthParameters authParameters = authParamsBuilder.build();
96108

97109
return interop.signInInteractively(parameters.windowHandle(), authParameters, application.correlationId(), parameters.loginHint())
98110
.thenCompose(acctResult -> interop.acquireTokenInteractively(parameters.windowHandle(), authParameters, application.correlationId(), ((AuthResult) acctResult).getAccount()))
@@ -102,8 +114,8 @@ public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplica
102114
((AuthResult) authResult).getAccessToken(),
103115
((AuthResult) authResult).getAccount().getAccountId(),
104116
((AuthResult) authResult).getAccount().getClientInfo(),
105-
((AuthResult) authResult).getAccessTokenExpirationTime())
106-
);
117+
((AuthResult) authResult).getAccessTokenExpirationTime(),
118+
((AuthResult) authResult).isPopAuthorization()));
107119
} catch (MsalInteropException interopException) {
108120
throw new MsalClientException(interopException.getErrorMessage(), AuthenticationErrorCode.MSALRUNTIME_INTEROP_ERROR);
109121
}
@@ -116,14 +128,20 @@ public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplica
116128
@Override
117129
public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, UserNamePasswordParameters parameters) {
118130
try {
119-
AuthParameters authParameters =
120-
new AuthParameters
121-
.AuthParametersBuilder(application.clientId(),
122-
application.authority(),
123-
String.join(" ", parameters.scopes()))
124-
.build();
131+
AuthParameters.AuthParametersBuilder authParamsBuilder = new AuthParameters.
132+
AuthParametersBuilder(application.clientId(),
133+
application.authority(),
134+
String.join(" ", parameters.scopes()))
135+
.additionalParameters(parameters.extraQueryParameters());
136+
137+
//If POP auth scheme configured, set parameters to get MSALRuntime to return POP tokens
138+
if (parameters.proofOfPossession() != null) {
139+
authParamsBuilder.popParameters(parameters.proofOfPossession().getHttpMethod().methodName,
140+
parameters.proofOfPossession().getUri(),
141+
parameters.proofOfPossession().getNonce());
142+
}
125143

126-
authParameters.setUsernamePassword(parameters.username(), new String(parameters.password()));
144+
AuthParameters authParameters = authParamsBuilder.build();
127145

128146
return interop.signInSilently(authParameters, application.correlationId())
129147
.thenCompose(acctResult -> interop.acquireTokenSilently(authParameters, application.correlationId(), ((AuthResult) acctResult).getAccount()))
@@ -133,7 +151,8 @@ public CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplica
133151
((AuthResult) authResult).getAccessToken(),
134152
((AuthResult) authResult).getAccount().getAccountId(),
135153
((AuthResult) authResult).getAccount().getClientInfo(),
136-
((AuthResult) authResult).getAccessTokenExpirationTime()));
154+
((AuthResult) authResult).getAccessTokenExpirationTime(),
155+
((AuthResult) authResult).isPopAuthorization()));
137156
} catch (MsalInteropException interopException) {
138157
throw new MsalClientException(interopException.getErrorMessage(), AuthenticationErrorCode.MSALRUNTIME_INTEROP_ERROR);
139158
}
@@ -163,17 +182,55 @@ public void removeAccount(PublicClientApplication application, IAccount msalJava
163182
*/
164183
@Override
165184
public boolean isBrokerAvailable() {
166-
try {
167-
interop.startupMsalRuntime();
185+
//brokerAvailable is only set after the first attempt to call MSALRuntime's startup API
186+
if (brokerAvailable == null) {
187+
try {
188+
interop.startupMsalRuntime();
168189

169-
LOG.info("MSALRuntime started successfully. MSAL Java will use MSALRuntime in all supported broker flows.");
190+
LOG.info("MSALRuntime started successfully. MSAL Java will use MSALRuntime in all supported broker flows.");
170191

171-
return true;
172-
} catch (MsalInteropException e) {
173-
LOG.warn("Exception thrown when trying to start MSALRuntime: {}", e.getErrorMessage());
174-
LOG.warn("MSALRuntime could not be started. MSAL Java will fall back to non-broker flows.");
192+
brokerAvailable = true;
193+
} catch (MsalInteropException e) {
194+
LOG.warn("Exception thrown when trying to start MSALRuntime: {}", e.getErrorMessage());
195+
LOG.warn("MSALRuntime could not be started. MSAL Java will fall back to non-broker flows.");
175196

176-
return false;
197+
brokerAvailable = false;
198+
}
199+
}
200+
201+
return brokerAvailable;
202+
}
203+
204+
/**
205+
* Toggles whether or not detailed MSALRuntime logs will appear in MSAL Java's normal logging framework.
206+
*
207+
* If enabled, you will see logs directly from MSALRuntime, containing verbose information relating to telemetry, API calls,successful/failed requests, and more.
208+
* These logs will appear alongside MSAL Java's logs (with a message indicating they came from MSALRuntime), and will follow the same log level as MSAL Java's logs (info/debug/error/etc.).
209+
*
210+
* If disabled (default), MSAL Java will still produce some logs related to MSALRuntime, particularly in error messages, but will be much less verbose.
211+
*
212+
* @param enableLogging true to enable MSALRuntime logs, false to disable it
213+
*/
214+
public void enableBrokerLogging(boolean enableLogging) {
215+
try {
216+
MsalRuntimeInterop.enableLogging(enableLogging);
217+
} catch (Exception ex) {
218+
throw new MsalClientException(String.format("Error occurred when calling MSALRuntime logging API: %s", ex.getMessage()), AuthenticationErrorCode.MSALRUNTIME_INTEROP_ERROR);
219+
}
220+
}
221+
222+
/**
223+
* If enabled, Personal Identifiable Information (PII) can appear in logs and error messages produced by MSALRuntime.
224+
*
225+
* If disabled (default), PII will not be shown, and you will simply see "(PII)" or similar notes in places where PII data would have appeared.
226+
*
227+
* @param enablePII true to allow PII to appear in logs and error messages, false to disallow it
228+
*/
229+
public void enableBrokerPIILogging(boolean enablePII) {
230+
try {
231+
MsalRuntimeInterop.enableLoggingPii(enablePII);
232+
} catch (Exception ex) {
233+
throw new MsalClientException(String.format("Error occurred when calling MSALRuntime PII logging API: %s", ex.getMessage()), AuthenticationErrorCode.MSALRUNTIME_INTEROP_ERROR);
177234
}
178235
}
179236
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//----------------------------------------------------------------------
2+
//
3+
// Copyright (c) Microsoft Corporation. All rights reserved.
4+
// Licensed under the MIT License.
5+
//
6+
//------------------------------------------------------------------------------
7+
8+
package infrastructure;
9+
10+
public class SeleniumConstants {
11+
final static String WEB_UPN_INPUT_ID = "i0116";
12+
final static String WEB_PASSWORD_ID = "i0118";
13+
final static String WEB_SUBMIT_ID = "idSIButton9";
14+
15+
// Stay signed in?
16+
final static String STAY_SIGN_IN_NO_BUTTON_ID = "idBtn_Back";
17+
18+
// Are you trying to sign in to ...
19+
//Only continue if you downloaded the app from a store or website that you trust.
20+
final static String ARE_YOU_TRYING_TO_SIGN_IN_TO = "idSIButton9";
21+
}

0 commit comments

Comments
 (0)