java.lang.Object
org.elasticsearch.xpack.core.ClientHelper
Utility class to help with the execution of requests made using a
Client such that they
have the origin as a transient and listeners have the appropriate context upon invocation-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.use ThreadContext.ACTION_ORIGIN_TRANSIENT_NAMEstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringList of headers that are related to securitystatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertNoAuthorizationHeader(Map<String, String> headers) static ClientclientWithOrigin(Client client, String origin) Deprecated.useOriginSettingClientinsteadstatic <Request extends ActionRequest,Response extends ActionResponse>
voidexecuteAsyncWithOrigin(Client client, String origin, ActionType<Response> action, Request request, ActionListener<Response> listener) Executes an asynchronous action using the provided client.static <Request,Response>
voidexecuteAsyncWithOrigin(ThreadContext threadContext, String origin, Request request, ActionListener<Response> listener, BiConsumer<Request, ActionListener<Response>> consumer) Executes a consumer after setting the origin and wrapping the listener so that the proper context is restoredstatic <T extends ActionResponse>
TExecute a client operation and return the response, try to run an action with least privileges, when headers existstatic <Request extends ActionRequest,Response extends ActionResponse>
voidexecuteWithHeadersAsync(Map<String, String> headers, String origin, Client client, ActionType<Response> action, Request request, ActionListener<Response> listener) Execute a client operation asynchronously, try to run an action with least privileges, when headers existstatic <Request,Response>
voidexecuteWithHeadersAsync(ThreadContext threadContext, Map<String, String> headers, String origin, Request request, ActionListener<Response> listener, BiConsumer<Request, ActionListener<Response>> consumer) filterSecurityHeaders(Map<String, String> headers) Leaves only headers that are related to security and filters out the rest.getPersistableSafeSecurityHeaders(Map<String, String> headers, ClusterState clusterState) Similar togetPersistableSafeSecurityHeaders(ThreadContext, ClusterState), but works on a Map of headers instead of ThreadContext.getPersistableSafeSecurityHeaders(ThreadContext threadContext, ClusterState clusterState) In addition tofilterSecurityHeaders(java.util.Map<java.lang.String, java.lang.String>), also check the version of Authentication objects and rewrite them using minNodeVersion so that they are safe to be persisted as index data and loaded by all nodes in the cluster.
-
Field Details
-
SECURITY_HEADER_FILTERS
List of headers that are related to security -
ACTION_ORIGIN_TRANSIENT_NAME
Deprecated.use ThreadContext.ACTION_ORIGIN_TRANSIENT_NAME.- See Also:
-
SECURITY_ORIGIN
- See Also:
-
SECURITY_PROFILE_ORIGIN
- See Also:
-
WATCHER_ORIGIN
- See Also:
-
ML_ORIGIN
- See Also:
-
INDEX_LIFECYCLE_ORIGIN
- See Also:
-
MONITORING_ORIGIN
- See Also:
-
DEPRECATION_ORIGIN
- See Also:
-
ROLLUP_ORIGIN
- See Also:
-
ENRICH_ORIGIN
- See Also:
-
TRANSFORM_ORIGIN
- See Also:
-
ASYNC_SEARCH_ORIGIN
- See Also:
-
IDP_ORIGIN
- See Also:
-
PROFILING_ORIGIN
- See Also:
-
STACK_ORIGIN
- See Also:
-
SEARCHABLE_SNAPSHOTS_ORIGIN
- See Also:
-
LOGSTASH_MANAGEMENT_ORIGIN
- See Also:
-
FLEET_ORIGIN
- See Also:
-
ENT_SEARCH_ORIGIN
- See Also:
-
CONNECTORS_ORIGIN
- See Also:
-
INFERENCE_ORIGIN
- See Also:
-
APM_ORIGIN
- See Also:
-
OTEL_ORIGIN
- See Also:
-
REINDEX_DATA_STREAM_ORIGIN
- See Also:
-
LOGS_PATTERN_USAGE_ORIGIN
- See Also:
-
-
Method Details
-
assertNoAuthorizationHeader
-
filterSecurityHeaders
Leaves only headers that are related to security and filters out the rest.- Parameters:
headers- Headers to be filtered- Returns:
- A portion of entries that are related to security
-
getPersistableSafeSecurityHeaders
public static Map<String,String> getPersistableSafeSecurityHeaders(ThreadContext threadContext, ClusterState clusterState) In addition tofilterSecurityHeaders(java.util.Map<java.lang.String, java.lang.String>), also check the version of Authentication objects and rewrite them using minNodeVersion so that they are safe to be persisted as index data and loaded by all nodes in the cluster. -
getPersistableSafeSecurityHeaders
public static Map<String,String> getPersistableSafeSecurityHeaders(Map<String, String> headers, ClusterState clusterState) Similar togetPersistableSafeSecurityHeaders(ThreadContext, ClusterState), but works on a Map of headers instead of ThreadContext. -
clientWithOrigin
Deprecated.useOriginSettingClientinsteadReturns a client that will always set the appropriate origin and ensure the proper context is restored by listeners -
executeAsyncWithOrigin
public static <Request,Response> void executeAsyncWithOrigin(ThreadContext threadContext, String origin, Request request, ActionListener<Response> listener, BiConsumer<Request, ActionListener<Response>> consumer) Executes a consumer after setting the origin and wrapping the listener so that the proper context is restored -
executeAsyncWithOrigin
public static <Request extends ActionRequest,Response extends ActionResponse> void executeAsyncWithOrigin(Client client, String origin, ActionType<Response> action, Request request, ActionListener<Response> listener) Executes an asynchronous action using the provided client. The origin is set in the context and the listener is wrapped to ensure the proper context is restored -
executeWithHeaders
public static <T extends ActionResponse> T executeWithHeaders(Map<String, String> headers, String origin, Client client, Supplier<T> supplier) Execute a client operation and return the response, try to run an action with least privileges, when headers exist- Parameters:
headers- Request headers, ideally including security headersorigin- The origin to fall back to if there are no security headersclient- The client used to querysupplier- The action to run- Returns:
- An instance of the response class
-
executeWithHeadersAsync
public static <Request extends ActionRequest,Response extends ActionResponse> void executeWithHeadersAsync(Map<String, String> headers, String origin, Client client, ActionType<Response> action, Request request, ActionListener<Response> listener) Execute a client operation asynchronously, try to run an action with least privileges, when headers exist- Parameters:
headers- Request headers, ideally including security headersorigin- The origin to fall back to if there are no security headersaction- The action to executerequest- The request object for the actionlistener- The listener to call when the action is complete
-
executeWithHeadersAsync
public static <Request,Response> void executeWithHeadersAsync(ThreadContext threadContext, Map<String, String> headers, String origin, Request request, ActionListener<Response> listener, BiConsumer<Request, ActionListener<Response>> consumer)
-