Put User API

edit

Execution

edit

Creating and updating a user can be performed using the security().putUser() method:

char[] password = new char[]{'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
PutUserRequest request =
    new PutUserRequest("example", password, Collections.singletonList("superuser"), null, null, true, null, RefreshPolicy.NONE);
PutUserResponse response = client.security().putUser(request, RequestOptions.DEFAULT);

Response

edit

The returned PutUserResponse contains a single field, created. This field serves as an indication if a user was created or if an existing entry was updated.

boolean isCreated = response.isCreated(); 

created is a boolean indicating whether the user was created or updated

Asynchronous Execution

edit

This request can be executed asynchronously:

client.security().putUserAsync(request, RequestOptions.DEFAULT, listener); 

The PutUserRequest to execute and the ActionListener to use when the execution completes.

The asynchronous method does not block and returns immediately. Once the request has completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed.

A typical listener for a PutUserResponse looks like:

ActionListener<PutUserResponse> listener = new ActionListener<PutUserResponse>() {
    @Override
    public void onResponse(PutUserResponse response) {
        
    }

    @Override
    public void onFailure(Exception e) {
        
    }
};

Called when the execution is successfully completed. The response is provided as an argument.

Called in case of failure. The raised exception is provided as an argument.