1

I am learning Elasticsearch (6.1.3) to use it in a Java-based web application.

I have installed X-Pack. Now I need to know how to program in the Java client by simply providing username and password without using SSL. I found out this page is helpful, but lacking:

https://www.elastic.co/guide/en/x-pack/current/java-clients.html

I am particularly interested in the following code snippet found in the above link:

TransportClient client = new PreBuiltXPackTransportClient(Settings.builder()
        .put("cluster.name", "myClusterName")
        .put("xpack.security.user", "transport_client_user:changeme")
        ...
        .build())
    .build()
    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300))
    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9301))

String token = basicAuthHeaderValue("test_user", new SecureString("changeme".toCharArray()));

client.filterWithHeader(Collections.singletonMap("Authorization", token))
    .prepareSearch().get();

Does this code snippet apply to my situation? Where is the password included?

I googled a lot, but not able to find a single complete example. I would really appreciate it for any info or links.

N8888
  • 670
  • 2
  • 14
  • 20
curious1
  • 14,155
  • 37
  • 130
  • 231

1 Answers1

3

According to the XPack documentation on configuring the transport client to work with a secured ES cluster, the line you car about is this one:

    .put("xpack.security.user", "transport_client_user:changeme")

and in there you can see that you have a username (transport_client_user) and a password (changeme), so you're good to go.

Val
  • 207,596
  • 13
  • 358
  • 360
  • Val, thanks for your help. I tested it and it worked. I saw that line and was not sure about whether username and password should be put in the same place separated by colon. – curious1 Feb 06 '18 at 14:57
  • If I hit http://localhost:9200/_xpack/security/user/ I only see 3 users elastic/kibana/logstash_system – Kalpesh Soni Sep 03 '19 at 19:34