Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
import org.elasticsearch.client.security.PutUserResponse;

import java.io.IOException;
import java.util.Optional;

import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;

/**
* A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Security APIs.
Expand Down Expand Up @@ -396,9 +396,9 @@ public void deleteRoleMappingAsync(DeleteRoleMappingRequest request, RequestOpti
* @return the response from the delete role call
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public DeleteRoleResponse deleteRole(DeleteRoleRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::deleteRole, options,
DeleteRoleResponse::fromXContent, singleton(404));
public Optional<DeleteRoleResponse> deleteRole(DeleteRoleRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseOptionalEntity(request, SecurityRequestConverters::deleteRole, options,
DeleteRoleResponse::fromXContent);
}

/**
Expand All @@ -409,9 +409,9 @@ public DeleteRoleResponse deleteRole(DeleteRoleRequest request, RequestOptions o
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void deleteRoleAsync(DeleteRoleRequest request, RequestOptions options, ActionListener<DeleteRoleResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::deleteRole, options,
DeleteRoleResponse::fromXContent, listener, singleton(404));
public void deleteRoleAsync(DeleteRoleRequest request, RequestOptions options, ActionListener<Optional<DeleteRoleResponse>> listener) {
restHighLevelClient.performRequestAsyncAndParseOptionalEntity(request, SecurityRequestConverters::deleteRole, options,
DeleteRoleResponse::fromXContent, listener);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,17 @@

package org.elasticsearch.client.security;

import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;

import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;

/**
* Response for a role being deleted from the native realm
*/
public final class DeleteRoleResponse {

private final boolean found;

public DeleteRoleResponse(boolean found) {
this.found = found;
}

public boolean isFound() {
return this.found;
}

private static final ConstructingObjectParser<DeleteRoleResponse, Void> PARSER = new ConstructingObjectParser<>("delete_role_response",
true, args -> new DeleteRoleResponse((boolean) args[0]));

static {
PARSER.declareBoolean(constructorArg(), new ParseField("found"));
public DeleteRoleResponse() {
}

public static DeleteRoleResponse fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
public static DeleteRoleResponse fromXContent(XContentParser parser) {
return new DeleteRoleResponse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -712,27 +713,27 @@ public void testDeleteRole() throws Exception {
// end::delete-role-request

// tag::delete-role-execute
DeleteRoleResponse deleteRoleResponse = client.security().deleteRole(deleteRoleRequest, RequestOptions.DEFAULT);
Optional<DeleteRoleResponse> deleteRoleResponse = client.security().deleteRole(deleteRoleRequest, RequestOptions.DEFAULT);
// end::delete-role-execute

// tag::delete-role-response
boolean found = deleteRoleResponse.isFound(); // <1>
boolean found = deleteRoleResponse.isPresent(); // <1>
// end::delete-role-response
assertTrue(found);

// check if deleting the already deleted role again will give us a different response
deleteRoleResponse = client.security().deleteRole(deleteRoleRequest, RequestOptions.DEFAULT);
assertFalse(deleteRoleResponse.isFound());
assertFalse(deleteRoleResponse.isPresent());
}

{
DeleteRoleRequest deleteRoleRequest = new DeleteRoleRequest("testrole");

ActionListener<DeleteRoleResponse> listener;
ActionListener<Optional<DeleteRoleResponse>> listener;
//tag::delete-role-execute-listener
listener = new ActionListener<DeleteRoleResponse>() {
listener = new ActionListener<Optional<DeleteRoleResponse>>() {
@Override
public void onResponse(DeleteRoleResponse deleteRoleResponse) {
public void onResponse(Optional<DeleteRoleResponse> deleteRoleResponse) {
// <1>
}

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion docs/java-rest/high-level/security/delete-role.asciidoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--
:api: delete-role
:request: DeleteRoleRequest
:response: DeleteRoleResponse
:response: Optional<DeleteRoleResponse>
--

[id="{upid}-{api}"]
Expand Down