Skip to content

Commit

Permalink
Update src/main/java/org/opensearch/security/user/UserService.java
Browse files Browse the repository at this point in the history
Co-authored-by: Darshit Chanpura <[email protected]>
Signed-off-by: Sam <[email protected]>
  • Loading branch information
samuelcostae and DarshitChanpura authored Sep 20, 2023
1 parent b9bf81b commit 81cbbc0
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/main/java/org/opensearch/security/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,29 +335,23 @@ public void includeAccountsIfType(SecurityDynamicConfiguration<?> configuration,
List<String> toBeRemoved = new ArrayList<>();

if (requestedAccountType == UserFilterType.SERVICE) {
for (Map.Entry<String, ?> entry : configuration.getCEntries().entrySet()) {
final InternalUserV7 internalUserEntry = (InternalUserV7) entry.getValue();
final Map accountAttributes = internalUserEntry.getAttributes();
final String accountName = entry.getKey();
final boolean isServiceAccount = Boolean.parseBoolean(accountAttributes.getOrDefault("service", "false").toString());

if (isServiceAccount == false) {
toBeRemoved.add(accountName);
}
}
accountToRemoveFromConfig(configuration, toBeRemoved, false);
} else if (requestedAccountType == UserFilterType.INTERNAL) {

for (Map.Entry<String, ?> entry : configuration.getCEntries().entrySet()) {
accountToRemoveFromConfig(configuration, toBeRemoved, true);
}
configuration.remove(toBeRemoved);
}

private void accountsToRemoveFromConfiguration(SecurityDynamicConfiguration<?> configuration, ArrayList<String> toBeRemoved, boolean isServiceAccountRequested) {
for (Map.Entry<String, ?> entry : configuration.getCEntries().entrySet()) {
final InternalUserV7 internalUserEntry = (InternalUserV7) entry.getValue();
final Map accountAttributes = internalUserEntry.getAttributes();
final String accountName = entry.getKey();
final boolean isServiceAccount = Boolean.parseBoolean(accountAttributes.getOrDefault("service", "false").toString());

if (isServiceAccount == true) {
if (isServiceAccount == isServiceAccountRequested) {
toBeRemoved.add(accountName);
}
}
}
configuration.remove(toBeRemoved);
}
}

0 comments on commit 81cbbc0

Please sign in to comment.