Get Current user using Java?

Hi all,

I think the question is clear but here´s the scenario:

Class Customer extends UserEntity
Customers are stored in a Group("customers")

Group customers (and only customers) has Authorization to start a ProcessInstance from Process “Start_Process”. The Process has no activitys, it just starts with a form and ends with a message(Java implementation) that Starts another Process passing all variables to it.

Java class toDo is: Get the Customer as User-> cast to customer → set a few Variables using Processvariables → Start the next Process by Message.

Maybe i´m away on the wrong but i thought about something like this working for all Customers:

Customer customer = (Customer)de.getProcessEngineServices().
getIdentityService().createUserQuery().
userId(
de.getProcessEngineServices().getIdentityService().getCurrentAuthentication().getUserId()
)
.singleResult();

But now i don´t think that will work… i should use something that returns the user that has started the ProcessInstance or pass the Customer as a Processvariable

thanks ahead!

Hi @s0561355,

it will work, as getCurrentAuthentication() gets the userId of the user who has done the last command in the process engine (here started the process instance).

You can use it to query the details if the user.

But you have call this implementation before you reach the first transaction boundary, maybe as the first activity or as a listener on the start event. If the job executor executes this method, the userId will be empty.

Cheers, Ingo

2 Likes