From e468f91dc9c34c90c2b318cb517b8ac1a55dae27 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Thu, 5 Dec 2024 17:47:45 -0500 Subject: [PATCH] Convert sets to lists Signed-off-by: Darshit Chanpura --- .../accesscontrol/resources/ShareWith.java | 16 ++++++++-------- .../plugins/NoOpResourceAccessControlPlugin.java | 10 +++++----- .../plugins/ResourceAccessControlPlugin.java | 13 ++++--------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java b/server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java index 1761efb45af3e..c50a973cef52d 100644 --- a/server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java +++ b/server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java @@ -16,8 +16,8 @@ import org.opensearch.core.xcontent.XContentParser; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Set; /** * This class contains information about whom a resource is shared with and at what scope. @@ -39,17 +39,17 @@ */ public class ShareWith implements ToXContentFragment, NamedWriteable { - private final List sharedWithScopes; + private final Set sharedWithScopes; - public ShareWith(List sharedWithScopes) { + public ShareWith(Set sharedWithScopes) { this.sharedWithScopes = sharedWithScopes; } public ShareWith(StreamInput in) throws IOException { - this.sharedWithScopes = in.readList(SharedWithScope::new); + this.sharedWithScopes = in.readSet(SharedWithScope::new); } - public List getSharedWithScopes() { + public Set getSharedWithScopes() { return sharedWithScopes; } @@ -65,7 +65,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } public static ShareWith fromXContent(XContentParser parser) throws IOException { - List sharedWithScopes = new ArrayList<>(); + Set sharedWithScopes = new HashSet<>(); if (parser.currentToken() != XContentParser.Token.START_OBJECT) { parser.nextToken(); @@ -90,7 +90,7 @@ public String getWriteableName() { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeList(sharedWithScopes); + out.writeCollection(sharedWithScopes); } @Override diff --git a/server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java b/server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java index f784fcf2f7ec7..171f7b2a18d28 100644 --- a/server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java @@ -12,8 +12,8 @@ import org.opensearch.accesscontrol.resources.ResourceSharing; import org.opensearch.accesscontrol.resources.ShareWith; -import java.util.List; import java.util.Map; +import java.util.Set; /** * This plugin class defines a no-op implementation of Resource Plugin. @@ -29,10 +29,10 @@ public class NoOpResourceAccessControlPlugin implements ResourceAccessControlPlu * @return empty list */ @Override - public List listAccessibleResourcesInPlugin(String systemIndexName) { + public Set listAccessibleResourcesInPlugin(String systemIndexName) { // returns an empty list since security plugin is disabled // TODO: check whether this should return all entries in the given index - return List.of(); + return Set.of(); } /** @@ -68,8 +68,8 @@ public ResourceSharing shareWith(String resourceId, String systemIndexName, Shar public ResourceSharing revokeAccess( String resourceId, String systemIndexName, - Map> revokeAccess, - List scopes + Map> revokeAccess, + Set scopes ) { return null; } diff --git a/server/src/main/java/org/opensearch/plugins/ResourceAccessControlPlugin.java b/server/src/main/java/org/opensearch/plugins/ResourceAccessControlPlugin.java index 1193c34d7379d..608a9a884c78d 100644 --- a/server/src/main/java/org/opensearch/plugins/ResourceAccessControlPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/ResourceAccessControlPlugin.java @@ -12,8 +12,8 @@ import org.opensearch.accesscontrol.resources.ResourceSharing; import org.opensearch.accesscontrol.resources.ShareWith; -import java.util.List; import java.util.Map; +import java.util.Set; /** * This interface determines presence of security plugin in the cluster. @@ -31,9 +31,9 @@ public interface ResourceAccessControlPlugin { /** * Returns all accessible resources for current user for a given system . * - * @return list of {@link ResourceSharing} items accessible by current user. + * @return set of {@link ResourceSharing} items accessible by current user. */ - List listAccessibleResourcesInPlugin(String systemIndex); + Set listAccessibleResourcesInPlugin(String systemIndex); /** * Checks whether current user has permission to given resource. @@ -64,12 +64,7 @@ public interface ResourceAccessControlPlugin { * @param scopes Scopes to be checked for revoking access. If empty, all scopes will be checked. * @return the updated ResourceSharing record */ - ResourceSharing revokeAccess( - String resourceId, - String systemIndexName, - Map> revokeAccess, - List scopes - ); + ResourceSharing revokeAccess(String resourceId, String systemIndexName, Map> revokeAccess, Set scopes); /** * Deletes an entry from .resource_sharing index