From 4196140e4c36a56957ea3c3bd3b5423f0731eda6 Mon Sep 17 00:00:00 2001 From: Bryan Bende Date: Mon, 8 Jan 2018 16:21:03 -0500 Subject: [PATCH] NIFI-4750 Ensuring preDestruction is called on authorizer and appropriate policy/user-group providers. This closes #2387 --- .../authorization/AuthorizerFactoryBean.java | 32 ++++++++++++++++++- ...ompositeConfigurableUserGroupProvider.java | 6 +++- .../CompositeUserGroupProvider.java | 13 ++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/main/java/org/apache/nifi/authorization/AuthorizerFactoryBean.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/main/java/org/apache/nifi/authorization/AuthorizerFactoryBean.java index 7a5617cf47..9f17a18ae5 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/main/java/org/apache/nifi/authorization/AuthorizerFactoryBean.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/main/java/org/apache/nifi/authorization/AuthorizerFactoryBean.java @@ -479,7 +479,37 @@ public class AuthorizerFactoryBean implements FactoryBean, DisposableBean, UserG @Override public void destroy() throws Exception { if (authorizer != null) { - authorizer.preDestruction(); + Exception error = null; + + try { + authorizer.preDestruction(); + } catch (final Exception e) { + error = e; + } + + if (authorizer instanceof ManagedAuthorizer) { + final AccessPolicyProvider accessPolicyProvider = ((ManagedAuthorizer) authorizer).getAccessPolicyProvider(); + if (accessPolicyProvider != null) { + try { + accessPolicyProvider.preDestruction(); + } catch (final Exception e) { + error = e; + } + + final UserGroupProvider userGroupProvider = accessPolicyProvider.getUserGroupProvider(); + if (userGroupProvider != null) { + try { + userGroupProvider.preDestruction(); + } catch (final Exception e) { + error = e; + } + } + } + } + + if (error != null) { + throw error; + } } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeConfigurableUserGroupProvider.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeConfigurableUserGroupProvider.java index 21409266ac..a2621979a7 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeConfigurableUserGroupProvider.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeConfigurableUserGroupProvider.java @@ -210,6 +210,10 @@ public class CompositeConfigurableUserGroupProvider extends CompositeUserGroupPr @Override public void preDestruction() throws AuthorizerDestructionException { - super.preDestruction(); + try { + configurableUserGroupProvider.preDestruction(); + } finally { + super.preDestruction(); + } } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeUserGroupProvider.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeUserGroupProvider.java index 5f351912b4..916865be80 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeUserGroupProvider.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/main/java/org/apache/nifi/authorization/CompositeUserGroupProvider.java @@ -199,5 +199,18 @@ public class CompositeUserGroupProvider implements UserGroupProvider { @Override public void preDestruction() throws AuthorizerDestructionException { + Exception error = null; + for (final UserGroupProvider userGroupProvider : userGroupProviders) { + try { + userGroupProvider.preDestruction(); + } catch (Exception e) { + error = e; + logger.error("Error pre-destructing: " + e); + } + } + + if (error != null) { + throw new AuthorizerDestructionException(error); + } } }