ALF-16098: Authenticated execution of asynchronous executions (introduced in Activiti 5.10)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@42261 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Frederik Heremans
2012-10-02 12:48:40 +00:00
parent dcce548a8d
commit 621e6949de
21 changed files with 131 additions and 26 deletions

View File

@@ -6,7 +6,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiAdhoc" name="Adhoc Activiti Process">
<process isExecutable="true" id="activitiAdhoc" name="Adhoc Activiti Process">
<startEvent id="start"
activiti:formKey="wf:submitAdhocTask" />
@@ -15,7 +15,7 @@
targetRef='adhocTask' />
<userTask id="adhocTask" name="Adhoc Task"
activiti:formKey="wf:adhocTask">
activiti:formKey="wf:adhocTask" activiti:async="true">
<extensionElements>
<activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">

View File

@@ -4,7 +4,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiInvitationModerated" name="Moderated activiti invitation process">
<process isExecutable="true" id="activitiInvitationModerated" name="Moderated activiti invitation process">
<startEvent id="start" activiti:formKey="imwf:moderatedInvitationSubmitTask" />

View File

@@ -4,7 +4,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiInvitationNominated" name="Nominated activiti invitation process">
<process isExecutable="true" id="activitiInvitationNominated" name="Nominated activiti invitation process">
<startEvent id="start" activiti:formKey="inwf:inviteToSiteTask" />

View File

@@ -6,7 +6,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiParallelGroupReview" name="Parallel Group Review And Approve Activiti Process">
<process isExecutable="true" id="activitiParallelGroupReview" name="Parallel Group Review And Approve Activiti Process">
<extensionElements>
<activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">

View File

@@ -6,7 +6,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiParallelReview" name="Parallel Review And Approve Activiti Process">
<process isExecutable="true" id="activitiParallelReview" name="Parallel Review And Approve Activiti Process">
<extensionElements>
<activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">

View File

@@ -6,7 +6,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="publishWebContent" name="Publish Web Content Activiti Process">
<process isExecutable="true" id="publishWebContent" name="Publish Web Content Activiti Process">
<startEvent id="start"
activiti:formKey="pubwf:startPublish" />

View File

@@ -6,7 +6,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiReviewPooled" name="Pooled Review And Approve Activiti Process">
<process isExecutable="true" id="activitiReviewPooled" name="Pooled Review And Approve Activiti Process">
<startEvent id="start"
activiti:formKey="wf:submitGroupReviewTask" />

View File

@@ -6,7 +6,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">
<process id="activitiReview" name="Review And Approve Activiti Process">
<process isExecutable="true" id="activitiReview" name="Review And Approve Activiti Process">
<startEvent id="start"
activiti:formKey="wf:submitReviewTask" />

View File

@@ -21,7 +21,9 @@ package org.alfresco.repo.workflow.activiti;
import java.util.List;
import org.activiti.engine.impl.jobexecutor.AsyncContinuationJobHandler;
import org.activiti.engine.impl.jobexecutor.JobHandler;
import org.activiti.engine.impl.jobexecutor.TimerCatchIntermediateEventJobHandler;
import org.activiti.engine.impl.jobexecutor.TimerExecuteNestedActivityJobHandler;
import org.activiti.engine.impl.variable.SerializableType;
import org.activiti.engine.impl.variable.VariableType;
@@ -56,12 +58,21 @@ public class AlfrescoProcessEngineConfiguration extends SpringProcessEngineConfi
{
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);
// Wrap timer-job handler to handle authentication
JobHandler timerJobHandler = jobHandlers.get(TimerExecuteNestedActivityJobHandler.TYPE);
JobHandler wrappingTimerJobHandler = new AuthenticatedTimerJobHandler(timerJobHandler);
jobHandlers.put(TimerExecuteNestedActivityJobHandler.TYPE, wrappingTimerJobHandler);
// Wrap async-job handler to handle authentication
JobHandler asyncJobHandler = jobHandlers.get(AsyncContinuationJobHandler.TYPE);
JobHandler wrappingAsyncJobHandler = new AuthenticatedAsyncJobHandler(asyncJobHandler);
jobHandlers.put(AsyncContinuationJobHandler.TYPE, wrappingAsyncJobHandler);
// Wrap intermediate-timer-job handler to handle authentication
JobHandler intermediateJobHandler = jobHandlers.get(TimerCatchIntermediateEventJobHandler.TYPE);
JobHandler wrappingIntermediateJobHandler = new AuthenticatedAsyncJobHandler(intermediateJobHandler);
jobHandlers.put(TimerCatchIntermediateEventJobHandler.TYPE, wrappingIntermediateJobHandler);
}
public void setCustomTypes(List<VariableType> customTypes)

