# How to get a NodeClient inside a X-Pack plugin?

**URL:** https://discuss.elastic.co/t/how-to-get-a-nodeclient-inside-a-x-pack-plugin/156347
**Category:** Elasticsearch
**Created:** [November 12, 2018, 8:50pm UTC](https://discuss.elastic.co/t/how-to-get-a-nodeclient-inside-a-x-pack-plugin/156347 "2018-11-12T20:50:29Z")
**Posts on this page:** 1
**Showing post:** 14

<div class="post-metadata">

### Author: ![gsu](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@gsu](https://discuss.elastic.co/u/gsu)
#### Post date: [November 14, 2018, 11:57am UTC](https://discuss.elastic.co/t/how-to-get-a-nodeclient-inside-a-x-pack-plugin/156347/14 "2018-11-14T11:57:49Z")

</div>

Good idea, thanks @Marcel-Hillmann. Worked like a charm until

```
{
        "error": {
            "root_cause": [
                {
                    "type": "security_exception",
                    "reason": "action [indices:data/read/search] is unauthorized for user [_system]",
                    "header": {
                        "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
                    }
                }
            ],
            "type": "security_exception",
            "reason": "action [indices:data/read/search] is unauthorized for user [_system]",
            "header": {
                "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
            }
        },
        "status": 403
    }

```

The \_system user is used by xpack internally. It seems  
Looking at the documentation

> **[Java client and security | Elasticsearch Guide \[6.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/java-clients.html)**

tells us:

> Using the Java Node Client with secured clusters is not recommended or supported.

I added the \_system user via the user\_roles file to the superuser group, didn't change anything. Interestingly the Authorization: Basic header I add isn't used in the request even though the internal-callback is.

> ```
> {
> Map<String, String> headers = new HashMap<String, String>();
> headers.put("internal-callback", "internal-callback");
> headers.put("Authorization", "Basic ");
> Client authClient = client.filterWithHeader(headers);
> SearchRequestBuilder request = authClient.prepareSearch("admin-stuff").setTypes("grp").setQuery(QueryBuilders.matchAllQuery());
> }
> 
> ```

Resulting in log output:

> [2018-11-14T12:33:54,975][INFO][i.z.s.p.e.j.JWTSecurityRealm] TOKEN:{Authorization=Bearer JWT-TOKEN}  
> [2018-11-14T12:33:55,085][WARN][i.z.s.p.e.j.JWTSecurityRealm] REALM: org.elasticsearch.client.node.NodeClient@588d630d  
> [2018-11-14T12:33:55,092][INFO][i.z.s.p.e.j.JWTSecurityRealm] {"query":{"match\_all":{"boost":1.0}}}  
> [2018-11-14T12:33:55,093][INFO][i.z.s.p.e.j.JWTSecurityRealm] TOKEN:{Authorization=Bearer JWT-TOKEN, internal-callback=internal-callback}

---

_[View the full topic](https://discuss.elastic.co/t/how-to-get-a-nodeclient-inside-a-x-pack-plugin/156347)._
