Set process starter

133 views
Skip to first unread message

p.leu...@gmail.com

unread,
Oct 13, 2014, 6:37:30 AM10/13/14
to camunda-...@googlegroups.com
Hi,

this is probably a very basic question, but I cannot find the information in the documentation:

I am starting CDI-injected processes by org.camunda.bpm.engine.cdi.BusinessProcess.startProcessByKey(String).
Later in my application I would like to query running instances by org.camunda.bpm.engine.history.HistoricProcessInstanceQuery.startedBy(String).

Until now I have not found a way to associate a fresh instance with the starting user, thus my query does not work.

Please let me know how to do this.

Thanks,
Philipp

Daniel Meyer

unread,
Oct 14, 2014, 4:28:16 AM10/14/14
to camunda-...@googlegroups.com, p.leu...@gmail.com
Hi Philipp,

You need to set the currently authenticated user:

@Inject
private BusinessProcess businessProcess;

@Inject
private IdentityService identityService;


public startProcess(...) {
 
try {
    identityService
.setAuthenticatedUserId("jonny");
    businessProcess
.startProcessByKey(...)
 
}
 
finally{
    identityService
.clearAuthentication();
 
}
}



If you have a application you could also set the authentication globally somewhere using a ServletFilter or something.

Does this help you?

Cheers,
Daniel

p.leu...@gmail.com

unread,
Oct 14, 2014, 5:21:46 AM10/14/14
to camunda-...@googlegroups.com, p.leu...@gmail.com
Thanks, Daniel! This is exactly what I was looking for.

Cheers,
Philipp

Si Joe

unread,
Jan 16, 2015, 11:28:59 AM1/16/15
to camunda-...@googlegroups.com, p.leu...@gmail.com
Hi Daniel,

Thanks for your tip on setting authentication globally using a Servlet Filter. 

I have two questions:
1. Can I do a @Inject IdentityService within a servlet filter ?
2. In this case where do I call clearAuthentiction() ?

Regards

Si Joe

Daniel Meyer

unread,
Jan 19, 2015, 2:45:23 AM1/19/15
to camunda-...@googlegroups.com, p.leu...@gmail.com
Hi Si Joe,

CDI Injection into Filters should work in Java EE 6 and better. If it does not work, you can access the identity service using

IdentityService identityService = ProcessEngines.getDefaultProcessEngine().getIdentityService();

The filter pattern would work like this:

public class SecurityFilter implements Filter {

 
@Inject
 
private IdentityService identityService;

 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
 
    identityService
.setAuthenticatedUserId("jonny");
   
try {
      chain
.doFilter(request, response);
   
}
   
finally {
      identityService
.clearAuthentication();
   
}
 
}
 
}


Hpe this helps,
Daniel

Si Joe

unread,
Jan 27, 2015, 10:11:43 AM1/27/15
to camunda-...@googlegroups.com, p.leu...@gmail.com
Hi Daniel,

That was perfect and works like a charm.

Thanks

S. Joe

--
You received this message because you are subscribed to a topic in the Google Groups "camunda BPM users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camunda-bpm-users/R9yo6X945yo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/17e9efb1-37dc-4ac8-ba61-d7e37aaa3431%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages