Skip to content

Commit

Permalink
Deprecate HLRC security methods
Browse files Browse the repository at this point in the history
This commit deprecates the few methods that had their parameters
reordered to facilitate the move from EmptyResponse to boolean. This
commit also readds the boolean based methods with the proper
signatures.

Relates elastic#37540
Relates elastic#36938
  • Loading branch information
hub-cap committed Jan 17, 2019
1 parent 56e4827 commit e3a6fa1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,12 @@ public void getRoleMappingsAsync(final GetRoleMappingsRequest request, final Req
*
* @param request the request with the user to enable
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response from the enable user call
* @return {@code true} if the request succeeded (the user is enabled)
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #enableUser(RequestOptions, EnableUserRequest)} instead
*/
@Deprecated
public EmptyResponse enableUser(EnableUserRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::enableUser, options,
EmptyResponse::fromXContent, emptySet());
public boolean enableUser(EnableUserRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequest(request, SecurityRequestConverters::enableUser, options,
RestHighLevelClient::convertExistsResponse, emptySet());
}

/**
Expand All @@ -254,7 +252,9 @@ public EmptyResponse enableUser(EnableUserRequest request, RequestOptions option
* @param request the request with the user to enable
* @return {@code true} if the request succeeded (the user is enabled)
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #enableUser(EnableUserRequest, RequestOptions)} instead
*/
@Deprecated
public boolean enableUser(RequestOptions options, EnableUserRequest request) throws IOException {
return restHighLevelClient.performRequest(request, SecurityRequestConverters::enableUser, options,
RestHighLevelClient::convertExistsResponse, emptySet());
Expand All @@ -268,13 +268,11 @@ public boolean enableUser(RequestOptions options, EnableUserRequest request) thr
* @param request the request with the user to enable
* @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
* @deprecated use {@link #enableUserAsync(RequestOptions, EnableUserRequest, ActionListener)} instead
*/
@Deprecated
public void enableUserAsync(EnableUserRequest request, RequestOptions options,
ActionListener<EmptyResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::enableUser, options,
EmptyResponse::fromXContent, listener, emptySet());
ActionListener<Boolean> listener) {
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::enableUser, options,
RestHighLevelClient::convertExistsResponse, listener, emptySet());
}

/**
Expand All @@ -285,7 +283,9 @@ public void enableUserAsync(EnableUserRequest request, RequestOptions options,
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param request the request with the user to enable
* @param listener the listener to be notified upon request completion
* @deprecated use {@link #enableUserAsync(EnableUserRequest, RequestOptions, ActionListener)} instead
*/
@Deprecated
public void enableUserAsync(RequestOptions options, EnableUserRequest request,
ActionListener<Boolean> listener) {
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::enableUser, options,
Expand All @@ -299,14 +299,12 @@ public void enableUserAsync(RequestOptions options, EnableUserRequest request,
*
* @param request the request with the user to disable
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response from the enable user call
* @return {@code true} if the request succeeded (the user is disabled)
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #disableUser(RequestOptions, DisableUserRequest)} instead
*/
@Deprecated
public EmptyResponse disableUser(DisableUserRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::disableUser, options,
EmptyResponse::fromXContent, emptySet());
public boolean disableUser(DisableUserRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequest(request, SecurityRequestConverters::disableUser, options,
RestHighLevelClient::convertExistsResponse, emptySet());
}

/**
Expand All @@ -318,7 +316,9 @@ public EmptyResponse disableUser(DisableUserRequest request, RequestOptions opti
* @param request the request with the user to disable
* @return {@code true} if the request succeeded (the user is disabled)
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #disableUser(DisableUserRequest, RequestOptions)} instead
*/
@Deprecated
public boolean disableUser(RequestOptions options, DisableUserRequest request) throws IOException {
return restHighLevelClient.performRequest(request, SecurityRequestConverters::disableUser, options,
RestHighLevelClient::convertExistsResponse, emptySet());
Expand All @@ -332,13 +332,11 @@ public boolean disableUser(RequestOptions options, DisableUserRequest request) t
* @param request the request with the user to disable
* @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
* @deprecated use {@link #disableUserAsync(RequestOptions, DisableUserRequest, ActionListener)} instead
*/
@Deprecated
public void disableUserAsync(DisableUserRequest request, RequestOptions options,
ActionListener<EmptyResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::disableUser, options,
EmptyResponse::fromXContent, listener, emptySet());
ActionListener<Boolean> listener) {
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::disableUser, options,
RestHighLevelClient::convertExistsResponse, listener, emptySet());
}

/**
Expand All @@ -349,7 +347,9 @@ public void disableUserAsync(DisableUserRequest request, RequestOptions options,
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param request the request with the user to disable
* @param listener the listener to be notified upon request completion
* @deprecated use {@link #disableUserAsync(DisableUserRequest, RequestOptions, ActionListener)} instead
*/
@Deprecated
public void disableUserAsync(RequestOptions options, DisableUserRequest request,
ActionListener<Boolean> listener) {
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::disableUser, options,
Expand Down Expand Up @@ -523,14 +523,12 @@ public void getSslCertificatesAsync(RequestOptions options, ActionListener<GetSs
*
* @param request the request with the user's new password
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response from the change user password call
* @return {@code true} if the request succeeded (the new password was set)
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #changePassword(RequestOptions, ChangePasswordRequest)} instead
*/
@Deprecated
public EmptyResponse changePassword(ChangePasswordRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::changePassword, options,
EmptyResponse::fromXContent, emptySet());
public boolean changePassword(ChangePasswordRequest request, RequestOptions options) throws IOException {
return restHighLevelClient.performRequest(request, SecurityRequestConverters::changePassword, options,
RestHighLevelClient::convertExistsResponse, emptySet());
}

/**
Expand All @@ -542,7 +540,9 @@ public EmptyResponse changePassword(ChangePasswordRequest request, RequestOption
* @param request the request with the user's new password
* @return {@code true} if the request succeeded (the new password was set)
* @throws IOException in case there is a problem sending the request or parsing back the response
* @deprecated use {@link #changePassword(ChangePasswordRequest, RequestOptions)} instead
*/
@Deprecated
public boolean changePassword(RequestOptions options, ChangePasswordRequest request) throws IOException {
return restHighLevelClient.performRequest(request, SecurityRequestConverters::changePassword, options,
RestHighLevelClient::convertExistsResponse, emptySet());
Expand All @@ -556,13 +556,11 @@ public boolean changePassword(RequestOptions options, ChangePasswordRequest requ
* @param request the request with the user's new password
* @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
* @deprecated use {@link #changePasswordAsync(RequestOptions, ChangePasswordRequest, ActionListener)} instead
*/
@Deprecated
public void changePasswordAsync(ChangePasswordRequest request, RequestOptions options,
ActionListener<EmptyResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::changePassword, options,
EmptyResponse::fromXContent, listener, emptySet());
ActionListener<Boolean> listener) {
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::changePassword, options,
RestHighLevelClient::convertExistsResponse, listener, emptySet());
}

/**
Expand All @@ -573,14 +571,15 @@ public void changePasswordAsync(ChangePasswordRequest request, RequestOptions op
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param request the request with the user's new password
* @param listener the listener to be notified upon request completion
* @deprecated use {@link #changePasswordAsync(ChangePasswordRequest, RequestOptions, ActionListener)} instead
*/
@Deprecated
public void changePasswordAsync(RequestOptions options, ChangePasswordRequest request,
ActionListener<Boolean> listener) {
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::changePassword, options,
RestHighLevelClient::convertExistsResponse, listener, emptySet());
}


/**
* Delete a role mapping.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role-mapping.html">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public void testEnableUser() throws Exception {
{
//tag::enable-user-execute
EnableUserRequest request = new EnableUserRequest("enable_user", RefreshPolicy.NONE);
boolean response = client.security().enableUser(RequestOptions.DEFAULT, request);
boolean response = client.security().enableUser(request, RequestOptions.DEFAULT);
//end::enable-user-execute

assertTrue(response);
Expand All @@ -544,7 +544,7 @@ public void onFailure(Exception e) {
listener = new LatchedActionListener<>(listener, latch);

// tag::enable-user-execute-async
client.security().enableUserAsync(RequestOptions.DEFAULT, request, listener); // <1>
client.security().enableUserAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::enable-user-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
Expand All @@ -561,7 +561,7 @@ public void testDisableUser() throws Exception {
{
//tag::disable-user-execute
DisableUserRequest request = new DisableUserRequest("disable_user", RefreshPolicy.NONE);
boolean response = client.security().disableUser(RequestOptions.DEFAULT, request);
boolean response = client.security().disableUser(request, RequestOptions.DEFAULT);
//end::disable-user-execute

assertTrue(response);
Expand All @@ -588,7 +588,7 @@ public void onFailure(Exception e) {
listener = new LatchedActionListener<>(listener, latch);

// tag::disable-user-execute-async
client.security().disableUserAsync(RequestOptions.DEFAULT, request, listener); // <1>
client.security().disableUserAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::disable-user-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public void testChangePassword() throws Exception {
{
//tag::change-password-execute
ChangePasswordRequest request = new ChangePasswordRequest("change_password_user", newPassword, RefreshPolicy.NONE);
boolean response = client.security().changePassword(RequestOptions.DEFAULT, request);
boolean response = client.security().changePassword(request, RequestOptions.DEFAULT);
//end::change-password-execute

assertTrue(response);
Expand All @@ -1062,7 +1062,7 @@ public void onFailure(Exception e) {
listener = new LatchedActionListener<>(listener, latch);

//tag::change-password-execute-async
client.security().changePasswordAsync(RequestOptions.DEFAULT, request, listener); // <1>
client.security().changePasswordAsync(request, RequestOptions.DEFAULT, listener); // <1>
//end::change-password-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
Expand Down

0 comments on commit e3a6fa1

Please sign in to comment.