Skip to content

Commit

Permalink
RANGER-4783: remove duplicate entries of users/groups/roles during in…
Browse files Browse the repository at this point in the history
… policy (#311)
  • Loading branch information
fateh288 committed May 6, 2024
1 parent fa18ffb commit e6b83f3
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,13 @@ private String getDuplicate(List<String> values) {
}
return duplicate;
}
private static void removeDuplicates(List<String> values){
if (values==null || values.isEmpty()){
return;
}
HashSet<String> uniqueElements = new HashSet<>();
values.removeIf(e -> !uniqueElements.add(e));
}

boolean isValidPolicyItems(List<RangerPolicyItem> policyItems, List<ValidationFailureDetails> failures, RangerServiceDef serviceDef) {
if(LOG.isDebugEnabled()) {
Expand Down Expand Up @@ -1030,6 +1037,9 @@ boolean isValidPolicyItem(RangerPolicyItem policyItem, List<ValidationFailureDet
.build());
valid = false;
} else {
removeDuplicates(policyItem.getUsers());
removeDuplicates(policyItem.getGroups());
removeDuplicates(policyItem.getRoles());
if (CollectionUtils.isNotEmpty(policyItem.getUsers()) && CollectionUtils.containsAny(policyItem.getUsers(), invalidItems)) {
ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_NULL_POLICY_ITEM_USER;
failures.add(new ValidationFailureDetailsBuilder()
Expand Down

0 comments on commit e6b83f3

Please sign in to comment.