# Authentication using Java API and TransportClient

**URL:** https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196
**Category:** Elasticsearch
**Created:** [October 27, 2016, 8:05pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196 "2016-10-27T20:05:14Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![robgratz](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robgratz](https://discuss.elastic.co/u/robgratz)
#### Post date: [October 27, 2016, 8:05pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/1 "2016-10-27T20:05:14Z")

</div>

I'm fairly new to using elasticsearch and xpack and am having trouble figuring out how to specify the username/password for authentication when connecting to a node using the TransportClient. I know my basic configuration is correct because if I go to :9200 with the browser, it prompts me for user/pw and when I enter the default credentials for user 'elastic', the page shows successfully.

I also know, other than the user/pw config, that my client application using the TransportClient is correct because if I disable authentication in the elasticsearch.yml file, I can make calls successfully to my ES node.

I've seen some mention of "xpack.security.user" as a property, but when I try setting that into the settings for connecting, it tells me that it is an invalid property.

Again, the same client succeeds when xpack.security.enabled=false, but when true, I get this error:

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{pyXJL2PeTtGejUwbpycDUg}{127.0.0.1}{127.0.0.1:9300}]]

Any help would be greatly appreciated. Thanks.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 28, 2016, 7:34am UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/2 "2016-10-28T07:34:54Z")

</div>

Hey,

can you share your configuration of the TransportClient?

Also, you need to check if you are on Elasticsearch 2.x or 5.x. The `xpack.security.user` field as mentioned [here](https://www.elastic.co/guide/en/x-pack/5.0/java-clients.html#transport-client) is for 5.x.

Last but not least, check if you have SSL enabled or not.

--Alex

---

<div class="post-metadata">

### Author: ![robgratz](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robgratz](https://discuss.elastic.co/u/robgratz)
#### Post date: [October 28, 2016, 1:03pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/3 "2016-10-28T13:03:18Z")

</div>

Here is how I create the transport client:

Settings settings = Settings.builder().build();  
TransportAddress addr = new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), 9300);  
TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(addr);

I am using ES 5.0.

As far as using SSL, I am using whatever the default configurations are after installing xpack. The only modification I've made on either ES or xpack is adding the xpack.security.enabled property so I could try everything with authentication turned off. Again, the exact same client and configuration works when I disable security, but when I enable it, I get the previously specified error.

Thank you for the link. I'll go through that information that I previously had not found.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 28, 2016, 1:24pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/4 "2016-10-28T13:24:59Z")

</div>

So, where is your `xpack.security.user` configuration for that transport client (or the error message that you having)? You need configure authentication for the transport client, either globally for all requests or for every single one? Did you take a look at a link that I had in my last post with the example?

--Alex

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 28, 2016, 1:26pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/5 "2016-10-28T13:26:00Z")

</div>

On top the link above also uses the specific `PreBuiltXPackTransportClient` class

---

<div class="post-metadata">

### Author: ![robgratz](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robgratz](https://discuss.elastic.co/u/robgratz)
#### Post date: [October 28, 2016, 2:22pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/6 "2016-10-28T14:22:04Z")

</div>

Thanks for the information. I had not seen the link you provided so when I set the xpack.security.user property it told me it was an invalid property so I took it out. Problem was I didn't realize there was a specific xpack-transport jar file I needed as well. My guess is that will enable setting the xpack.security.user property without throwing an error and also make available the xpack transport class you just mentioned.

With that said, when will that transport jar be made available on the main maven repositories. I am having trouble accessing the elasticsearch repository mentioned in the documentation. So, needless to say, I haven't been able to try the suggestions that you and the documentation have made. I've tried hitting the repo straight from the browser which works for the other repos we use and that doesn't work and I've tried adding the repository configuration to my pom and that hasn't worked either. Anyone else having any issues on that front?

Again, thanks for the help. Think I'm close but just need to get that jar file.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 28, 2016, 2:53pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/7 "2016-10-28T14:53:50Z")

</div>

Hey,

we cant put that transport client into the maven repo, because it is not open source. If you have issues connecting to the elastic repo lets make sure we debug those, can you show what does not work? Can you paste your mvn configuration along with the output you got?

--Alex

---

<div class="post-metadata">

### Author: ![robgratz](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robgratz](https://discuss.elastic.co/u/robgratz)
#### Post date: [October 28, 2016, 3:04pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/8 "2016-10-28T15:04:59Z")

</div>

The transport client isn't open source? I didn't see anything about licensing on that. Does that mean that xpack is also not open source?

I've added the repo specified in the documentation to our local repository as a proxy and all that I see when browsing that repo is an archetype-catalog. No jar file artifacts. When I try hitting that URL from the browser I now get redirected to:  
[https://www.elastic.co/downloads](https://www.elastic.co/downloads)

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 28, 2016, 3:06pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/9 "2016-10-28T15:06:17Z")

</div>

Hey,

the `PreBuiltXPackTransportClient` class is part of x-pack, which in turn is not open source and thus not propagated to sonatype.

--Alex

---

<div class="post-metadata">

### Author: ![robgratz](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robgratz](https://discuss.elastic.co/u/robgratz)
#### Post date: [October 28, 2016, 3:15pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/10 "2016-10-28T15:15:31Z")

</div>

So I'm confused. I don't see anywhere in any documentation that talks about how to license that product. Can you point me to that information? We really don't have an option of running elasticsearch wide open as it is by default.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 28, 2016, 3:20pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/11 "2016-10-28T15:20:07Z")

</div>

Sure, you might wanna check out [license management](https://www.elastic.co/guide/en/x-pack/5.0/license-management.html) documentation or head over to the [subscriptions](https://www.elastic.co/subscriptions) page

--Alex

---

<div class="post-metadata">

### Author: ![robgratz](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@robgratz](https://discuss.elastic.co/u/robgratz)
#### Post date: [October 28, 2016, 3:56pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/12 "2016-10-28T15:56:56Z")

</div>

Thank you. That's exactly what I need. Appreciate all the help.

---

<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: [July 6, 2017, 1:40pm UTC](https://discuss.elastic.co/t/authentication-using-java-api-and-transportclient/64196/13 "2017-07-06T13:40:11Z")

</div>