View File

@@ -0,0 +1,94 @@
/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.workflow.activiti;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.jobexecutor.JobHandler;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.workflow.WorkflowConstants;
/**
* An {@link JobHandler} which executes activiti jobs authenticated against Alfresco.
* The job is executed as the process-initiator. If initiator is not available, system user is used.
*
* It wraps another JobHandler to which the actual execution is delegated to.
*
* @author Frederik Heremans
* @since 4.2
*/
public class AuthenticatedAsyncJobHandler implements JobHandler
{
private JobHandler wrappedHandler;
public AuthenticatedAsyncJobHandler(JobHandler jobHandler)
{
if (jobHandler == null)
{
throw new IllegalArgumentException("JobHandler to delegate to is required");
}
this.wrappedHandler = jobHandler;
}
@Override
public void execute(final String configuration, final ExecutionEntity execution,
final CommandContext commandContext)
{
// Get initiator
String userName = AuthenticationUtil.runAsSystem(new RunAsWork<String>() {
@Override
public String doWork() throws Exception {
ActivitiScriptNode ownerNode = (ActivitiScriptNode) execution.getVariable(WorkflowConstants.PROP_INITIATOR);
if(ownerNode != null && ownerNode.exists())
{
return (String) ownerNode.getProperties().get(ContentModel.PROP_USERNAME);
}
return null;
}
});
// When no initiator is set, use system user to run job
if (userName == null)
{
userName = AuthenticationUtil.getSystemUserName();
}
// Execute job
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
@SuppressWarnings("synthetic-access")
public Void doWork() throws Exception
{
wrappedHandler.execute(configuration, execution, commandContext);
return null;
}
}, userName);
}
@Override
public String getType()
{
return wrappedHandler.getType();
}
}

View File

@@ -82,7 +82,7 @@ public class AuthenticatedTimerJobHandler implements JobHandler
userName = AuthenticationUtil.getSystemUserName();
}
// Execute timer
// Execute timer
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
@SuppressWarnings("synthetic-access")

View File

@@ -8,7 +8,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="adhoc" name="Adhoc Process">
<process isExecutable="true" id="adhoc" name="Adhoc Process">
<startEvent id="start"
activiti:formKey="adhocStart.form" />

View File

@@ -5,7 +5,7 @@
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="testAdhoc" name="Test Adhoc Process">
<process isExecutable="true" id="testAdhoc" name="Test Adhoc Process">
<startEvent id="start" activiti:formKey="wf:submitAdhocTask" />

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="MyProcess" name="MyProcess">
<process isExecutable="true" id="MyProcess" name="MyProcess">
<documentation>Custom activiti, created to test that the priority is automatically set to an allowed value e.g. change from 50 to 2.</documentation>
<startEvent id="alfrescoStartevent1" name="Alfresco start"></startEvent>
<userTask id="alfrescoUsertask1" name="Alfresco User Task">

View File

@@ -6,7 +6,7 @@
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="testDiagram" name="Test Process Diagram">
<process isExecutable="true" id="testDiagram" name="Test Process Diagram">
<startEvent id="start" activiti:formKey="bpm_foo" />
<sequenceFlow id='flow2' sourceRef='start'
targetRef='firstTask' />

View File

@@ -5,7 +5,7 @@
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="testJob" name="Test Timer Job Process">
<process isExecutable="true" id="testJob" name="Test Timer Job Process">
<startEvent id="start" activiti:formKey="bpm_foo" />

View File

@@ -5,7 +5,7 @@
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="testReview" name="Test Review Process">
<process isExecutable="true" id="testReview" name="Test Review Process">
<startEvent id="start"
activiti:formKey="wf:submitReviewTask" />

View File

@@ -5,7 +5,7 @@
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="testSignalling" name="Process to Test Signalling">
<process isExecutable="true" id="testSignalling" name="Process to Test Signalling">
<startEvent id="start" activiti:formKey="wf:submitAdhocTask" />

View File

@@ -5,7 +5,7 @@
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="testTimer" name="Test Timer Job Process">
<process isExecutable="true" id="testTimer" name="Test Timer Job Process">
<startEvent id="start" activiti:formKey="bpm:startTask" />

View File

@@ -5,7 +5,7 @@
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="testTimerTransaction" name="Test Timer Job Process">
<process isExecutable="true" id="testTimerTransaction" name="Test Timer Job Process">
<startEvent id="start" activiti:formKey="bpm:startTask" />

View File

@@ -5,7 +5,7 @@
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:activiti="http://activiti.org/bpmn">
<process id="testTask" name="Test Task Process">
<process isExecutable="true" id="testTask" name="Test Task Process">
<startEvent id="start2" activiti:formKey="bpm_foo" />