Get API Key information APIedit

API Key(s) information can be retrieved using this API.

Get API Key Requestedit

The GetApiKeyRequest supports retrieving API key information for

  1. A specific API key
  2. All API keys for a specific realm
  3. All API keys for a specific user
  4. All API keys for a specific user in a specific realm

Retrieve a specific API key by its idedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyId(createApiKeyResponse1.getId());

Retrieve a specific API key by its nameedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingApiKeyName(createApiKeyResponse1.getName());

Retrieve all API keys for given realmedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmName("default_file");

Retrieve all API keys for a given useredit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingUserName("test_user");

Retrieve all API keys for given user in a realmedit

GetApiKeyRequest getApiKeyRequest = GetApiKeyRequest.usingRealmAndUserName("default_file", "test_user");

Synchronous Executionedit

When executing a GetApiKeyRequest in the following manner, the client waits for the GetApiKeyResponse to be returned before continuing with code execution:

GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT);

Synchronous calls may throw an IOException in case of either failing to parse the REST response in the high-level REST client, the request times out or similar cases where there is no response coming back from the server.

In cases where the server returns a 4xx or 5xx error code, the high-level client tries to parse the response body error details instead and then throws a generic ElasticsearchException and adds the original ResponseException as a suppressed exception to it.

Asynchronous Executionedit

Executing a GetApiKeyRequest can also be done in an asynchronous fashion so that the client can return directly. Users need to specify how the response or potential failures will be handled by passing the request and a listener to the asynchronous get-api-key method:

client.security().getApiKeyAsync(getApiKeyRequest, RequestOptions.DEFAULT, listener); 

The GetApiKeyRequest to execute and the ActionListener to use when the execution completes

The asynchronous method does not block and returns immediately. Once it is completed the ActionListener is called back using the onResponse method if the execution successfully completed or using the onFailure method if it failed. Failure scenarios and expected exceptions are the same as in the synchronous execution case.

A typical listener for get-api-key looks like:

listener = new ActionListener<GetApiKeyResponse>() {
    @Override
    public void onResponse(GetApiKeyResponse getApiKeyResponse) {
        
    }

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

Called when the execution is successfully completed.

Called when the whole GetApiKeyRequest fails.

Get API Key information API Responseedit

The returned GetApiKeyResponse contains the information regarding the API keys that were requested.

api_keys
Available using getApiKeyInfos, contains list of API keys that were retrieved for this request.
GetApiKeyResponse getApiKeyResponse = client.security().getApiKey(getApiKeyRequest, RequestOptions.DEFAULT);