Skip to content

Commit 66530db

Browse files
authored
Deprecate HLRC security methods (#37883)
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 #37540 Relates #36938
1 parent be1bb0e commit 66530db

File tree

4 files changed

+45
-143
lines changed

4 files changed

+45
-143
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/SecurityClient.java

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.elasticsearch.client.security.DeleteUserRequest;
3939
import org.elasticsearch.client.security.DeleteUserResponse;
4040
import org.elasticsearch.client.security.DisableUserRequest;
41-
import org.elasticsearch.client.security.EmptyResponse;
4241
import org.elasticsearch.client.security.EnableUserRequest;
4342
import org.elasticsearch.client.security.GetPrivilegesRequest;
4443
import org.elasticsearch.client.security.GetPrivilegesResponse;
@@ -235,14 +234,12 @@ public void getRoleMappingsAsync(final GetRoleMappingsRequest request, final Req
235234
*
236235
* @param request the request with the user to enable
237236
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
238-
* @return the response from the enable user call
237+
* @return {@code true} if the request succeeded (the user is enabled)
239238
* @throws IOException in case there is a problem sending the request or parsing back the response
240-
* @deprecated use {@link #enableUser(RequestOptions, EnableUserRequest)} instead
241239
*/
242-
@Deprecated
243-
public EmptyResponse enableUser(EnableUserRequest request, RequestOptions options) throws IOException {
244-
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::enableUser, options,
245-
EmptyResponse::fromXContent, emptySet());
240+
public boolean enableUser(EnableUserRequest request, RequestOptions options) throws IOException {
241+
return restHighLevelClient.performRequest(request, SecurityRequestConverters::enableUser, options,
242+
RestHighLevelClient::convertExistsResponse, emptySet());
246243
}
247244

248245
/**
@@ -254,10 +251,11 @@ public EmptyResponse enableUser(EnableUserRequest request, RequestOptions option
254251
* @param request the request with the user to enable
255252
* @return {@code true} if the request succeeded (the user is enabled)
256253
* @throws IOException in case there is a problem sending the request or parsing back the response
254+
* @deprecated use {@link #enableUser(EnableUserRequest, RequestOptions)} instead
257255
*/
256+
@Deprecated
258257
public boolean enableUser(RequestOptions options, EnableUserRequest request) throws IOException {
259-
return restHighLevelClient.performRequest(request, SecurityRequestConverters::enableUser, options,
260-
RestHighLevelClient::convertExistsResponse, emptySet());
258+
return enableUser(request, options);
261259
}
262260

263261
/**
@@ -268,13 +266,11 @@ public boolean enableUser(RequestOptions options, EnableUserRequest request) thr
268266
* @param request the request with the user to enable
269267
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
270268
* @param listener the listener to be notified upon request completion
271-
* @deprecated use {@link #enableUserAsync(RequestOptions, EnableUserRequest, ActionListener)} instead
272269
*/
273-
@Deprecated
274270
public void enableUserAsync(EnableUserRequest request, RequestOptions options,
275-
ActionListener<EmptyResponse> listener) {
276-
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::enableUser, options,
277-
EmptyResponse::fromXContent, listener, emptySet());
271+
ActionListener<Boolean> listener) {
272+
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::enableUser, options,
273+
RestHighLevelClient::convertExistsResponse, listener, emptySet());
278274
}
279275

280276
/**
@@ -285,11 +281,12 @@ public void enableUserAsync(EnableUserRequest request, RequestOptions options,
285281
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
286282
* @param request the request with the user to enable
287283
* @param listener the listener to be notified upon request completion
284+
* @deprecated use {@link #enableUserAsync(EnableUserRequest, RequestOptions, ActionListener)} instead
288285
*/
286+
@Deprecated
289287
public void enableUserAsync(RequestOptions options, EnableUserRequest request,
290288
ActionListener<Boolean> listener) {
291-
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::enableUser, options,
292-
RestHighLevelClient::convertExistsResponse, listener, emptySet());
289+
enableUserAsync(request, options, listener);
293290
}
294291

