AnsweredAssumed Answered

Time start events and authentication

Question asked by ungawunga on Dec 11, 2013
Per some documentation we managed to find on Activiti Start Time Events, we found this:

"When a timer fires, it's executed by a job-executor thread. In this thread, by default, NO authenticated user is set. However, if you really want timers to be executed as a certain user, you can override the job handler. Good example of this is a class I implemented in alfresco, which uses the "assignee" of the task as authenticated user in alfresco. A similar approach can be created to call the setAuthenticatedUser() and clear it again before and after the time fires."

This also mentions authentication:
http://activiti.org/userguide/#bpmnStartEvents

It even has a code snippet:

try {
  identityService.setAuthenticatedUserId("bono");
  runtimeService.startProcessInstanceByKey("someProcessKey");
} finally {
  identityService.setAuthenticatedUserId(null);
}


My question:  how do we inject the 'identityService' object/bean into our java listener? What should the context.XML look like? We're looking for the property element's ref value to pass in the identityService bean.

If we can't go that route, how can we get the ProcessEngine bean? According to some Alfresco code we stumbled across by looking through the source code:

  public void setProcessEngine(ProcessEngine processEngine) {
    this.processEngine = processEngine;
    init();
  }

  public void init() {
    processEngine.getIdentityService().setAuthenticatedUserId("admin");
    initDemoData();
  }


How can we inject the ProcessEngine bean into our java listener?

Outcomes