|
| 1 | +From 93055143af33db3044aeb2ca6bab78d15ddaa4b2 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Andrew Kenworthy < [email protected]> |
| 3 | +Date: Wed, 15 Oct 2025 17:12:12 +0200 |
| 4 | +Subject: update root ID via callback |
| 5 | + |
| 6 | +--- |
| 7 | + .../nifi/flow/FlowInitializationCallback.java | 9 +++++++ |
| 8 | + .../FileAccessPolicyProvider.java | 4 +++ |
| 9 | + .../FileAuthorizerInitializer.java | 25 +++++++++++++++++++ |
| 10 | + .../nifi/controller/StandardFlowService.java | 16 ++++++++++-- |
| 11 | + 4 files changed, 52 insertions(+), 2 deletions(-) |
| 12 | + create mode 100644 nifi-framework-api/src/main/java/org/apache/nifi/flow/FlowInitializationCallback.java |
| 13 | + create mode 100644 nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizerInitializer.java |
| 14 | + |
| 15 | +diff --git a/nifi-framework-api/src/main/java/org/apache/nifi/flow/FlowInitializationCallback.java b/nifi-framework-api/src/main/java/org/apache/nifi/flow/FlowInitializationCallback.java |
| 16 | +new file mode 100644 |
| 17 | +index 0000000000..3039c97497 |
| 18 | +--- /dev/null |
| 19 | ++++ b/nifi-framework-api/src/main/java/org/apache/nifi/flow/FlowInitializationCallback.java |
| 20 | +@@ -0,0 +1,9 @@ |
| 21 | ++package org.apache.nifi.flow; |
| 22 | ++ |
| 23 | ++/** |
| 24 | ++ * Simple callback interface invoked when the root process group has been |
| 25 | ++ * loaded and the flow is fully initialized for the first time. |
| 26 | ++ */ |
| 27 | ++public interface FlowInitializationCallback { |
| 28 | ++ void onRootGroupLoaded(); |
| 29 | ++} |
| 30 | +diff --git a/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAccessPolicyProvider.java b/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAccessPolicyProvider.java |
| 31 | +index ca9758f32c..cb16cd1a30 100644 |
| 32 | +--- a/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAccessPolicyProvider.java |
| 33 | ++++ b/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAccessPolicyProvider.java |
| 34 | +@@ -29,6 +29,7 @@ import org.apache.nifi.authorization.resource.ResourceType; |
| 35 | + import org.apache.nifi.authorization.util.IdentityMapping; |
| 36 | + import org.apache.nifi.authorization.util.IdentityMappingUtil; |
| 37 | + import org.apache.nifi.components.PropertyValue; |
| 38 | ++import org.apache.nifi.controller.StandardFlowService; |
| 39 | + import org.apache.nifi.util.FlowInfo; |
| 40 | + import org.apache.nifi.util.FlowParser; |
| 41 | + import org.apache.nifi.util.NiFiProperties; |
| 42 | +@@ -133,6 +134,9 @@ public class FileAccessPolicyProvider implements ConfigurableAccessPolicyProvide |
| 43 | + public void initialize(AccessPolicyProviderInitializationContext initializationContext) throws AuthorizerCreationException { |
| 44 | + userGroupProviderLookup = initializationContext.getUserGroupProviderLookup(); |
| 45 | + |
| 46 | ++ // Register flow initialization hook |
| 47 | ++ StandardFlowService.registerInitializationCallback(new FileAuthorizerInitializer(this)); |
| 48 | ++ |
| 49 | + try { |
| 50 | + final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
| 51 | + authorizationsSchema = schemaFactory.newSchema(FileAccessPolicyProvider.class.getResource(AUTHORIZATIONS_XSD)); |
| 52 | +diff --git a/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizerInitializer.java b/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizerInitializer.java |
| 53 | +new file mode 100644 |
| 54 | +index 0000000000..f67328ef84 |
| 55 | +--- /dev/null |
| 56 | ++++ b/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/main/java/org/apache/nifi/authorization/FileAuthorizerInitializer.java |
| 57 | +@@ -0,0 +1,25 @@ |
| 58 | ++package org.apache.nifi.authorization; |
| 59 | ++ |
| 60 | ++import org.apache.nifi.flow.FlowInitializationCallback; |
| 61 | ++import org.slf4j.Logger; |
| 62 | ++import org.slf4j.LoggerFactory; |
| 63 | ++ |
| 64 | ++ |
| 65 | ++public class FileAuthorizerInitializer implements FlowInitializationCallback { |
| 66 | ++ private static final Logger logger = LoggerFactory.getLogger(FileAuthorizerInitializer.class); |
| 67 | ++private FileAccessPolicyProvider fileAccessPolicyProvider; |
| 68 | ++ |
| 69 | ++ public FileAuthorizerInitializer(FileAccessPolicyProvider fileAccessPolicyProvider) { |
| 70 | ++ this.fileAccessPolicyProvider = fileAccessPolicyProvider; |
| 71 | ++ } |
| 72 | ++ |
| 73 | ++ @Override |
| 74 | ++ public void onRootGroupLoaded() { |
| 75 | ++ try { |
| 76 | ++ logger.info("Flow initialized; ensuring root group ID is recorded in authorizations.xml"); |
| 77 | ++ this.fileAccessPolicyProvider.replaceWithRootGroupId(); |
| 78 | ++ } catch (Exception e) { |
| 79 | ++ logger.warn("Unable to update authorizations.xml with root group ID", e); |
| 80 | ++ } |
| 81 | ++ } |
| 82 | ++} |
| 83 | +\ No newline at end of file |
| 84 | +diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java |
| 85 | +index dad44540de..b0137c8302 100644 |
| 86 | +--- a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java |
| 87 | ++++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardFlowService.java |
| 88 | +@@ -55,6 +55,7 @@ import org.apache.nifi.controller.serialization.FlowSynchronizationException; |
| 89 | + import org.apache.nifi.controller.status.ProcessGroupStatus; |
| 90 | + import org.apache.nifi.engine.FlowEngine; |
| 91 | + import org.apache.nifi.events.BulletinFactory; |
| 92 | ++import org.apache.nifi.flow.FlowInitializationCallback; |
| 93 | + import org.apache.nifi.groups.BundleUpdateStrategy; |
| 94 | + import org.apache.nifi.groups.ProcessGroup; |
| 95 | + import org.apache.nifi.groups.RemoteProcessGroup; |
| 96 | +@@ -148,6 +149,13 @@ public class StandardFlowService implements FlowService, ProtocolHandler { |
| 97 | + private static final String CONNECTION_EXCEPTION_MSG_PREFIX = "Failed to connect node to cluster"; |
| 98 | + private static final Logger logger = LoggerFactory.getLogger(StandardFlowService.class); |
| 99 | + |
| 100 | ++ // Static callback registration for post-initialization hooks |
| 101 | ++ private static volatile FlowInitializationCallback initializationCallback; |
| 102 | ++ |
| 103 | ++ public static void registerInitializationCallback(FlowInitializationCallback callback) { |
| 104 | ++ initializationCallback = callback; |
| 105 | ++ } |
| 106 | ++ |
| 107 | + public static StandardFlowService createStandaloneInstance( |
| 108 | + final FlowController controller, |
| 109 | + final NiFiProperties nifiProperties, |
| 110 | +@@ -934,8 +942,12 @@ public class StandardFlowService implements FlowService, ProtocolHandler { |
| 111 | + controller.onFlowInitialized(autoResumeState); |
| 112 | + |
| 113 | + // this should be done once the flow has been initialized |
| 114 | +- if (this.authorizer instanceof org.apache.nifi.authorization.FileAccessPolicyProvider) { |
| 115 | +- ((org.apache.nifi.authorization.FileAccessPolicyProvider) this.authorizer).replaceWithRootGroupId(); |
| 116 | ++ if (initializationCallback != null) { |
| 117 | ++ try { |
| 118 | ++ initializationCallback.onRootGroupLoaded(); |
| 119 | ++ } catch (Exception e) { |
| 120 | ++ logger.warn("Error invoking FlowInitializationCallback", e); |
| 121 | ++ } |
| 122 | + } |
| 123 | + |
| 124 | + loadSnippets(dataFlow.getSnippets()); |
0 commit comments