NIFI-4750 Ensuring preDestruction is called on authorizer and appropriate policy/user-group providers. This closes #2387

This commit is contained in:
Bryan Bende 2018-01-08 16:21:03 -05:00 committed by Matt Gilman
parent 8f635f1c0d
commit 4196140e4c
No known key found for this signature in database
GPG Key ID: DF61EC19432AEE37
3 changed files with 49 additions and 2 deletions

View File

@ -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;
}
}
}

View File

@ -210,6 +210,10 @@ public class CompositeConfigurableUserGroupProvider extends CompositeUserGroupPr
@Override
public void preDestruction() throws AuthorizerDestructionException {
super.preDestruction();
try {
configurableUserGroupProvider.preDestruction();
} finally {
super.preDestruction();
}
}
}

View File

@ -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);
}
}
}