NIFI-9888 Fix Azure header datetime format

This fixes the occasional "403 Forbidden" bug that we have seen, simply because
the signature ends up being invalid due to an invalid datetime format used.

Issue: NIFI-9888
Reference: https://stackoverflow.com/a/51636763/647151

Use statically defined formatter and explain why

This closes #5943.

Signed-off-by: Kevin Doran <kdoran@apache.org>
This commit is contained in:
Malthe Borch 2022-04-07 07:15:09 +00:00 committed by Kevin Doran
parent 4f423a59ba
commit 83a9e965d2
1 changed files with 4 additions and 1 deletions

View File

@ -50,6 +50,9 @@ public abstract class AbstractAzureLogAnalyticsReportingTask extends AbstractRep
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final String HMAC_SHA256_ALG = "HmacSHA256";
// DateTimeFormatter.RFC_1123_DATE_TIME does not work in every case, such as when a
// two-digit day of month is always required, so we are defining our own formatter here.
private static final DateTimeFormatter RFC_1123_DATE_TIME = DateTimeFormatter
.ofPattern("EEE, dd MMM yyyy HH:mm:ss O");
@ -136,7 +139,7 @@ public abstract class AbstractAzureLogAnalyticsReportingTask extends AbstractRep
final int bodyLength = rawJson.getBytes(UTF8).length;
final ZonedDateTime zNow = ZonedDateTime.now(ZoneOffset.UTC);
final String nowRfc1123 = zNow.format(DateTimeFormatter.RFC_1123_DATE_TIME);
final String nowRfc1123 = zNow.format(RFC_1123_DATE_TIME);
final String nowISO8601 = zNow.format(DateTimeFormatter.ISO_DATE_TIME);
final String createAuthorization = createAuthorization(workspaceId, linuxPrimaryKey, bodyLength, nowRfc1123);
request.addHeader("Authorization", createAuthorization);