From 259366306ebf2a54fcbc1bf1b9906f6a551c5c79 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 17 Dec 2024 17:49:46 -0500 Subject: [PATCH] WIP on share with rest action from security plugin Signed-off-by: Craig Perkins --- .../security/OpenSearchSecurityPlugin.java | 3 +++ .../dlic/rest/api/SecurityRestApiActions.java | 4 +++- .../security/rest/resource/ShareWithAction.java | 7 +++---- .../rest/resource/ShareWithTransportAction.java | 17 +++++------------ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java b/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java index ab81ca5a77..8aa1eb0e02 100644 --- a/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java +++ b/src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java @@ -183,6 +183,8 @@ import org.opensearch.security.rest.SecurityInfoAction; import org.opensearch.security.rest.SecurityWhoAmIAction; import org.opensearch.security.rest.TenantInfoAction; +import org.opensearch.security.rest.resource.ShareWithAction; +import org.opensearch.security.rest.resource.ShareWithTransportAction; import org.opensearch.security.securityconf.DynamicConfigFactory; import org.opensearch.security.securityconf.impl.CType; import org.opensearch.security.setting.OpensearchDynamicSetting; @@ -701,6 +703,7 @@ public UnaryOperator getRestHandlerWrapper(final ThreadContext thre actions.add(new ActionHandler<>(CertificatesActionType.INSTANCE, TransportCertificatesInfoNodesAction.class)); } actions.add(new ActionHandler<>(WhoAmIAction.INSTANCE, TransportWhoAmIAction.class)); + actions.add(new ActionHandler<>(ShareWithAction.INSTANCE, ShareWithTransportAction.class)); } return actions; } diff --git a/src/main/java/org/opensearch/security/dlic/rest/api/SecurityRestApiActions.java b/src/main/java/org/opensearch/security/dlic/rest/api/SecurityRestApiActions.java index 926b091c91..d8c5402f81 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/api/SecurityRestApiActions.java +++ b/src/main/java/org/opensearch/security/dlic/rest/api/SecurityRestApiActions.java @@ -25,6 +25,7 @@ import org.opensearch.security.configuration.ConfigurationRepository; import org.opensearch.security.hasher.PasswordHasher; import org.opensearch.security.privileges.PrivilegesEvaluator; +import org.opensearch.security.rest.resource.ShareWithRestAction; import org.opensearch.security.spi.ResourceSharingExtension; import org.opensearch.security.ssl.SslSettingsManager; import org.opensearch.security.ssl.transport.PrincipalExtractor; @@ -107,7 +108,8 @@ public static Collection getHandler( certificatesReloadEnabled, securityApiDependencies ), - new CertificatesApiAction(clusterService, threadPool, securityApiDependencies) + new CertificatesApiAction(clusterService, threadPool, securityApiDependencies), + new ShareWithRestAction(resourceSharingExtensions) ); } diff --git a/src/main/java/org/opensearch/security/rest/resource/ShareWithAction.java b/src/main/java/org/opensearch/security/rest/resource/ShareWithAction.java index a97989270e..7e0f52ce4e 100644 --- a/src/main/java/org/opensearch/security/rest/resource/ShareWithAction.java +++ b/src/main/java/org/opensearch/security/rest/resource/ShareWithAction.java @@ -9,14 +9,13 @@ package org.opensearch.security.rest.resource; import org.opensearch.action.ActionType; -import org.opensearch.security.spi.actions.sharing.update.UpdateResourceSharingResponse; /** * Action to update sharing configuration for a sample resource */ -public class ShareWithAction extends ActionType { +public class ShareWithAction extends ActionType { /** - * Update sharing configuratino for sample resource action instance + * Update sharing configuration for sample resource action instance */ public static final ShareWithAction INSTANCE = new ShareWithAction(); /** @@ -25,6 +24,6 @@ public class ShareWithAction extends ActionType { public static final String NAME = "cluster:admin/opendistro_security/resource/share_with"; private ShareWithAction() { - super(NAME, UpdateResourceSharingResponse::new); + super(NAME, ShareWithResponse::new); } } diff --git a/src/main/java/org/opensearch/security/rest/resource/ShareWithTransportAction.java b/src/main/java/org/opensearch/security/rest/resource/ShareWithTransportAction.java index 06d2241600..014b08d5f0 100644 --- a/src/main/java/org/opensearch/security/rest/resource/ShareWithTransportAction.java +++ b/src/main/java/org/opensearch/security/rest/resource/ShareWithTransportAction.java @@ -21,16 +21,15 @@ import org.opensearch.action.update.UpdateRequest; import org.opensearch.action.update.UpdateResponse; import org.opensearch.client.Client; +import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.core.action.ActionListener; -import org.opensearch.core.common.io.stream.Writeable; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.QueryBuilders; import org.opensearch.search.SearchHit; import org.opensearch.search.builder.SearchSourceBuilder; -import org.opensearch.security.spi.Resource; import org.opensearch.security.spi.ShareWith; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; @@ -38,7 +37,7 @@ /** * Transport action for UpdateResourceSharing. */ -public class ShareWithTransportAction extends HandledTransportAction { +public class ShareWithTransportAction extends HandledTransportAction { private static final Logger log = LogManager.getLogger(ShareWithTransportAction.class); public static final String RESOURCE_SHARING_INDEX = ".resource-sharing"; @@ -46,15 +45,9 @@ public class ShareWithTransportAction extends HandledTranspo private final TransportService transportService; private final Client nodeClient; - public ShareWithTransportAction( - TransportService transportService, - ActionFilters actionFilters, - Client nodeClient, - String actionName, - String resourceIndex, - Writeable.Reader shareWithReader - ) { - super(actionName, transportService, actionFilters, (in) -> new ShareWithRequest(in, shareWithReader)); + @Inject + public ShareWithTransportAction(TransportService transportService, ActionFilters actionFilters, Client nodeClient) { + super(ShareWithAction.NAME, transportService, actionFilters, (in) -> new ShareWithRequest(in, ShareWith::new)); this.transportService = transportService; this.nodeClient = nodeClient; }