From 828ef2be96c9d2b7977a4273a2d3634513b4bfa4 Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Tue, 3 Oct 2023 18:23:49 +0000 Subject: [PATCH] Fix parameter consumption Signed-off-by: Peter Nied --- .../security/dlic/rest/api/AbstractApiAction.java | 7 ++++--- .../security/filter/OpenSearchRequestChannel.java | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java b/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java index 15308aaa6c..fb0e584f66 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java +++ b/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java @@ -536,12 +536,13 @@ public void onFailure(Exception e) { @Override protected final RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + // consume all parameters first so we can return a correct HTTP status, + // not 400 + consumeParameters(request); + return channel -> { final SecurityRequestChannel securityRequest = SecurityRequestFactory.from(request, channel); - // consume all parameters first so we can return a correct HTTP status, - // not 400 - consumeParameters(request); // check if .opendistro_security index has been initialized if (!ensureIndexExists()) { diff --git a/src/main/java/org/opensearch/security/filter/OpenSearchRequestChannel.java b/src/main/java/org/opensearch/security/filter/OpenSearchRequestChannel.java index c47e4207dd..50273fc137 100644 --- a/src/main/java/org/opensearch/security/filter/OpenSearchRequestChannel.java +++ b/src/main/java/org/opensearch/security/filter/OpenSearchRequestChannel.java @@ -35,7 +35,9 @@ public boolean completeWithResponse(int statusCode, Map headers, try { final BytesRestResponse restResponse = new BytesRestResponse(RestStatus.fromCode(statusCode), body); - headers.forEach(restResponse::addHeader); + if (headers != null) { + headers.forEach(restResponse::addHeader); + } underlyingChannel.sendResponse(restResponse); return true;