From 5b0ec41b5e12442fd57ece718bbb041858aae7a1 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 18:52:29 -0700 Subject: [PATCH] Change connector access control creation allow empty list (#1085) Signed-off-by: zane-neo (cherry picked from commit 66750bb1d04adcfe099b0da2ec14cc86ee4620f2) Co-authored-by: zane-neo --- .../common/transport/connector/MLCreateConnectorInput.java | 7 ++++--- .../action/connector/TransportCreateConnectorAction.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java b/common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java index dc7c6f0b0d..aec2d1b0b6 100644 --- a/common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java +++ b/common/src/main/java/org/opensearch/ml/common/transport/connector/MLCreateConnectorInput.java @@ -10,6 +10,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.io.stream.Writeable; +import org.opensearch.common.util.CollectionUtils; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -184,7 +185,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws if (actions != null) { builder.field(CONNECTOR_ACTIONS_FIELD, actions); } - if (backendRoles != null) { + if (!CollectionUtils.isEmpty(backendRoles)) { builder.field(BACKEND_ROLES_FIELD, backendRoles); } if (addAllBackendRoles != null) { @@ -224,7 +225,7 @@ public void writeTo(StreamOutput output) throws IOException { } else { output.writeBoolean(false); } - if (backendRoles != null) { + if (!CollectionUtils.isEmpty(backendRoles)) { output.writeBoolean(true); output.writeOptionalStringCollection(backendRoles); } else { @@ -267,4 +268,4 @@ public MLCreateConnectorInput(StreamInput input) throws IOException { } dryRun = input.readBoolean(); } -} \ No newline at end of file +} diff --git a/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java b/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java index a0bf60788e..0408fafe96 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/connector/TransportCreateConnectorAction.java @@ -193,7 +193,7 @@ private void validateRequest4AccessControl(MLCreateConnectorInput input, User us } private void validateSecurityDisabledOrConnectorAccessControlDisabled(MLCreateConnectorInput input) { - if (input.getAccess() != null || input.getAddAllBackendRoles() != null || input.getBackendRoles() != null) { + if (input.getAccess() != null || input.getAddAllBackendRoles() != null || !CollectionUtils.isEmpty(input.getBackendRoles())) { throw new IllegalArgumentException( "You cannot specify connector access control parameters because the Security plugin or connector access control is disabled on your cluster." );