Skip to content

Commit

Permalink
NIFI-4750 Ensuring preDestruction is called on authorizer and appropr…
Browse files Browse the repository at this point in the history
…iate policy/user-group providers. This closes apache#2387
  • Loading branch information
bbende authored and mcgilman committed Jan 8, 2018
1 parent 8f635f1 commit 4196140
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,37 @@ public boolean isSingleton() {
@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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public UserAndGroups getUserAndGroups(String identity) throws AuthorizationAcces

@Override
public void preDestruction() throws AuthorizerDestructionException {
super.preDestruction();
try {
configurableUserGroupProvider.preDestruction();
} finally {
super.preDestruction();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,18 @@ public UserAndGroups getUserAndGroups(String identity) throws AuthorizationAcces

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

0 comments on commit 4196140

Please sign in to comment.