Skip to content

Commit a65cd3c

Browse files
committed
Merge branch 'dev' into avdunn/test-poc
2 parents 11abc43 + 15e26ca commit a65cd3c

37 files changed

+535
-153
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Quick links:
1616
The library supports the following Java environments:
1717
- Java 8 (or higher)
1818

19-
Current version - 1.20.1
19+
Current version - 1.21.0
2020

2121
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

@@ -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.20.1</version>
31+
<version>1.21.0</version>
3232
</dependency>
3333
```
3434
### Gradle
3535

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

4040
## Usage

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 1.21.0
2+
=============
3+
- Add support for claims, client capabilities, and token revocation in Service Fabric scenarios (#929, #943)
4+
- Improve retry logic for HTTP requests, and add API to disable retries (#960, #963, #964)
5+
- Support multiple date formats in Managed identity scenarios (#956)
6+
- Fix query parameter issue in IMDS scenarios (#954)
7+
- Update dependencies used in tests to avoid CVE warnings (#962)
8+
19
Version 1.20.1
210
=============
311
- Fix Base64URL decoding bug (#938)

msal4j-sdk/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Quick links:
1616
The library supports the following Java environments:
1717
- Java 8 (or higher)
1818

19-
Current version - 1.20.1
19+
Current version - 1.21.0
2020

2121
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).
2222

@@ -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.20.1</version>
31+
<version>1.21.0</version>
3232
</dependency>
3333
```
3434
### Gradle
3535

3636
```gradle
37-
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.20.1'
37+
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.21.0'
3838
```
3939

4040
## Usage

msal4j-sdk/bnd.bnd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Export-Package: com.microsoft.aad.msal4j;version="1.20.1"
1+
Export-Package: com.microsoft.aad.msal4j;version="1.21.0"
22
Automatic-Module-Name: com.microsoft.aad.msal4j

