Get user id from tasklist in JSF CDI Bean

I use the camunda tasklist and external jsf forms. I know that I have to set the userId from the logged in user in the identityService from camunda to handle my jsf form authentication. Is there a way to get the userid from tasklist? Or from anywhere else?
Thanks a lot,

Hi @NickiMueller,

I don’t know if it works in a JSF environment, but the engine has a built-in-expression: ${currentUser()}.

Here are the details:

Hope this helps, Ingo

HI @Ingo_Richtsmeier,
thanks you for your answer. But I am really confused and do not understand where and how to use this code.
I think I would need a service task like this:

So in my bpmn-file I see the following code
<bpmn:serviceTask id=“setUserTask” name=“setUserTask” camunda:expression="${currentUser}">

But how can I now read in in my cdi bean?
Sorry for my confusion.
Thanks so much for your help.

@NickiMueller it should be like below:

<bpmn:serviceTask id="setUserTask" name="setUserTask" camunda:expression="${currentUser()}">

Function Return Type Description
currentUser() String Returns the user id of the currently authenticated user or null no user is authenticated at the moment.

Hi @NickiMueller,

I havn’t been deep in JSF development, but I would try to use the expression in the JSF page itself. If the user is logged in, it should get the ID.

What do you want to use the userId for?

BTW, in your sceenshot you’re missing the parenthesis for the method call.

Here is the implementation if the function:

Hope this helps, Ingo

Good morning,

thanks for your ideas.
@Ingo_Richtsmeier I tried to directly use the method in jsf but that does not work.

@Ingo_Richtsmeier Why I need the logged in user:
I work with external jsf forms. A camunda user (for example a user named “studi1” in group “StudentGroup”) can start a process named “Abschlussarbeit beantragen” via the camunda tasklist. The studi1 user can now add his master data to the form.
Now I want to save the data for my studi1 user and therefore I need the username.
Another thing is that I want to show the logged in user name in my jsf external forms.

I tried to set a processVariable via using the currentUser() method:
I took pizza order example. I added the following code in placeorder.jsf:

   <label for="currentUser">CurrentUser</label>
      <!-- create process variables using the processVariables map. -->

<h:outputText id=“currentUser” value="#{processVariables[’$currentUser()’]}" required=“true” />

Then I tried to read it in via:

Map<String, Object> variables = delegateExecution.getVariables();

  String currentUser = (String) variables.get("currentUser");

But the currentUser is null.

Any more ideas? Do you know a way via javascript to read the logged in user? So I could write the user
in HttpSession and try to read in my CDI Bean via HTTPSession Object? Unfortunately I am not used to write javascipts.

Thank you a lot for you help!

Current user is neither stored as process variables nor task variables