# Access currently authenticated user from custom realm logic

**URL:** <https://discuss.elastic.co/t/access-currently-authenticated-user-from-custom-realm-logic/167082>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [February 5, 2019, 8:59am UTC](https://discuss.elastic.co/t/access-currently-authenticated-user-from-custom-realm-logic/167082 "2019-02-05T08:59:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guiss39](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@Guiss39](https://discuss.elastic.co/u/Guiss39)\
**Post date:** [February 5, 2019, 8:59am UTC](https://discuss.elastic.co/t/access-currently-authenticated-user-from-custom-realm-logic/167082/1 "2019-02-05T08:59:52Z")

</div>

Hi,

I'm building a custom plugin with XPack and I have a custom Realm.  
From the `token()` method (e.g. [https://github.com/elastic/elasticsearch/blob/6.4/x-pack/qa/security-example-spi-extension/src/main/java/org/elasticsearch/example/realm/CustomRealm.java#L40](https://github.com/elastic/elasticsearch/blob/6.4/x-pack/qa/security-example-spi-extension/src/main/java/org/elasticsearch/example/realm/CustomRealm.java#L40)) I would like to access the authenticated user like if I would run:

`GET _xpack/security/_authenticate`

is that possible to do that programmatically there?

Thanks.  
Regards.

---

<div class="post-metadata">

**Author:** ![Yogesh\_Gaikwad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yogesh_gaikwad/32/27025_2.png) [@Yogesh\_Gaikwad](https://discuss.elastic.co/u/Yogesh_Gaikwad)\
**Post date:** [February 15, 2019, 3:43am UTC](https://discuss.elastic.co/t/access-currently-authenticated-user-from-custom-realm-logic/167082/2 "2019-02-15T03:43:41Z")

</div>

Hi @Guiss39,

If you look at the documentation for `token()` you will see that this method is responsible  
for extracting the authentication token from the request. So at this point, the authentication  
is still in progress and there is no information regarding User and its role.

> <https://github.com/elastic/elasticsearch/blob/9723458e3243f93ddd9c708737cb0269f932fc6b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/Realm.java#L96>

Could you please give us some details as to what you are trying to do? so we can help you better.

Regards,  
Yogesh Gaikwad

---

<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:** [March 15, 2019, 3:43am UTC](https://discuss.elastic.co/t/access-currently-authenticated-user-from-custom-realm-logic/167082/3 "2019-03-15T03:43:41Z")

</div>

Closed on March 15, 2019, 3:43am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