295292
/**
@@ -299,14 +296,12 @@ public void enableUserAsync(RequestOptions options, EnableUserRequest request,
299296
*
300297
* @param request the request with the user to disable
301298
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
302-
* @return the response from the enable user call
299+
* @return {@code true} if the request succeeded (the user is disabled)
303300
* @throws IOException in case there is a problem sending the request or parsing back the response
304-
* @deprecated use {@link #disableUser(RequestOptions, DisableUserRequest)} instead
305301
*/
306-
@Deprecated
307-
public EmptyResponse disableUser(DisableUserRequest request, RequestOptions options) throws IOException {
308-
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::disableUser, options,
309-
EmptyResponse::fromXContent, emptySet());
302+
public boolean disableUser(DisableUserRequest request, RequestOptions options) throws IOException {
303+
return restHighLevelClient.performRequest(request, SecurityRequestConverters::disableUser, options,
304+
RestHighLevelClient::convertExistsResponse, emptySet());
310305
}
311306

312307
/**
@@ -318,10 +313,11 @@ public EmptyResponse disableUser(DisableUserRequest request, RequestOptions opti
318313
* @param request the request with the user to disable
319314
* @return {@code true} if the request succeeded (the user is disabled)
320315
* @throws IOException in case there is a problem sending the request or parsing back the response
316+
* @deprecated use {@link #disableUser(DisableUserRequest, RequestOptions)} instead
321317
*/
318+
@Deprecated
322319
public boolean disableUser(RequestOptions options, DisableUserRequest request) throws IOException {
323-
return restHighLevelClient.performRequest(request, SecurityRequestConverters::disableUser, options,
324-
RestHighLevelClient::convertExistsResponse, emptySet());
320+
return disableUser(request, options);
325321
}
326322

327323
/**
@@ -332,13 +328,11 @@ public boolean disableUser(RequestOptions options, DisableUserRequest request) t
332328
* @param request the request with the user to disable
333329
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
334330
* @param listener the listener to be notified upon request completion
335-
* @deprecated use {@link #disableUserAsync(RequestOptions, DisableUserRequest, ActionListener)} instead
336331
*/
337-
@Deprecated
338332
public void disableUserAsync(DisableUserRequest request, RequestOptions options,
339-
ActionListener<EmptyResponse> listener) {
340-
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::disableUser, options,
341-
EmptyResponse::fromXContent, listener, emptySet());
333+
ActionListener<Boolean> listener) {
334+
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::disableUser, options,
335+
RestHighLevelClient::convertExistsResponse, listener, emptySet());
342336
}
343337

344338
/**
@@ -349,11 +343,12 @@ public void disableUserAsync(DisableUserRequest request, RequestOptions options,
349343
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
350344
* @param request the request with the user to disable
351345
* @param listener the listener to be notified upon request completion
346+
* @deprecated use {@link #disableUserAsync(DisableUserRequest, RequestOptions, ActionListener)} instead
352347
*/
348+
@Deprecated
353349
public void disableUserAsync(RequestOptions options, DisableUserRequest request,
354350
ActionListener<Boolean> listener) {
355-
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::disableUser, options,
356-
RestHighLevelClient::convertExistsResponse, listener, emptySet());
351+
disableUserAsync(request, options, listener);
357352
}
358353

