# Shield with Java Client

**URL:** <https://discuss.elastic.co/t/shield-with-java-client/21887>\
**Category:** Elasticsearch\
**Created:** [January 28, 2015, 9:12pm UTC](https://discuss.elastic.co/t/shield-with-java-client/21887 "2015-01-28T21:12:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jettro\_Coenradie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jettro_coenradie/32/59704_2.png) [@Jettro\_Coenradie](https://discuss.elastic.co/u/Jettro_Coenradie)\
**Post date:** [January 28, 2015, 9:12pm UTC](https://discuss.elastic.co/t/shield-with-java-client/21887/1 "2015-01-28T21:12:31Z")

</div>

Hi,  
trying to get Shield working with a java client. When setting the header  
token on the client, there is no problem. But when I try to use the header  
of a request there is no succes. I am trying this code, which is almost a  
copy of the sample code in the documentation. It does not work, if I  
uncomment the line with shield.user, it does work: Any clues on what I  
should do are appreciated.

package nl.gridshore.dwes.elastic;

import org.elasticsearch.action.count.CountResponse;  
import org.elasticsearch.action.search.SearchResponse;  
import org.elasticsearch.client.Client;  
import org.elasticsearch.client.transport.TransportClient;  
import org.elasticsearch.common.settings.ImmutableSettings;  
import org.elasticsearch.common.settings.Settings;  
import org.elasticsearch.common.transport.InetSocketTransportAddress;  
import org.elasticsearch.common.transport.TransportAddress;  
import org.elasticsearch.shield.authc.support.SecuredString;

import java.util.ArrayList;  
import java.util.List;

import static java.util.stream.Collectors.toList;  
import static  
org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;

public class SecureElastic {  
public static void main(String[] args) {  
Settings settings = ImmutableSettings.settingsBuilder()  
.put("cluster.name", "jc-play")  
// .put("shield.user", "jettro:nopiforme")  
.build();

```
    Client client = new TransportClient(settings)
            .addTransportAddress(new 

```

InetSocketTransportAddress("localhost",9300));

```
    String token = basicAuthHeaderValue("jettro", new 

```

SecuredString("nopiforme".toCharArray()));

```
    SearchResponse searchResponse = 

```

client.prepareSearch("gridshore").putHeader("Authorization", token).get();  
long totalHits = searchResponse.getHits().totalHits();

```
    System.out.println(totalHits);
}

```

}

The exception:  
Caused by: org.elasticsearch.shield.authc.AuthenticationException: missing  
authentication token for action [cluster:monitor/nodes/info]

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/89dd6e89-680a-435c-824b-b11b8128beda%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/89dd6e89-680a-435c-824b-b11b8128beda%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jettro\_Coenradie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jettro_coenradie/32/59704_2.png) [@Jettro\_Coenradie](https://discuss.elastic.co/u/Jettro_Coenradie)\
**Post date:** [January 28, 2015, 11:46pm UTC](https://discuss.elastic.co/t/shield-with-java-client/21887/2 "2015-01-28T23:46:53Z")

</div>

Never mind, misread the documentation. It seems a node info request is  
done first, therefore you need to provide the username password in the  
client. Than if you want to, you can change the username password for each  
request that you do.

It works now.

Op woensdag 28 januari 2015 22:12:31 UTC+1 schreef Jettro Coenradie:

> Hi,  
> trying to get Shield working with a java client. When setting the header  
> token on the client, there is no problem. But when I try to use the header  
> of a request there is no succes. I am trying this code, which is almost a  
> copy of the sample code in the documentation. It does not work, if I  
> uncomment the line with shield.user, it does work: Any clues on what I  
> should do are appreciated.
> 
> package nl.gridshore.dwes.elastic;
> 
> import org.elasticsearch.action.count.CountResponse;  
> import org.elasticsearch.action.search.SearchResponse;  
> import org.elasticsearch.client.Client;  
> import org.elasticsearch.client.transport.TransportClient;  
> import org.elasticsearch.common.settings.ImmutableSettings;  
> import org.elasticsearch.common.settings.Settings;  
> import org.elasticsearch.common.transport.InetSocketTransportAddress;  
> import org.elasticsearch.common.transport.TransportAddress;  
> import org.elasticsearch.shield.authc.support.SecuredString;
> 
> import java.util.ArrayList;  
> import java.util.List;
> 
> import static java.util.stream.Collectors.toList;  
> import static  
> org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
> 
> public class SecureElastic {  
> public static void main(String args) {  
> Settings settings = ImmutableSettings.settingsBuilder()  
> .put("cluster.name", "jc-play")  
> // .put("shield.user", "jettro:nopiforme")  
> .build();
> 
> ```
> Client client = new TransportClient(settings)
> .addTransportAddress(new 
> 
> ```
> 
> InetSocketTransportAddress("localhost",9300));
> 
> ```
> String token = basicAuthHeaderValue("jettro", new 
> 
> ```
> 
> SecuredString("nopiforme".toCharArray()));
> 
> ```
> SearchResponse searchResponse = 
> 
> ```
> 
> client.prepareSearch("gridshore").putHeader("Authorization", token).get();  
> long totalHits = searchResponse.getHits().totalHits();
> 
> ```
> System.out.println(totalHits);
> }
> 
> ```
> 
> }
> 
> The exception:  
> Caused by: org.elasticsearch.shield.authc.AuthenticationException: missing  
> authentication token for action [cluster:monitor/nodes/info]

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2d6284d4-324d-43be-82f9-36a8975ba8af%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2d6284d4-324d-43be-82f9-36a8975ba8af%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Zsolt\_Bakonyi](https://avatars.discourse-cdn.com/v4/letter/z/c89c15/32.png) [@Zsolt\_Bakonyi](https://discuss.elastic.co/u/Zsolt_Bakonyi)\
**Post date:** [March 10, 2015, 12:30pm UTC](https://discuss.elastic.co/t/shield-with-java-client/21887/3 "2015-03-10T12:30:23Z")

</div>

Dear Jettro.

Can you help me, how could you do it?  
I try to comminicate to Elasticsearch with Shield plugin. This is done when  
I make CURL requests.  
Without shield plugin my JAVA code ( Client is same as yours ) works well.  
But after install Shield, and put Shield into maven depencies in my  
application:

org.elasticsearch elasticsearch-shield 1.0.1

I got strange error, without creating any change in my code:

12:53:23,746 INFO [org.elasticsearch.plugins] (default task-1) [Honey  
Lemon] loaded [shield], sites   
12:53:23,987 INFO [org.elasticsearch.transport] (default task-1) [Honey  
Lemon] Using  
[org.elasticsearch.shield.transport.ShieldClientTransportService] as  
transport service, overridden by [shield]  
12:53:23,987 INFO [org.elasticsearch.transport] (default task-1) [Honey  
Lemon] Using  
[org.elasticsearch.shield.transport.netty.ShieldNettyTransport] as  
transport, overridden by [shield]  
12:53:24,232 ERROR [org.jboss.as.ejb3.invocation] (default task-1)  
JBAS014134: EJB Invocation failed on component Elasticsearch for method  
public org.elasticsearch.client.Client  
net._ **.** _.search.Elasticsearch.AuthElasticSearch(java.lang.String,java.lang.String):  
javax.ejb.EJBException: org.elasticsearch.common.inject.CreationException:  
Guice creation errors:

1. A binding to org.elasticsearch.shield.transport.filter.IPFilter was  
already configured at _unknown_.

at _unknown_

1. A binding to org.elasticsearch.shield.transport.ClientTransportFilter  
was already configured at _unknown_.

at _unknown_

1. A binding to org.elasticsearch.shield.ssl.SSLService was already  
configured at _unknown_.

at _unknown_

3 errors

My code:

@SuppressWarnings("resource")  
public Client AuthElasticSearch(String user, String pass) {

Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
"\*\*\*\*").put("client.transport.sniff", true)  
.put("shield.user", user + ":" + pass).build();  
Client client = new TransportClient(settings).addTransportAddress(new  
InetSocketTransportAddress("localhost", 9300));

return client;

}

Both ES versions in Ubuntu and app are 1.4.4  
Both SHIELD versions are 1.0.1

java version "1.8.0\_40"  
Java(TM) SE Runtime Environment (build 1.8.0\_40-b25)  
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

Thank you.

1. január 29., csütörtök 0:46:53 UTC+1 időpontban Jettro Coenradie a  
következőt írta:

> Never mind, misread the documentation. It seems a node info request is  
> done first, therefore you need to provide the username password in the  
> client. Than if you want to, you can change the username password for each  
> request that you do.
> 
> It works now.
> 
> Op woensdag 28 januari 2015 22:12:31 UTC+1 schreef Jettro Coenradie:
> 
> > Hi,  
> > trying to get Shield working with a java client. When setting the header  
> > token on the client, there is no problem. But when I try to use the header  
> > of a request there is no succes. I am trying this code, which is almost a  
> > copy of the sample code in the documentation. It does not work, if I  
> > uncomment the line with shield.user, it does work: Any clues on what I  
> > should do are appreciated.
> > 
> > package nl.gridshore.dwes.elastic;
> > 
> > import org.elasticsearch.action.count.CountResponse;  
> > import org.elasticsearch.action.search.SearchResponse;  
> > import org.elasticsearch.client.Client;  
> > import org.elasticsearch.client.transport.TransportClient;  
> > import org.elasticsearch.common.settings.ImmutableSettings;  
> > import org.elasticsearch.common.settings.Settings;  
> > import org.elasticsearch.common.transport.InetSocketTransportAddress;  
> > import org.elasticsearch.common.transport.TransportAddress;  
> > import org.elasticsearch.shield.authc.support.SecuredString;
> > 
> > import java.util.ArrayList;  
> > import java.util.List;
> > 
> > import static java.util.stream.Collectors.toList;  
> > import static  
> > org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
> > 
> > public class SecureElastic {  
> > public static void main(String args) {  
> > Settings settings = ImmutableSettings.settingsBuilder()  
> > .put("cluster.name", "jc-play")  
> > // .put("shield.user", "jettro:nopiforme")  
> > .build();
> > 
> > ```
> > Client client = new TransportClient(settings)
> > .addTransportAddress(new 
> > 
> > ```
> > 
> > InetSocketTransportAddress("localhost",9300));
> > 
> > ```
> > String token = basicAuthHeaderValue("jettro", new 
> > 
> > ```
> > 
> > SecuredString("nopiforme".toCharArray()));
> > 
> > ```
> > SearchResponse searchResponse = 
> > 
> > ```
> > 
> > client.prepareSearch("gridshore").putHeader("Authorization", token).get();  
> > long totalHits = searchResponse.getHits().totalHits();
> > 
> > ```
> > System.out.println(totalHits);
> > }
> > 
> > ```
> > 
> > }
> > 
> > The exception:  
> > Caused by: org.elasticsearch.shield.authc.AuthenticationException:  
> > missing authentication token for action [cluster:monitor/nodes/info]

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jettro\_Coenradie\_2](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Jettro\_Coenradie\_2](https://discuss.elastic.co/u/Jettro_Coenradie_2)\
**Post date:** [March 10, 2015, 3:48pm UTC](https://discuss.elastic.co/t/shield-with-java-client/21887/4 "2015-03-10T15:48:19Z")

</div>

Can you try to switch off client.transport.sniff, this might trigger  
another authority rule. I am not sure, but it is worth a try.

On Tue, Mar 10, 2015 at 5:30 AM, Zsolt Bákonyi [info@netmango.net](mailto:info@netmango.net) wrote:

> Dear Jettro.
> 
> Can you help me, how could you do it?  
> I try to comminicate to Elasticsearch with Shield plugin. This is done  
> when I make CURL requests.  
> Without shield plugin my JAVA code ( Client is same as yours ) works  
> well. But after install Shield, and put Shield into maven depencies in my  
> application:
> 
> org.elasticsearch elasticsearch-shield 1.0.1
> 
> I got strange error, without creating any change in my code:
> 
> 12:53:23,746 INFO [org.elasticsearch.plugins] (default task-1) [Honey  
> Lemon] loaded [shield], sites   
> 12:53:23,987 INFO [org.elasticsearch.transport] (default task-1) [Honey  
> Lemon] Using  
> [org.elasticsearch.shield.transport.ShieldClientTransportService] as  
> transport service, overridden by [shield]  
> 12:53:23,987 INFO [org.elasticsearch.transport] (default task-1) [Honey  
> Lemon] Using  
> [org.elasticsearch.shield.transport.netty.ShieldNettyTransport] as  
> transport, overridden by [shield]  
> 12:53:24,232 ERROR [org.jboss.as.ejb3.invocation] (default task-1)  
> JBAS014134: EJB Invocation failed on component Elasticsearch for method  
> public org.elasticsearch.client.Client  
> net._ **.** _.search.Elasticsearch.AuthElasticSearch(java.lang.String,java.lang.String):  
> javax.ejb.EJBException: org.elasticsearch.common.inject.CreationException:  
> Guice creation errors:
> 
> 1. A binding to org.elasticsearch.shield.transport.filter.IPFilter was  
> already configured at _unknown_.
> 
> at _unknown_
> 
> 1. A binding to org.elasticsearch.shield.transport.ClientTransportFilter  
> was already configured at _unknown_.
> 
> at _unknown_
> 
> 1. A binding to org.elasticsearch.shield.ssl.SSLService was already  
> configured at _unknown_.
> 
> at _unknown_
> 
> 3 errors
> 
> My code:
> 
> @SuppressWarnings("resource")  
> public Client AuthElasticSearch(String user, String pass) {
> 
> Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
> "\*\*\*\*").put("client.transport.sniff", true)  
> .put("shield.user", user + ":" + pass).build();  
> Client client = new TransportClient(settings).addTransportAddress(new  
> InetSocketTransportAddress("localhost", 9300));
> 
> return client;
> 
> }
> 
> Both ES versions in Ubuntu and app are 1.4.4  
> Both SHIELD versions are 1.0.1
> 
> java version "1.8.0\_40"  
> Java(TM) SE Runtime Environment (build 1.8.0\_40-b25)  
> Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
> 
> Thank you.
> 
> 1. január 29., csütörtök 0:46:53 UTC+1 időpontban Jettro Coenradie a  
> következőt írta:
> 
> > Never mind, misread the documentation. It seems a node info request is  
> > done first, therefore you need to provide the username password in the  
> > client. Than if you want to, you can change the username password for each  
> > request that you do.
> > 
> > It works now.
> > 
> > Op woensdag 28 januari 2015 22:12:31 UTC+1 schreef Jettro Coenradie:
> > 
> > > Hi,  
> > > trying to get Shield working with a java client. When setting the header  
> > > token on the client, there is no problem. But when I try to use the header  
> > > of a request there is no succes. I am trying this code, which is almost a  
> > > copy of the sample code in the documentation. It does not work, if I  
> > > uncomment the line with shield.user, it does work: Any clues on what I  
> > > should do are appreciated.
> > > 
> > > package nl.gridshore.dwes.elastic;
> > > 
> > > import org.elasticsearch.action.count.CountResponse;  
> > > import org.elasticsearch.action.search.SearchResponse;  
> > > import org.elasticsearch.client.Client;  
> > > import org.elasticsearch.client.transport.TransportClient;  
> > > import org.elasticsearch.common.settings.ImmutableSettings;  
> > > import org.elasticsearch.common.settings.Settings;  
> > > import org.elasticsearch.common.transport.InetSocketTransportAddress;  
> > > import org.elasticsearch.common.transport.TransportAddress;  
> > > import org.elasticsearch.shield.authc.support.SecuredString;
> > > 
> > > import java.util.ArrayList;  
> > > import java.util.List;
> > > 
> > > import static java.util.stream.Collectors.toList;  
> > > import static org.elasticsearch.shield.authc.support.  
> > > UsernamePasswordToken.basicAuthHeaderValue;
> > > 
> > > public class SecureElastic {  
> > > public static void main(String args) {  
> > > Settings settings = ImmutableSettings.settingsBuilder()  
> > > .put("cluster.name", "jc-play")  
> > > // .put("shield.user", "jettro:nopiforme")  
> > > .build();
> > > 
> > > ```
> > > Client client = new TransportClient(settings)
> > > .addTransportAddress(new InetSocketTransportAddress("
> > > 
> > > ```
> > > 
> > > localhost",9300));
> > > 
> > > ```
> > > String token = basicAuthHeaderValue("jettro", new
> > > 
> > > ```
> > > 
> > > SecuredString("nopiforme".toCharArray()));
> > > 
> > > ```
> > > SearchResponse searchResponse = client.prepareSearch("
> > > 
> > > ```
> > > 
> > > gridshore").putHeader("Authorization", token).get();  
> > > long totalHits = searchResponse.getHits().totalHits();
> > > 
> > > ```
> > > System.out.println(totalHits);
> > > }
> > > 
> > > ```
> > > 
> > > }
> > > 
> > > The exception:  
> > > Caused by: org.elasticsearch.shield.authc.AuthenticationException:  
> > > missing authentication token for action [cluster:monitor/nodes/info]
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/WcD4Ej9cMbA/unsubscribe](https://groups.google.com/d/topic/elasticsearch/WcD4Ej9cMbA/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Jettro Coenradie

> **[Gridshore](https://www.gridshore.nl/)**
>
> A weblog about software engineering, Architecture, Technology an other things we like.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CABB4caOxpt%3DRkRqGq%2BS\_qbhhCqMC6ZhyPFtEbA9C3UZPxN-52A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CABB4caOxpt%3DRkRqGq%2BS_qbhhCqMC6ZhyPFtEbA9C3UZPxN-52A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Zsolt\_Bakonyi](https://avatars.discourse-cdn.com/v4/letter/z/c89c15/32.png) [@Zsolt\_Bakonyi](https://discuss.elastic.co/u/Zsolt_Bakonyi)\
**Post date:** [March 10, 2015, 8:48pm UTC](https://discuss.elastic.co/t/shield-with-java-client/21887/5 "2015-03-10T20:48:59Z")

</div>

Thank you for reply, but nothing changed...

You know the most "funny" thing is, if i left only this in my code:

Client client = new TransportClient().addTransportAddress(new  
InetSocketTransportAddress("localhost", 9300));

Basic client without settings, and the exception is the same. If i  
commented out the shield depency in pom.xml the error has gone, Of course  
it is not working, but this exception disappear... I deploy it in wildfly  
8.2.

☹

1. március 10., kedd 16:48:53 UTC+1 időpontban Jettro Coenradie a  
következőt írta:

> Can you try to switch off client.transport.sniff, this might trigger  
> another authority rule. I am not sure, but it is worth a try.
> 
> On Tue, Mar 10, 2015 at 5:30 AM, Zsolt Bákonyi \<[in...@netmango.net](mailto:in...@netmango.net)  
> \<javascript:\>\> wrote:
> 
> > Dear Jettro.
> > 
> > Can you help me, how could you do it?  
> > I try to comminicate to Elasticsearch with Shield plugin. This is done  
> > when I make CURL requests.  
> > Without shield plugin my JAVA code ( Client is same as yours ) works  
> > well. But after install Shield, and put Shield into maven depencies in my  
> > application:
> > 
> > org.elasticsearch elasticsearch-shield 1.0.1
> > 
> > I got strange error, without creating any change in my code:
> > 
> > 12:53:23,746 INFO [org.elasticsearch.plugins] (default task-1) [Honey  
> > Lemon] loaded [shield], sites   
> > 12:53:23,987 INFO [org.elasticsearch.transport] (default task-1) [Honey  
> > Lemon] Using  
> > [org.elasticsearch.shield.transport.ShieldClientTransportService] as  
> > transport service, overridden by [shield]  
> > 12:53:23,987 INFO [org.elasticsearch.transport] (default task-1) [Honey  
> > Lemon] Using  
> > [org.elasticsearch.shield.transport.netty.ShieldNettyTransport] as  
> > transport, overridden by [shield]  
> > 12:53:24,232 ERROR [org.jboss.as.ejb3.invocation] (default task-1)  
> > JBAS014134: EJB Invocation failed on component Elasticsearch for method  
> > public org.elasticsearch.client.Client  
> > net._ **.** _.search.Elasticsearch.AuthElasticSearch(java.lang.String,java.lang.String):  
> > javax.ejb.EJBException: org.elasticsearch.common.inject.CreationException:  
> > Guice creation errors:
> > 
> > 1. A binding to org.elasticsearch.shield.transport.filter.IPFilter was  
> > already configured at _unknown_.
> > 
> > at _unknown_
> > 
> > 1. A binding to org.elasticsearch.shield.transport.ClientTransportFilter  
> > was already configured at _unknown_.
> > 
> > at _unknown_
> > 
> > 1. A binding to org.elasticsearch.shield.ssl.SSLService was already  
> > configured at _unknown_.
> > 
> > at _unknown_
> > 
> > 3 errors
> > 
> > My code:
> > 
> > @SuppressWarnings("resource")  
> > public Client AuthElasticSearch(String user, String pass) {
> > 
> > Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name",  
> > "\*\*\*\*").put("client.transport.sniff", true)  
> > .put("shield.user", user + ":" + pass).build();  
> > Client client = new TransportClient(settings).addTransportAddress(new  
> > InetSocketTransportAddress("localhost", 9300));
> > 
> > return client;
> > 
> > }
> > 
> > Both ES versions in Ubuntu and app are 1.4.4  
> > Both SHIELD versions are 1.0.1
> > 
> > java version "1.8.0\_40"  
> > Java(TM) SE Runtime Environment (build 1.8.0\_40-b25)  
> > Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
> > 
> > Thank you.
> > 
> > 1. január 29., csütörtök 0:46:53 UTC+1 időpontban Jettro Coenradie a  
> > következőt írta:
> > 
> > > Never mind, misread the documentation. It seems a node info request is  
> > > done first, therefore you need to provide the username password in the  
> > > client. Than if you want to, you can change the username password for each  
> > > request that you do.
> > > 
> > > It works now.
> > > 
> > > Op woensdag 28 januari 2015 22:12:31 UTC+1 schreef Jettro Coenradie:
> > > 
> > > > Hi,  
> > > > trying to get Shield working with a java client. When setting the  
> > > > header token on the client, there is no problem. But when I try to use the  
> > > > header of a request there is no succes. I am trying this code, which is  
> > > > almost a copy of the sample code in the documentation. It does not work, if  
> > > > I uncomment the line with shield.user, it does work: Any clues on what I  
> > > > should do are appreciated.
> > > > 
> > > > package nl.gridshore.dwes.elastic;
> > > > 
> > > > import org.elasticsearch.action.count.CountResponse;  
> > > > import org.elasticsearch.action.search.SearchResponse;  
> > > > import org.elasticsearch.client.Client;  
> > > > import org.elasticsearch.client.transport.TransportClient;  
> > > > import org.elasticsearch.common.settings.ImmutableSettings;  
> > > > import org.elasticsearch.common.settings.Settings;  
> > > > import org.elasticsearch.common.transport.InetSocketTransportAddress;  
> > > > import org.elasticsearch.common.transport.TransportAddress;  
> > > > import org.elasticsearch.shield.authc.support.SecuredString;
> > > > 
> > > > import java.util.ArrayList;  
> > > > import java.util.List;
> > > > 
> > > > import static java.util.stream.Collectors.toList;  
> > > > import static org.elasticsearch.shield.authc.support.  
> > > > UsernamePasswordToken.basicAuthHeaderValue;
> > > > 
> > > > public class SecureElastic {  
> > > > public static void main(String args) {  
> > > > Settings settings = ImmutableSettings.settingsBuilder()  
> > > > .put("cluster.name", "jc-play")  
> > > > // .put("shield.user", "jettro:nopiforme")  
> > > > .build();
> > > > 
> > > > ```
> > > > Client client = new TransportClient(settings)
> > > > .addTransportAddress(new InetSocketTransportAddress("
> > > > 
> > > > ```
> > > > 
> > > > localhost",9300));
> > > > 
> > > > ```
> > > > String token = basicAuthHeaderValue("jettro", new 
> > > > 
> > > > ```
> > > > 
> > > > SecuredString("nopiforme".toCharArray()));
> > > > 
> > > > ```
> > > > SearchResponse searchResponse = client.prepareSearch("
> > > > 
> > > > ```
> > > > 
> > > > gridshore").putHeader("Authorization", token).get();  
> > > > long totalHits = searchResponse.getHits().totalHits();
> > > > 
> > > > ```
> > > > System.out.println(totalHits);
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > }
> > > > 
> > > > The exception:  
> > > > Caused by: org.elasticsearch.shield.authc.AuthenticationException:  
> > > > missing authentication token for action [cluster:monitor/nodes/info]
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/WcD4Ej9cMbA/unsubscribe](https://groups.google.com/d/topic/elasticsearch/WcD4Ej9cMbA/unsubscribe).  
> > > > To unsubscribe from this group and all its topics, send an email to  
> > > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/860e98d4-63a3-4bd7-816b-095405e799a4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Jettro Coenradie  
> [http://www.gridshore.nl](http://www.gridshore.nl)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/80ae9b81-32c2-42d1-a04f-c737664ac7b0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/80ae9b81-32c2-42d1-a04f-c737664ac7b0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:27am UTC](https://discuss.elastic.co/t/shield-with-java-client/21887/6 "2017-07-06T00:27:32Z")

</div>


