Skip to content

Commit

Permalink
changes from PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Sam <[email protected]>
  • Loading branch information
samuelcostae committed Sep 19, 2023
1 parent 28ed6a7 commit b9bf81b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
import org.opensearch.security.support.SecurityJsonNode;
import org.opensearch.security.user.AccountType;
import org.opensearch.security.user.UserFilterType;
import org.opensearch.security.user.UserService;
import org.opensearch.security.user.UserServiceException;
import org.opensearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -138,18 +138,18 @@ private void internalUsersApiRequestHandlers(RequestHandler.RequestHandlersBuild

}

protected final ValidationResult<SecurityConfiguration> filterUsers(SecurityDynamicConfiguration users, String userType) {
userService.includeAccountsIfType(users, AccountType.fromString(userType));
protected final ValidationResult<SecurityConfiguration> filterUsers(SecurityDynamicConfiguration users, UserFilterType userType) {
userService.includeAccountsIfType(users, userType);
return ValidationResult.success(SecurityConfiguration.of(users.getCType().toString(), users));

}

protected final String filterParam(final RestRequest request) {
final String name = request.param("filterBy");
if (Strings.isNullOrEmpty(name)) {
return "any";
protected final UserFilterType filterParam(final RestRequest request) {
final String filter = request.param("filterBy");
if (Strings.isNullOrEmpty(filter)) {
return UserFilterType.ANY;
}
return name;
return UserFilterType.fromString(filter);
}

ValidationResult<String> withAuthTokenPath(final RestRequest request) throws IOException {
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/org/opensearch/security/user/AccountType.java

This file was deleted.

39 changes: 39 additions & 0 deletions src/main/java/org/opensearch/security/user/UserFilterType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.security.user;

public enum UserFilterType {

ANY("any"),
INTERNAL("internal"),
SERVICE("service");

private String name;

UserFilterType(String name) {
this.name = name;
}

public String getName() {
return this.name;
}

public static UserFilterType fromString(String name) {
for (UserFilterType b : UserFilterType.values()) {
if (b.name.equalsIgnoreCase(name)) {
return b;
}
}
return UserFilterType.ANY;
}

}
8 changes: 4 additions & 4 deletions src/main/java/org/opensearch/security/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ public static void saveAndUpdateConfigs(
* @param requestedAccountType The type of account to be kept. Should be "service" or "internal"
*
*/
public void includeAccountsIfType(SecurityDynamicConfiguration<?> configuration, AccountType requestedAccountType) {
if (requestedAccountType != AccountType.INTERNAL && requestedAccountType != AccountType.SERVICE) {
public void includeAccountsIfType(SecurityDynamicConfiguration<?> configuration, UserFilterType requestedAccountType) {
if (requestedAccountType != UserFilterType.INTERNAL && requestedAccountType != UserFilterType.SERVICE) {
return;
}
List<String> toBeRemoved = new ArrayList<>();

if (requestedAccountType == AccountType.SERVICE) {
if (requestedAccountType == UserFilterType.SERVICE) {
for (Map.Entry<String, ?> entry : configuration.getCEntries().entrySet()) {
final InternalUserV7 internalUserEntry = (InternalUserV7) entry.getValue();
final Map accountAttributes = internalUserEntry.getAttributes();
Expand All @@ -345,7 +345,7 @@ public void includeAccountsIfType(SecurityDynamicConfiguration<?> configuration,
toBeRemoved.add(accountName);
}
}
} else if (requestedAccountType == AccountType.INTERNAL) {
} else if (requestedAccountType == UserFilterType.INTERNAL) {

for (Map.Entry<String, ?> entry : configuration.getCEntries().entrySet()) {
final InternalUserV7 internalUserEntry = (InternalUserV7) entry.getValue();
Expand Down

0 comments on commit b9bf81b

Please sign in to comment.