SOLVED: Consuming ElasticSearch endpoint behind Basic-Auth with RestHighLevelClient

Hi. I have an ElasticSearch cluster that is behind a proxy configured with Basic Auth. How do I make a call from RestHighLevelClient with credentials? In SpringBoot you usually have to configure a HttpClientContext like this:

@Bean
public HttpClientContext configuredContext() {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS));

    AuthCache authCache = new BasicAuthCache();
    authCache.put(httpHost, new BasicScheme());

    final HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);
    context.setAuthCache(authCache);
    return context;
}

but I can't find any fitting parameters on the ClientBuilder or Request for the context.

EDIT: this setup works; thread can be closed

@Bean
public RestHighLevelClient configuredClient() {
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS));

    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(host, port, protocol));

    restClientBuilder.setHttpClientConfigCallback(httpClientBuilder ->
            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));

    return new RestHighLevelClient(restClientBuilder);
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.