359354
/**
@@ -523,14 +518,12 @@ public void getSslCertificatesAsync(RequestOptions options, ActionListener<GetSs
523518
*
524519
* @param request the request with the user's new password
525520
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
526-
* @return the response from the change user password call
521+
* @return {@code true} if the request succeeded (the new password was set)
527522
* @throws IOException in case there is a problem sending the request or parsing back the response
528-
* @deprecated use {@link #changePassword(RequestOptions, ChangePasswordRequest)} instead
529523
*/
530-
@Deprecated
531-
public EmptyResponse changePassword(ChangePasswordRequest request, RequestOptions options) throws IOException {
532-
return restHighLevelClient.performRequestAndParseEntity(request, SecurityRequestConverters::changePassword, options,
533-
EmptyResponse::fromXContent, emptySet());
524+
public boolean changePassword(ChangePasswordRequest request, RequestOptions options) throws IOException {
525+
return restHighLevelClient.performRequest(request, SecurityRequestConverters::changePassword, options,
526+
RestHighLevelClient::convertExistsResponse, emptySet());
534527
}
535528

536529
/**
@@ -542,10 +535,11 @@ public EmptyResponse changePassword(ChangePasswordRequest request, RequestOption
542535
* @param request the request with the user's new password
543536
* @return {@code true} if the request succeeded (the new password was set)
544537
* @throws IOException in case there is a problem sending the request or parsing back the response
538+
* @deprecated use {@link #changePassword(ChangePasswordRequest, RequestOptions)} instead
545539
*/
540+
@Deprecated
546541
public boolean changePassword(RequestOptions options, ChangePasswordRequest request) throws IOException {
547-
return restHighLevelClient.performRequest(request, SecurityRequestConverters::changePassword, options,
548-
RestHighLevelClient::convertExistsResponse, emptySet());
542+
return changePassword(request, options);
549543
}
550544

551545
/**
@@ -556,13 +550,11 @@ public boolean changePassword(RequestOptions options, ChangePasswordRequest requ
556550
* @param request the request with the user's new password
557551
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
558552
* @param listener the listener to be notified upon request completion
559-
* @deprecated use {@link #changePasswordAsync(RequestOptions, ChangePasswordRequest, ActionListener)} instead
560553
*/
561-
@Deprecated
562554
public void changePasswordAsync(ChangePasswordRequest request, RequestOptions options,
563-
ActionListener<EmptyResponse> listener) {
564-
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::changePassword, options,
565-
EmptyResponse::fromXContent, listener, emptySet());
555+
ActionListener<Boolean> listener) {
556+
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::changePassword, options,
557+
RestHighLevelClient::convertExistsResponse, listener, emptySet());
566558
}
567559

568560
/**
@@ -573,14 +565,14 @@ public void changePasswordAsync(ChangePasswordRequest request, RequestOptions op
573565
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
574566
* @param request the request with the user's new password
575567
* @param listener the listener to be notified upon request completion
568+
* @deprecated use {@link #changePasswordAsync(ChangePasswordRequest, RequestOptions, ActionListener)} instead
576569
*/
570+
@Deprecated
577571
public void changePasswordAsync(RequestOptions options, ChangePasswordRequest request,
578572
ActionListener<Boolean> listener) {
579-
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::changePassword, options,
580-
RestHighLevelClient::convertExistsResponse, listener, emptySet());
573+
changePasswordAsync(request, options, listener);
581574
}
582575

583-
584576
/**
585577
* Delete a role mapping.
586578
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role-mapping.html">

client/rest-high-level/src/main/java/org/elasticsearch/client/security/EmptyResponse.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SecurityDocumentationIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public void testEnableUser() throws Exception {
517517
{
518518
//tag::enable-user-execute
519519
EnableUserRequest request = new EnableUserRequest("enable_user", RefreshPolicy.NONE);
520-
boolean response = client.security().enableUser(RequestOptions.DEFAULT, request);
520+
boolean response = client.security().enableUser(request, RequestOptions.DEFAULT);
521521
//end::enable-user-execute
522522

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

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

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

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

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

594594
assertTrue(latch.await(30L, TimeUnit.SECONDS));
@@ -1038,7 +1038,7 @@ public void testChangePassword() throws Exception {
10381038
{
10391039
//tag::change-password-execute
10401040
ChangePasswordRequest request = new ChangePasswordRequest("change_password_user", newPassword, RefreshPolicy.NONE);
1041-
boolean response = client.security().changePassword(RequestOptions.DEFAULT, request);
1041+
boolean response = client.security().changePassword(request, RequestOptions.DEFAULT);
10421042
//end::change-password-execute
10431043

10441044
assertTrue(response);
@@ -1064,7 +1064,7 @@ public void onFailure(Exception e) {
10641064
listener = new LatchedActionListener<>(listener, latch);
10651065

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

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

client/rest-high-level/src/test/java/org/elasticsearch/client/security/EmptyResponseTests.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)