msal4j-sdk/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>1.20.1</version>
6+
<version>1.21.0</version>
77
<packaging>jar</packaging>
88
<name>msal4j</name>
99
<description>

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ static AadInstanceDiscoveryResponse sendInstanceDiscoveryRequest(URL authorityUr
235235

236236
AadInstanceDiscoveryResponse response = JsonHelper.convertJsonStringToJsonSerializableObject(httpResponse.body(), AadInstanceDiscoveryResponse::fromJson);
237237

238-
if (httpResponse.statusCode() != HttpHelper.HTTP_STATUS_200) {
239-
if (httpResponse.statusCode() == HttpHelper.HTTP_STATUS_400 && response.error().equals("invalid_instance")) {
238+
if (httpResponse.statusCode() != HttpStatus.HTTP_OK) {
239+
if (httpResponse.statusCode() == HttpStatus.HTTP_BAD_REQUEST && response.error().equals("invalid_instance")) {
240240
// instance discovery failed due to an invalid authority, throw an exception.
241241
throw MsalServiceExceptionFactory.fromHttpResponse(httpResponse);
242242
}
@@ -310,7 +310,7 @@ static String discoverRegion(MsalRequest msalRequest, ServiceBundle serviceBundl
310310
log.info("Starting call to IMDS endpoint.");
311311
IHttpResponse httpResponse = future.get(IMDS_TIMEOUT, IMDS_TIMEOUT_UNIT);
312312
//If call to IMDS endpoint was successful, return region from response body
313-
if (httpResponse.statusCode() == HttpHelper.HTTP_STATUS_200 && !httpResponse.body().isEmpty()) {
313+
if (httpResponse.statusCode() == HttpStatus.HTTP_OK && !httpResponse.body().isEmpty()) {
314314
log.info(String.format("Region retrieved from IMDS endpoint: %s", httpResponse.body()));
315315
currentRequest.regionSource(RegionTelemetry.REGION_SOURCE_IMDS.telemetryValue);
316316

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AbstractApplicationBase.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public abstract class AbstractApplicationBase implements IApplicationBase {
3232
private IHttpClient httpClient;
3333
private Integer connectTimeoutForDefaultHttpClient;
3434
private Integer readTimeoutForDefaultHttpClient;
35+
private boolean retryDisabled;
3536
String tenant;
3637

3738
//The following fields are set in only some applications and/or set internally by the library. To avoid excessive
@@ -150,6 +151,10 @@ public Integer readTimeoutForDefaultHttpClient() {
150151
return this.readTimeoutForDefaultHttpClient;
151152
}
152153

154+
boolean isRetryDisabled() {
155+
return this.retryDisabled;
156+
}
157+
153158
String tenant() {
154159
return this.tenant;
155160
}
@@ -190,6 +195,7 @@ public abstract static class Builder<T extends Builder<T>> {
190195
Boolean onlySendFailureTelemetry = false;
191196
Integer connectTimeoutForDefaultHttpClient;
192197
Integer readTimeoutForDefaultHttpClient;
198+
boolean disableInternalRetries;
193199
private String clientId;
194200
private Authority authenticationAuthority = createDefaultAADAuthority();
195201

@@ -319,6 +325,18 @@ public T readTimeoutForDefaultHttpClient(Integer val) {
319325
return self();
320326
}
321327

328+
/**
329+
* The library has a number of policies for retrying HTTP calls in different scenarios.
330+
* <p>
331+
* This will disable all internal retry behavior, allowing customized retry behavior via your own implementation of {@link IHttpClient}
332+
*
333+
* @return instance of the Builder on which method was called
334+
*/
335+
public T disableInternalRetries() {
336+
disableInternalRetries = true;
337+
return self();
338+
}
339+
322340
T telemetryConsumer(Consumer<List<HashMap<String, String>>> val) {
323341
validateNotNull("telemetryConsumer", val);
324342

@@ -356,5 +374,16 @@ private static Authority createDefaultAADAuthority() {
356374
readTimeoutForDefaultHttpClient = builder.readTimeoutForDefaultHttpClient;
357375
authenticationAuthority = builder.authenticationAuthority;
358376
clientId = builder.clientId;
377+
retryDisabled = builder.disableInternalRetries;
378+
379+
if (builder.httpClient == null) {
380+
httpClient = new DefaultHttpClient(
381+
builder.proxy,
382+
builder.sslSocketFactory,
383+
builder.connectTimeoutForDefaultHttpClient,
384+
builder.readTimeoutForDefaultHttpClient);
385+
} else {
386+
httpClient = builder.httpClient;
387+
}
359388
}
360389
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AbstractClientApplicationBase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,7 @@ public T correlationId(String val) {
566566
super.serviceBundle = new ServiceBundle(
567567
builder.executorService,
568568
new TelemetryManager(telemetryConsumer, builder.onlySendFailureTelemetry),
569-
new HttpHelper(builder.httpClient == null ?
570-
new DefaultHttpClient(builder.proxy, builder.sslSocketFactory, builder.connectTimeoutForDefaultHttpClient, builder.readTimeoutForDefaultHttpClient) :
571-
builder.httpClient)
569+
new HttpHelper(this, new DefaultRetryPolicy())
572570
);
573571

574572
if (aadAadInstanceDiscoveryResponse != null) {

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthorizationResponseHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AuthorizationResponseHandler implements HttpHandler {
4141
public void handle(HttpExchange httpExchange) throws IOException {
4242
try {
4343
if (!httpExchange.getRequestURI().getPath().equalsIgnoreCase("/")) {
44-
httpExchange.sendResponseHeaders(200, 0);
44+
httpExchange.sendResponseHeaders(HttpStatus.HTTP_OK, 0);
4545
return;
4646
}
4747
String responseBody = new BufferedReader(new InputStreamReader(
@@ -92,13 +92,13 @@ private void sendErrorResponse(HttpExchange httpExchange, String response) throw
9292
private void send302Response(HttpExchange httpExchange, String redirectUri) throws IOException {
9393
Headers responseHeaders = httpExchange.getResponseHeaders();
9494
responseHeaders.set("Location", redirectUri);
95-
httpExchange.sendResponseHeaders(302, 0);
95+
httpExchange.sendResponseHeaders(HttpStatus.HTTP_FOUND, 0);
9696
}
9797

9898
private void send200Response(HttpExchange httpExchange, String response) throws IOException {
9999
byte[] responseBytes = response.getBytes("UTF-8");
100100
httpExchange.getResponseHeaders().set("Content-Type", "text/html; charset=UTF-8");
101-
httpExchange.sendResponseHeaders(200, responseBytes.length);
101+
httpExchange.sendResponseHeaders(HttpStatus.HTTP_OK, responseBytes.length);
102102
OutputStream os = httpExchange.getResponseBody();
103103
os.write(responseBytes);
104104
os.close();

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/ClientCertificate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static ClientCertificate create(final PrivateKey key, final X509Certificate publ
110110
}
111111

112112
private static byte[] getHashSha1(final byte[] inputBytes) throws NoSuchAlgorithmException {
113-
final MessageDigest md = MessageDigest.getInstance("SHA-1");
113+
final MessageDigest md = MessageDigest.getInstance("SHA-1"); // CodeQL [SM05136] ADFS scenarios require SHA-1 hashing, and we cannot remove our use until ADFS does.
114114
md.update(inputBytes);
115115
return md.digest();
116116
}

0 commit comments

Comments
 (0)