From 83a9e965d285d77e7f85bd0df7d18e774d20d845 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Thu, 7 Apr 2022 07:15:09 +0000 Subject: [PATCH] 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 --- .../loganalytics/AbstractAzureLogAnalyticsReportingTask.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/main/java/org/apache/nifi/reporting/azure/loganalytics/AbstractAzureLogAnalyticsReportingTask.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/main/java/org/apache/nifi/reporting/azure/loganalytics/AbstractAzureLogAnalyticsReportingTask.java index 1017ee54ea..056d05d2a8 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/main/java/org/apache/nifi/reporting/azure/loganalytics/AbstractAzureLogAnalyticsReportingTask.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/main/java/org/apache/nifi/reporting/azure/loganalytics/AbstractAzureLogAnalyticsReportingTask.java @@ -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);