This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 9cd319e3e5 NIFI-13646 Corrected Current User Replicated Response
Handling (#9164)
9cd319e3e5 is described below
commit 9cd319e3e5ca19cbdf92bad60e761ef680f2297c
Author: David Handermann <[email protected]>
AuthorDate: Wed Aug 7 16:22:39 2024 -0500
NIFI-13646 Corrected Current User Replicated Response Handling (#9164)
Signed-off-by: David Handermann <[email protected]>
---
.../java/org/apache/nifi/web/api/FlowResource.java | 27 +++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
index dfe6399d11..722c49c449 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
@@ -16,6 +16,7 @@
*/
package org.apache.nifi.web.api;
+import com.fasterxml.jackson.databind.ObjectMapper;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.common.TextFormat;
import io.swagger.v3.oas.annotations.Operation;
@@ -152,6 +153,9 @@ import org.apache.nifi.web.util.PaginationHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UncheckedIOException;
import java.text.Collator;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
@@ -188,6 +192,8 @@ public class FlowResource extends ApplicationResource {
private static final String
VERSIONED_REPORTING_TASK_SNAPSHOT_FILENAME_PATTERN =
"VersionedReportingTaskSnapshot-%s.json";
private static final String VERSIONED_REPORTING_TASK_SNAPSHOT_DATE_FORMAT
= "yyyyMMddHHmmss";
+ private static final ObjectMapper objectMapper = new ObjectMapper();
+
private NiFiServiceFacade serviceFacade;
private Authorizer authorizer;
@@ -343,7 +349,7 @@ public class FlowResource extends ApplicationResource {
final CurrentUserEntity entity;
if (isReplicateRequest()) {
try (Response replicatedResponse = replicate(HttpMethod.GET)) {
- final CurrentUserEntity replicatedCurrentUserEntity =
(CurrentUserEntity) replicatedResponse.getEntity();
+ final CurrentUserEntity replicatedCurrentUserEntity =
readReplicatedCurrentUserEntity(replicatedResponse);
final CurrentUserEntity currentUserEntity =
serviceFacade.getCurrentUser();
// Set Logout Supported based on local client information
instead of replicated and merged responses
replicatedCurrentUserEntity.setLogoutSupported(currentUserEntity.isLogoutSupported());
@@ -356,6 +362,25 @@ public class FlowResource extends ApplicationResource {
return generateOkResponse(entity).build();
}
+ private CurrentUserEntity readReplicatedCurrentUserEntity(final Response
replicatedResponse) {
+ final Object entity = replicatedResponse.getEntity();
+ if (entity instanceof CurrentUserEntity replicatedCurrentUserEntity) {
+ return replicatedCurrentUserEntity;
+ } else if (entity instanceof StreamingOutput streamingOutput) {
+ final ByteArrayOutputStream outputStream = new
ByteArrayOutputStream();
+ try {
+ streamingOutput.write(outputStream);
+
+ final byte[] bytes = outputStream.toByteArray();
+ return objectMapper.readValue(bytes, CurrentUserEntity.class);
+ } catch (final IOException e) {
+ throw new UncheckedIOException("Read Current User Entity
failed", e);
+ }
+ } else {
+ throw new IllegalStateException("Current User Entity not expected
[%s]".formatted(entity));
+ }
+ }
+
/**
* Retrieves the contents of the specified group.
*