# Elasticsearch RestHighLevelClient behind a corporate firewall via a proxy

**URL:** <https://discuss.elastic.co/t/elasticsearch-resthighlevelclient-behind-a-corporate-firewall-via-a-proxy/254642>\
**Category:** Elasticsearch\
**Created:** [November 7, 2020, 10:21pm UTC](https://discuss.elastic.co/t/elasticsearch-resthighlevelclient-behind-a-corporate-firewall-via-a-proxy/254642 "2020-11-07T22:21:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilya\_I](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ilya_i/32/78623_2.png) [@Ilya\_I](https://discuss.elastic.co/u/Ilya_I)\
**Post date:** [November 7, 2020, 10:21pm UTC](https://discuss.elastic.co/t/elasticsearch-resthighlevelclient-behind-a-corporate-firewall-via-a-proxy/254642/1 "2020-11-07T22:21:55Z")

</div>

I am trying to access cloud Elasticsearch installation from our network that requires using a proxy for external requests. This is the snippet of code I use to pass Elasticsearch credentials and our proxy settings:

CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(elasticUser, elasticPassword));

RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostName,port,"https")).setHttpClientConfigCallback(httpClientBuilder -\> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).setHttpClientConfigCallback(httpClientBuilder -\> httpClientBuilder.setProxy(new HttpHost(proxyURL", proxyPort, "http")));

RestHighLevelClient client = new RestHighLevelClient(restClientBuilder);

This results in this response from ES:

"Exception in thread "main" ElasticsearchStatusException[Elasticsearch exception [type=security\_exception, reason=action [indices:data/read/search] requires authentication]]"

It appears that Elasticsearch credentials are not passed for some reason.

---

<div class="post-metadata">

**Author:** ![Ilya\_I](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ilya_i/32/78623_2.png) [@Ilya\_I](https://discuss.elastic.co/u/Ilya_I)\
**Post date:** [November 8, 2020, 6:29pm UTC](https://discuss.elastic.co/t/elasticsearch-resthighlevelclient-behind-a-corporate-firewall-via-a-proxy/254642/2 "2020-11-08T18:29:41Z")

</div>

should have been done like this:

```
	RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostName, port, "https"))
		.setHttpClientConfigCallback(clientBuilder -> {
		  clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
		  clientBuilder.setProxy(new HttpHost(proxyURL, proxyPort, "http"));
		  return clientBuilder;
		 });
```

---

<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:** [December 6, 2020, 6:29pm UTC](https://discuss.elastic.co/t/elasticsearch-resthighlevelclient-behind-a-corporate-firewall-via-a-proxy/254642/3 "2020-12-06T18:29:49Z")

</div>

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