diff --git a/sandbox/modules/identity/src/main/java/org/opensearch/identity/IdentityPlugin.java b/sandbox/modules/identity/src/main/java/org/opensearch/identity/IdentityPlugin.java index ca5d2ae791f51..b005f7c6d3ec1 100644 --- a/sandbox/modules/identity/src/main/java/org/opensearch/identity/IdentityPlugin.java +++ b/sandbox/modules/identity/src/main/java/org/opensearch/identity/IdentityPlugin.java @@ -166,10 +166,7 @@ public List getRestHandlers( new ActionHandler<>(MultiGetUserAction.INSTANCE, TransportMultiGetUserAction.class), new ActionHandler<>(DeleteUserAction.INSTANCE, TransportDeleteUserAction.class), new ActionHandler<>(PutPermissionAction.INSTANCE, TransportPutPermissionAction.class), - new ActionHandler<>(DeleteUserAction.INSTANCE, TransportDeleteUserAction.class), - new ActionHandler<>(ResetPasswordAction.INSTANCE, TransportResetPasswordAction.class), - new ActionHandler<>(IdentityConfigUpdateAction.INSTANCE, TransportIdentityConfigUpdateAction.class) - + new ActionHandler<>(ResetPasswordAction.INSTANCE, TransportResetPasswordAction.class) ); } diff --git a/sandbox/modules/identity/src/main/java/org/opensearch/identity/SecurityRestFilter.java b/sandbox/modules/identity/src/main/java/org/opensearch/identity/SecurityRestFilter.java index 7575604879c8a..8d901d004f3b1 100644 --- a/sandbox/modules/identity/src/main/java/org/opensearch/identity/SecurityRestFilter.java +++ b/sandbox/modules/identity/src/main/java/org/opensearch/identity/SecurityRestFilter.java @@ -72,7 +72,9 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c if (authTokenHeader == null) { Subject currentSubject = Identity.getAuthManager().getSubject(); // TODO replace with Principal Identifier Token if destination is extension - jwtClaims.put("sub", currentSubject.getPrincipal().getName()); + if (currentSubject != null) { + jwtClaims.put("sub", currentSubject.getPrincipal().getName()); + } jwtClaims.put("iat", Instant.now().toString()); } diff --git a/sandbox/modules/identity/src/main/java/org/opensearch/identity/utils/ErrorType.java b/sandbox/modules/identity/src/main/java/org/opensearch/identity/utils/ErrorType.java index f3d882ca93e31..a0791e51cbe1c 100644 --- a/sandbox/modules/identity/src/main/java/org/opensearch/identity/utils/ErrorType.java +++ b/sandbox/modules/identity/src/main/java/org/opensearch/identity/utils/ErrorType.java @@ -19,6 +19,7 @@ public enum ErrorType { OLDPASSWORD_MISMATCHING("Old passwords do not match."), USER_NOT_EXISTING("Failed to reset password, because target user does not exist."), NEWPASSWORD_MATCHING_OLDPASSWORD("New password is same as the current password, please create another new password."); + private String message; private ErrorType(String message) { diff --git a/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/IdentityRestTestCase.java b/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/IdentityRestTestCase.java index 9fcedb92008ee..44f8907f8f986 100644 --- a/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/IdentityRestTestCase.java +++ b/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/IdentityRestTestCase.java @@ -50,7 +50,7 @@ protected boolean preserveIndicesUponCompletion() { * This warning is expected to be thrown as we are accessing identity index directly * @return the warning message to be expected */ - public RequestOptions options() { + public static RequestOptions options() { RequestOptions.Builder options = RequestOptions.DEFAULT.toBuilder(); options.addHeader("Authorization", "Basic YWRtaW46YWRtaW4="); // admin:admin; diff --git a/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/RestPermissionsIT.java b/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/RestPermissionsIT.java index 96788490a043a..fa7aef7407ffc 100644 --- a/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/RestPermissionsIT.java +++ b/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/RestPermissionsIT.java @@ -62,6 +62,7 @@ public void testPermissionsRestApi() throws Exception { // _identity/api/permissions/test Request putRequest = new Request("PUT", endpoint + "/" + username); putRequest.setJsonEntity("{ \"permission\" : \"cluster.admin/read\"}\n"); + putRequest.setOptions(IdentityRestTestCase.options()); Response putResponse = client().performRequest(putRequest); assertThat(putResponse.getStatusLine().getStatusCode(), is(200)); assertTrue(new String(putResponse.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8).contains("true")); @@ -77,6 +78,7 @@ public void testPermissionsRestApi() throws Exception { putRequest = new Request("PUT", endpoint + "/" + username); putRequest.setJsonEntity("{ \"permission\" : \":1:2:3\"}\n"); // Invalid permission + putRequest.setOptions(IdentityRestTestCase.options()); try { putResponse = client().performRequest(putRequest); } catch (ResponseException ex) { diff --git a/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/UserIT.java b/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/UserIT.java index 405bf7d31bf89..69cc8e9774451 100644 --- a/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/UserIT.java +++ b/sandbox/modules/identity/src/test/java/org/opensearch/identity/remotecluster/UserIT.java @@ -11,10 +11,7 @@ import org.opensearch.client.Request; import org.opensearch.client.Response; import org.opensearch.client.ResponseException; -import org.opensearch.identity.IdentityConfigConstants; -import org.opensearch.identity.rest.IdentityRestConstants; import org.opensearch.identity.utils.ErrorType; -import org.opensearch.test.rest.OpenSearchRestTestCase; import java.util.List; import java.util.Map; @@ -112,7 +109,7 @@ public void testResetPassword() throws Exception { String createMessage = username + " created successfully."; Request userCreationRequest = new Request("PUT", ENDPOINT + "/users/" + username); userCreationRequest.setJsonEntity(userCreationContent); - userCreationRequest.setOptions(systemIndexWarning()); + userCreationRequest.setOptions(options()); Response userCreationResponse = client().performRequest(userCreationRequest); assertEquals(userCreationResponse.getStatusLine().getStatusCode(), 200); Map userCreated = entityAsMap(userCreationResponse); @@ -123,7 +120,7 @@ public void testResetPassword() throws Exception { Request request = new Request("POST", ENDPOINT + "/users/" + username + "/resetpassword"); request.setJsonEntity(requestContent); - request.setOptions(systemIndexWarning()); + request.setOptions(options()); Response response = client().performRequest(request); assertEquals(200, response.getStatusLine().getStatusCode()); } @@ -134,7 +131,7 @@ public void testResetPasswordWithNotExistedUser() throws Exception { Request request = new Request("POST", ENDPOINT + "/users/" + username + "/resetpassword"); request.setJsonEntity(requestContent); - request.setOptions(systemIndexWarning()); + request.setOptions(options()); ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(request)); Map exception = entityAsMap(e.getResponse()); assertEquals(400, exception.get("status")); @@ -151,7 +148,7 @@ public void testResetPasswordWithBadRequests() throws Exception { String createMessage = username + " created successfully."; Request userCreationRequest = new Request("PUT", ENDPOINT + "/users/" + username); userCreationRequest.setJsonEntity(userCreationContent); - userCreationRequest.setOptions(systemIndexWarning()); + userCreationRequest.setOptions(options()); Response userCreationResponse = client().performRequest(userCreationRequest); assertEquals(userCreationResponse.getStatusLine().getStatusCode(), 200); Map userCreated = entityAsMap(userCreationResponse); @@ -163,7 +160,7 @@ public void testResetPasswordWithBadRequests() throws Exception { // Old password mismatching Request requestOldPasswordMismatching = new Request("POST", ENDPOINT + "/users/" + username + "/resetpassword"); requestOldPasswordMismatching.setJsonEntity(oldPasswordsDontMatch); - requestOldPasswordMismatching.setOptions(systemIndexWarning()); + requestOldPasswordMismatching.setOptions(options()); ResponseException eOldPasswordMismatching = expectThrows( ResponseException.class, () -> client().performRequest(requestOldPasswordMismatching) @@ -178,7 +175,7 @@ public void testResetPasswordWithBadRequests() throws Exception { // New password matching old password Request requestNewPasswordMatchingOldPassword = new Request("POST", ENDPOINT + "/users/" + username + "/resetpassword"); requestNewPasswordMatchingOldPassword.setJsonEntity(newPasswordsMatchOldPassword); - requestNewPasswordMatchingOldPassword.setOptions(systemIndexWarning()); + requestNewPasswordMatchingOldPassword.setOptions(options()); ResponseException eNewPasswordMatchingOldPassword = expectThrows( ResponseException.class, () -> client().performRequest(requestNewPasswordMatchingOldPassword)