# Elasticsearch is built with known username & password and need to access with java api

**URL:** <https://discuss.elastic.co/t/elasticsearch-is-built-with-known-username-password-and-need-to-access-with-java-api/272247>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security, language-clients\
**Created:** [May 6, 2021, 7:02am UTC](https://discuss.elastic.co/t/elasticsearch-is-built-with-known-username-password-and-need-to-access-with-java-api/272247 "2021-05-06T07:02:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KK\_LL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kk_ll/32/88295_2.png) [@KK\_LL](https://discuss.elastic.co/u/KK_LL)\
**Post date:** [May 6, 2021, 7:02am UTC](https://discuss.elastic.co/t/elasticsearch-is-built-with-known-username-password-and-need-to-access-with-java-api/272247/1 "2021-05-06T07:02:08Z")

</div>

I have built and up an elasticsearch on my computer. And set the

```auto
xpack.security.enabled: true
xpack.security.authc.api_key.enabled: true

```

to enable basic security. The elastic username password is also generated automatically.  
Now I need to access the 127.0.0.1:9200 with java API, how can I do that? If any example or demo provided is better.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 6, 2021, 8:11am UTC](https://discuss.elastic.co/t/elasticsearch-is-built-with-known-username-password-and-need-to-access-with-java-api/272247/2 "2021-05-06T08:11:18Z")

</div>

Welcome!

Have a look at:

> **[Basic authentication | Java REST Client \[7.12\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.12/_basic_authentication.html)**

And

> **[Other authentication methods | Java REST Client \[7.12\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.12/_other_authentication_methods.html)**

---

<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:** [June 3, 2021, 8:12am UTC](https://discuss.elastic.co/t/elasticsearch-is-built-with-known-username-password-and-need-to-access-with-java-api/272247/3 "2021-06-03T08:12:08Z")

</div>

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