Get current authenticating user programmatically

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

1 Like

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

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

@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?