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
This commit is contained in:
parent
be1bb0ec7d
commit
66530dbde0
|
@ -38,7 +38,6 @@ import org.elasticsearch.client.security.DeleteRoleResponse;
|
|||
import org.elasticsearch.client.security.DeleteUserRequest;
|
||||
import org.elasticsearch.client.security.DeleteUserResponse;
|
||||
import org.elasticsearch.client.security.DisableUserRequest;
|
||||
import org.elasticsearch.client.security.EmptyResponse;
|
||||
import org.elasticsearch.client.security.EnableUserRequest;
|
||||
import org.elasticsearch.client.security.GetPrivilegesRequest;
|
||||
import org.elasticsearch.client.security.GetPrivilegesResponse;
|
||||
|
@ -235,14 +234,12 @@ public final class SecurityClient {
|
|||
*
|
||||
* @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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,27 +251,11 @@ public final class SecurityClient {
|
|||
* @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
|
||||
*/
|
||||
public boolean enableUser(RequestOptions options, EnableUserRequest request) throws IOException {
|
||||
return restHighLevelClient.performRequest(request, SecurityRequestConverters::enableUser, options,
|
||||
RestHighLevelClient::convertExistsResponse, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a native realm or built-in user asynchronously.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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 use {@link #enableUser(EnableUserRequest, RequestOptions)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void enableUserAsync(EnableUserRequest request, RequestOptions options,
|
||||
ActionListener<EmptyResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::enableUser, options,
|
||||
EmptyResponse::fromXContent, listener, emptySet());
|
||||
public boolean enableUser(RequestOptions options, EnableUserRequest request) throws IOException {
|
||||
return enableUser(request, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -282,16 +263,32 @@ public final class SecurityClient {
|
|||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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 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 enableUserAsync(RequestOptions options, EnableUserRequest request,
|
||||
public void enableUserAsync(EnableUserRequest request, RequestOptions options,
|
||||
ActionListener<Boolean> listener) {
|
||||
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::enableUser, options,
|
||||
RestHighLevelClient::convertExistsResponse, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a native realm or built-in user asynchronously.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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) {
|
||||
enableUserAsync(request, options, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a native realm or built-in user synchronously.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html">
|
||||
|
@ -299,14 +296,12 @@ public final class SecurityClient {
|
|||
*
|
||||
* @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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,27 +313,11 @@ public final class SecurityClient {
|
|||
* @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
|
||||
*/
|
||||
public boolean disableUser(RequestOptions options, DisableUserRequest request) throws IOException {
|
||||
return restHighLevelClient.performRequest(request, SecurityRequestConverters::disableUser, options,
|
||||
RestHighLevelClient::convertExistsResponse, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a native realm or built-in user asynchronously.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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 use {@link #disableUser(DisableUserRequest, RequestOptions)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void disableUserAsync(DisableUserRequest request, RequestOptions options,
|
||||
ActionListener<EmptyResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::disableUser, options,
|
||||
EmptyResponse::fromXContent, listener, emptySet());
|
||||
public boolean disableUser(RequestOptions options, DisableUserRequest request) throws IOException {
|
||||
return disableUser(request, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -346,16 +325,32 @@ public final class SecurityClient {
|
|||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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 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 disableUserAsync(RequestOptions options, DisableUserRequest request,
|
||||
public void disableUserAsync(DisableUserRequest request, RequestOptions options,
|
||||
ActionListener<Boolean> listener) {
|
||||
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::disableUser, options,
|
||||
RestHighLevelClient::convertExistsResponse, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a native realm or built-in user asynchronously.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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) {
|
||||
disableUserAsync(request, options, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate the current user and return all the information about the authenticated user.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-authenticate.html">
|
||||
|
@ -523,14 +518,12 @@ public final class SecurityClient {
|
|||
*
|
||||
* @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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,27 +535,11 @@ public final class SecurityClient {
|
|||
* @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
|
||||
*/
|
||||
public boolean changePassword(RequestOptions options, ChangePasswordRequest request) throws IOException {
|
||||
return restHighLevelClient.performRequest(request, SecurityRequestConverters::changePassword, options,
|
||||
RestHighLevelClient::convertExistsResponse, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the password of a user of a native realm or built-in user asynchronously.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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 use {@link #changePassword(ChangePasswordRequest, RequestOptions)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void changePasswordAsync(ChangePasswordRequest request, RequestOptions options,
|
||||
ActionListener<EmptyResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request, SecurityRequestConverters::changePassword, options,
|
||||
EmptyResponse::fromXContent, listener, emptySet());
|
||||
public boolean changePassword(RequestOptions options, ChangePasswordRequest request) throws IOException {
|
||||
return changePassword(request, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -570,16 +547,31 @@ public final class SecurityClient {
|
|||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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 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 changePasswordAsync(RequestOptions options, ChangePasswordRequest request,
|
||||
public void changePasswordAsync(ChangePasswordRequest request, RequestOptions options,
|
||||
ActionListener<Boolean> listener) {
|
||||
restHighLevelClient.performRequestAsync(request, SecurityRequestConverters::changePassword, options,
|
||||
RestHighLevelClient::convertExistsResponse, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the password of a user of a native realm or built-in user asynchronously.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html">
|
||||
* the docs</a> for more.
|
||||
*
|
||||
* @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) {
|
||||
changePasswordAsync(request, options, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a role mapping.
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client.security;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Response for a request which simply returns an empty object.
|
||||
@deprecated Use a boolean instead of this class
|
||||
*/
|
||||
@Deprecated
|
||||
public final class EmptyResponse {
|
||||
|
||||
private static final ObjectParser<EmptyResponse, Void> PARSER = new ObjectParser<>("empty_response", false, EmptyResponse::new);
|
||||
|
||||
public static EmptyResponse fromXContent(XContentParser parser) throws IOException {
|
||||
return PARSER.parse(parser, null);
|
||||
}
|
||||
}
|
|
@ -517,7 +517,7 @@ public class SecurityDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
//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);
|
||||
|
@ -544,7 +544,7 @@ public class SecurityDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
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));
|
||||
|
@ -561,7 +561,7 @@ public class SecurityDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
//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);
|
||||
|
@ -588,7 +588,7 @@ public class SecurityDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
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));
|
||||
|
@ -1038,7 +1038,7 @@ public class SecurityDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
{
|
||||
//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);
|
||||
|
@ -1064,7 +1064,7 @@ public class SecurityDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
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));
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client.security;
|
||||
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
public class EmptyResponseTests extends ESTestCase {
|
||||
|
||||
public void testParseFromXContent() throws IOException {
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, "{}")) {
|
||||
|
||||
EmptyResponse response = EmptyResponse.fromXContent(parser);
|
||||
assertNotNull(response);
|
||||
}
|
||||
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, "{\"foo\": \"bar\"}")) {
|
||||
|
||||
XContentParseException exception =
|
||||
expectThrows(XContentParseException.class, () -> EmptyResponse.fromXContent(parser));
|
||||
assertThat(exception.getMessage(), containsString("field [foo]"));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue