Skip to content

Commit

Permalink
[Test] Remove API key methods from HLRC (#85802)
Browse files Browse the repository at this point in the history
The High Level Rest Client (HLRC) is deprecated and is no longer
shipped as a standalone artifact.
It can now be safely removed from the ES codebase.

This commit removes all API key methods from the HLRC
SecurityClient, along with their associated Request/Response
classes.

Test code that depended on these methods has been migrated
to use TestSecurityClient instead.

Relates: #83423
  • Loading branch information
tvernum committed Apr 19, 2022
1 parent 88600d1 commit b49a799
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 964 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
import org.elasticsearch.client.security.ClearRealmCacheResponse;
import org.elasticsearch.client.security.DelegatePkiAuthenticationRequest;
import org.elasticsearch.client.security.DelegatePkiAuthenticationResponse;
import org.elasticsearch.client.security.GetApiKeyRequest;
import org.elasticsearch.client.security.GetApiKeyResponse;
import org.elasticsearch.client.security.InvalidateApiKeyRequest;
import org.elasticsearch.client.security.InvalidateApiKeyResponse;

import java.io.IOException;

Expand Down Expand Up @@ -60,47 +56,6 @@ public ClearRealmCacheResponse clearRealmCache(ClearRealmCacheRequest request, R
);
}

/**
* Retrieve API Key(s) information.<br>
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-api-key.html">
* the docs</a> for more.
*
* @param request the request to retrieve API key(s)
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response from the get API key call
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetApiKeyResponse getApiKey(final GetApiKeyRequest request, final RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
SecurityRequestConverters::getApiKey,
options,
GetApiKeyResponse::fromXContent,
emptySet()
);
}

/**
* Invalidate API Key(s).<br>
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-api-key.html">
* the docs</a> for more.
*
* @param request the request to invalidate API key(s)
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response from the invalidate API key call
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public InvalidateApiKeyResponse invalidateApiKey(final InvalidateApiKeyRequest request, final RequestOptions options)
throws IOException {
return restHighLevelClient.performRequestAndParseEntity(
request,
SecurityRequestConverters::invalidateApiKey,
options,
InvalidateApiKeyResponse::fromXContent,
emptySet()
);
}

/**
* Get an Elasticsearch access token from an {@code X509Certificate} chain. The certificate chain is that of the client from a mutually
* authenticated TLS session, and it is validated by the PKI realms with {@code delegation.enabled} toggled to {@code true}.<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@

package org.elasticsearch.client;

import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.elasticsearch.client.security.ClearRealmCacheRequest;
import org.elasticsearch.client.security.DelegatePkiAuthenticationRequest;
import org.elasticsearch.client.security.GetApiKeyRequest;
import org.elasticsearch.client.security.InvalidateApiKeyRequest;
import org.elasticsearch.common.Strings;

import java.io.IOException;
Expand Down Expand Up @@ -49,28 +45,4 @@ static Request delegatePkiAuthentication(DelegatePkiAuthenticationRequest delega
return request;
}

static Request getApiKey(final GetApiKeyRequest getApiKeyRequest) throws IOException {
final Request request = new Request(HttpGet.METHOD_NAME, "/_security/api_key");
if (Strings.hasText(getApiKeyRequest.getId())) {
request.addParameter("id", getApiKeyRequest.getId());
}
if (Strings.hasText(getApiKeyRequest.getName())) {
request.addParameter("name", getApiKeyRequest.getName());
}
if (Strings.hasText(getApiKeyRequest.getUserName())) {
request.addParameter("username", getApiKeyRequest.getUserName());
}
if (Strings.hasText(getApiKeyRequest.getRealmName())) {
request.addParameter("realm_name", getApiKeyRequest.getRealmName());
}
request.addParameter("owner", Boolean.toString(getApiKeyRequest.ownedByAuthenticatedUser()));
return request;
}

static Request invalidateApiKey(final InvalidateApiKeyRequest invalidateApiKeyRequest) throws IOException {
final Request request = new Request(HttpDelete.METHOD_NAME, "/_security/api_key");
request.setEntity(createEntity(invalidateApiKeyRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

}

This file was deleted.

This file was deleted.

0 comments on commit b49a799

Please sign in to comment.