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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/2d6284d4-324d-43be-82f9-36a8975ba8af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to