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/89dd6e89-680a-435c-824b-b11b8128beda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.