JobExecutor to run jobs within a context.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2013 12:47 AM
Hi,
Is it possible to make jobExecutor to run jobs within some context??. The usecase here is, the async tasks which would communicate with my application would need some user permissions. The process instance starts with this security context in the thread local but this context is not propogated to Jobexecutor as the jobs will be run by altogether different threads.
Thanks
Sujata
Is it possible to make jobExecutor to run jobs within some context??. The usecase here is, the async tasks which would communicate with my application would need some user permissions. The process instance starts with this security context in the thread local but this context is not propogated to Jobexecutor as the jobs will be run by altogether different threads.
Thanks
Sujata
Labels:
- Labels:
-
Archive
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2013 07:57 AM
Inside Alfresco, activiti uses a custom JobHandler to achieve this:
http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/jav...
Before executing the Timer (or any other job you want to handle) a context is built up for the thread, depending on task's assignee of process-initiator. We wrap the default one provided by activiti:
Using a custom ProcessEngineConfiguration, we wrap the original job-handler:
http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/jav...
Before executing the Timer (or any other job you want to handle) a context is built up for the thread, depending on task's assignee of process-initiator. We wrap the default one provided by activiti:
// Execute timer
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
@SuppressWarnings("synthetic-access")
public Void doWork() throws Exception
{
wrappedHandler.execute(job, configuration, execution, commandContext);
return null;
}
}, userName);
Using a custom ProcessEngineConfiguration, we wrap the original job-handler:
@Override
protected void initJobExecutor()
{
super.initJobExecutor();
// Get the existing timer-job handler and wrap
// with one that is alfresco-authentication aware
JobHandler jobHandler = jobHandlers.get(TimerExecuteNestedActivityJobHandler.TYPE);
JobHandler wrappingJobHandler = new AuthenticatedTimerJobHandler(jobHandler);
jobHandlers.put(TimerExecuteNestedActivityJobHandler.TYPE, wrappingJobHandler);
}
