Cannot query user after enable Authorization Check

Hello,

I’ve implemented the TaskListener to notify assignee by email, refer to code

When Authorization Check is disabled, User object was returned properly but if Authorization Check enabled query service return null

IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService();
User user = identityService.createUserQuery().userId(assignee).singleResult();

Is there any authorisation need to be set ?

Thank you

Nont

Hi @nontster,

You can run your code without authentication as below

IdentityService identityService = delegateTask.getProcessEngineServices().getIdentityService();
Authentication currentAuthentication = identityService.getCurrentAuthentication();
try {
  identityService.clearAuthentication();
 
  // run your code without authentication
  User user = identityService.createUserQuery().userId(assignee).singleResult();

} finally {
  // set back authentication
  identityService.setAuthentication(currentAuthentication);
}

Hi @hassang

It works!

Thanks for you help :slight_smile:

Nont

1 Like