# SOLVED: Consuming ElasticSearch endpoint behind Basic-Auth with RestHighLevelClient

**URL:** <https://discuss.elastic.co/t/solved-consuming-elasticsearch-endpoint-behind-basic-auth-with-resthighlevelclient/161949>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [December 23, 2018, 12:59pm UTC](https://discuss.elastic.co/t/solved-consuming-elasticsearch-endpoint-behind-basic-auth-with-resthighlevelclient/161949 "2018-12-23T12:59:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philly-vanilly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/philly-vanilly/32/39130_2.png) [@philly-vanilly](https://discuss.elastic.co/u/philly-vanilly)\
**Post date:** [December 23, 2018, 12:59pm UTC](https://discuss.elastic.co/t/solved-consuming-elasticsearch-endpoint-behind-basic-auth-with-resthighlevelclient/161949/1 "2018-12-23T12:59:53Z")

</div>

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);
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 20, 2019, 12:59pm UTC](https://discuss.elastic.co/t/solved-consuming-elasticsearch-endpoint-behind-basic-auth-with-resthighlevelclient/161949/2 "2019-01-20T12:59:54Z")

</div>

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