# Get current authenticating user programmatically

**URL:** <https://forum.flowable.org/t/get-current-authenticating-user-programmatically/1368>\
**Category:** Flowable Engine\
**Created:** [December 26, 2017, 5:46pm UTC](https://forum.flowable.org/t/get-current-authenticating-user-programmatically/1368 "2017-12-26T17:46:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seq2seq](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@seq2seq](https://forum.flowable.org/u/seq2seq)\
**Post date:** [December 26, 2017, 5:46pm UTC](https://forum.flowable.org/t/get-current-authenticating-user-programmatically/1368/1 "2017-12-26T17:46:26Z")

</div>

How to get the username of the actual authenticating user in a Java Service Task?

---

<div class="post-metadata">

**Author:** ![fegorama](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/fegorama/32/313_2.png) [@fegorama](https://forum.flowable.org/u/fegorama)\
**Post date:** [December 27, 2017, 11:07am UTC](https://forum.flowable.org/t/get-current-authenticating-user-programmatically/1368/2 "2017-12-27T11:07:34Z")

</div>

User currentUser = SecurityUtils.getCurrentUserObject();  
String userId=currentUser.getId();

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [December 29, 2017, 4:05pm UTC](https://forum.flowable.org/t/get-current-authenticating-user-programmatically/1368/4 "2017-12-29T16:05:35Z")

</div>

Note that the SecurityUtils class is only available on the classpath of the UI application.

---

<div class="post-metadata">

**Author:** ![jit](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jit](https://forum.flowable.org/u/jit)\
**Post date:** [February 9, 2022, 6:11pm UTC](https://forum.flowable.org/t/get-current-authenticating-user-programmatically/1368/5 "2022-02-09T18:11:18Z")

</div>

@joram I want to get User session outside of the UI classpath and it is always returning null as expected.

Another workaround is to get **initiator** variable from execution and query the identity service with that information to list user details but this is not a secure way since someone may override this **initiator** variable from Script Task and pretend to be that user. So what is the secure way of doing this?
