mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Asynchronous rules are now executed as the user that triggers the rule.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2349 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -5,19 +5,16 @@
|
|||||||
|
|
||||||
<!-- Action Service -->
|
<!-- Action Service -->
|
||||||
|
|
||||||
<bean id="actionService" class="org.alfresco.repo.action.ActionServiceImpl" init-method="initialise">
|
<bean id="actionService" class="org.alfresco.repo.action.ActionServiceImpl">
|
||||||
<property name="nodeService">
|
<property name="nodeService">
|
||||||
<ref bean="NodeService" />
|
<ref bean="NodeService" />
|
||||||
</property>
|
</property>
|
||||||
<property name="policyComponent">
|
|
||||||
<ref bean="policyComponent"/>
|
|
||||||
</property>
|
|
||||||
<property name="searchService">
|
<property name="searchService">
|
||||||
<ref bean="SearchService" />
|
<ref bean="SearchService" />
|
||||||
</property>
|
</property>
|
||||||
<property name="transactionService">
|
<property name="authenticationComponent">
|
||||||
<ref bean="transactionComponent"/>
|
<ref bean="authenticationComponent" />
|
||||||
</property>
|
</property>
|
||||||
<property name="asynchronousActionExecutionQueue">
|
<property name="asynchronousActionExecutionQueue">
|
||||||
<ref bean="asynchronousActionExecutionQueue"/>
|
<ref bean="asynchronousActionExecutionQueue"/>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -85,6 +85,11 @@ public class ActionImpl extends ParameterizedItemImpl
|
|||||||
*/
|
*/
|
||||||
private String actionDefinitionName;
|
private String actionDefinitionName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The run as user name
|
||||||
|
*/
|
||||||
|
private String runAsUserName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The owning node reference
|
* The owning node reference
|
||||||
*/
|
*/
|
||||||
@@ -377,4 +382,14 @@ public class ActionImpl extends ParameterizedItemImpl
|
|||||||
{
|
{
|
||||||
return actionChain;
|
return actionChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRunAsUser()
|
||||||
|
{
|
||||||
|
return this.runAsUserName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRunAsUser(String runAsUserName)
|
||||||
|
{
|
||||||
|
this.runAsUserName = runAsUserName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ import java.util.Set;
|
|||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
|
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
|
||||||
import org.alfresco.repo.action.executer.ActionExecuter;
|
import org.alfresco.repo.action.executer.ActionExecuter;
|
||||||
import org.alfresco.repo.policy.PolicyComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.action.ActionCondition;
|
import org.alfresco.service.cmr.action.ActionCondition;
|
||||||
@@ -46,7 +46,6 @@ import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
|
|||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
|
||||||
import org.alfresco.util.GUID;
|
import org.alfresco.util.GUID;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -88,16 +87,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
* The application context
|
* The application context
|
||||||
*/
|
*/
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
/**
|
|
||||||
* The transacton service
|
|
||||||
*/
|
|
||||||
private TransactionService transactionService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The policy component
|
|
||||||
*/
|
|
||||||
private PolicyComponent policyComponent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The node service
|
* The node service
|
||||||
@@ -108,6 +97,9 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
* The search service
|
* The search service
|
||||||
*/
|
*/
|
||||||
private SearchService searchService;
|
private SearchService searchService;
|
||||||
|
|
||||||
|
/** The authentication component */
|
||||||
|
private AuthenticationComponent authenticationComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The asynchronous action execution queue
|
* The asynchronous action execution queue
|
||||||
@@ -138,16 +130,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
{
|
{
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the policy component
|
|
||||||
*
|
|
||||||
* @param policyComponent the policy component to register with
|
|
||||||
*/
|
|
||||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
|
||||||
{
|
|
||||||
this.policyComponent = policyComponent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the node service
|
* Set the node service
|
||||||
@@ -168,17 +150,17 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
{
|
{
|
||||||
this.searchService = searchService;
|
this.searchService = searchService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the transaction service
|
* Set the authentication component
|
||||||
*
|
*
|
||||||
* @param transactionService the transaction service
|
* @param authenticationComponent the authentication component
|
||||||
*/
|
*/
|
||||||
public void setTransactionService(TransactionService transactionService)
|
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
||||||
{
|
{
|
||||||
this.transactionService = transactionService;
|
this.authenticationComponent = authenticationComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the asynchronous action execution queue
|
* Set the asynchronous action execution queue
|
||||||
*
|
*
|
||||||
@@ -199,13 +181,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
{
|
{
|
||||||
return asynchronousActionExecutionQueue;
|
return asynchronousActionExecutionQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise methods called by Spring framework
|
|
||||||
*/
|
|
||||||
public void initialise()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the saved action folder reference
|
* Gets the saved action folder reference
|
||||||
@@ -399,7 +374,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Set<String> currentActionChain = this.currentActionChain.get();
|
|
||||||
Set<String> origActionChain = null;
|
Set<String> origActionChain = null;
|
||||||
|
|
||||||
if (actionChain == null)
|
if (actionChain == null)
|
||||||
@@ -457,7 +431,10 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
Action compensatingAction = action.getCompensatingAction();
|
Action compensatingAction = action.getCompensatingAction();
|
||||||
if (compensatingAction != null)
|
if (compensatingAction != null)
|
||||||
{
|
{
|
||||||
// Queue the compensating action ready for execution
|
// Set the current user
|
||||||
|
((ActionImpl)compensatingAction).setRunAsUser(this.authenticationComponent.getCurrentUserName());
|
||||||
|
|
||||||
|
// Queue the compensating action ready for execution
|
||||||
this.asynchronousActionExecutionQueue.executeAction(this, compensatingAction, actionedUponNodeRef, false, null);
|
this.asynchronousActionExecutionQueue.executeAction(this, compensatingAction, actionedUponNodeRef, false, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -481,6 +458,12 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
*/
|
*/
|
||||||
public void directActionExecution(Action action, NodeRef actionedUponNodeRef)
|
public void directActionExecution(Action action, NodeRef actionedUponNodeRef)
|
||||||
{
|
{
|
||||||
|
// Debug output
|
||||||
|
if (logger.isDebugEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.debug("The action is being executed as the user: " + this.authenticationComponent.getCurrentUserName());
|
||||||
|
}
|
||||||
|
|
||||||
// Get the action executer and execute
|
// Get the action executer and execute
|
||||||
ActionExecuter executer = (ActionExecuter)this.applicationContext.getBean(action.getActionDefinitionName());
|
ActionExecuter executer = (ActionExecuter)this.applicationContext.getBean(action.getActionDefinitionName());
|
||||||
executer.execute(action, actionedUponNodeRef);
|
executer.execute(action, actionedUponNodeRef);
|
||||||
@@ -1097,6 +1080,13 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
|
|||||||
logger.debug("Doing addPostTransactionPendingAction");
|
logger.debug("Doing addPostTransactionPendingAction");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the run as user to the current user
|
||||||
|
if (logger.isDebugEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.debug("The current user is: " + this.authenticationComponent.getCurrentUserName());
|
||||||
|
}
|
||||||
|
((ActionImpl)action).setRunAsUser(this.authenticationComponent.getCurrentUserName());
|
||||||
|
|
||||||
// Ensure that the transaction listener is bound to the transaction
|
// Ensure that the transaction listener is bound to the transaction
|
||||||
AlfrescoTransactionSupport.bindListener(this.transactionListener);
|
AlfrescoTransactionSupport.bindListener(this.transactionListener);
|
||||||
|
|
||||||
|
@@ -24,9 +24,12 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil;
|
import org.alfresco.repo.transaction.TransactionUtil;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
|
import org.alfresco.service.cmr.action.ActionServiceException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
|
||||||
|
import freemarker.log.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The asynchronous action execution queue implementation
|
* The asynchronous action execution queue implementation
|
||||||
*
|
*
|
||||||
@@ -261,32 +264,37 @@ public class AsynchronousActionExecutionQueueImpl extends ThreadPoolExecutor imp
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Get the run as user name
|
||||||
// For now run all actions in the background as the system user
|
final String userName = ((ActionImpl)ActionExecutionWrapper.this.action).getRunAsUser();
|
||||||
ActionExecutionWrapper.this.authenticationComponent
|
if (userName == null)
|
||||||
.setCurrentUser(ActionExecutionWrapper.this.authenticationComponent.getSystemUserName());
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
TransactionUtil.executeInNonPropagatingUserTransaction(this.transactionService,
|
throw new ActionServiceException("Cannot execute action asynchronously since run as user is 'null'");
|
||||||
new TransactionUtil.TransactionWork()
|
}
|
||||||
{
|
|
||||||
public Object doWork()
|
TransactionUtil.executeInNonPropagatingUserTransaction(this.transactionService,
|
||||||
|
new TransactionUtil.TransactionWork()
|
||||||
|
{
|
||||||
|
public Object doWork()
|
||||||
|
{
|
||||||
|
ActionExecutionWrapper.this.authenticationComponent
|
||||||
|
.setCurrentUser(userName);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
ActionExecutionWrapper.this.actionService.executeActionImpl(
|
ActionExecutionWrapper.this.actionService.executeActionImpl(
|
||||||
ActionExecutionWrapper.this.action,
|
ActionExecutionWrapper.this.action,
|
||||||
ActionExecutionWrapper.this.actionedUponNodeRef,
|
ActionExecutionWrapper.this.actionedUponNodeRef,
|
||||||
ActionExecutionWrapper.this.checkConditions, true,
|
ActionExecutionWrapper.this.checkConditions, true,
|
||||||
ActionExecutionWrapper.this.actionChain);
|
ActionExecutionWrapper.this.actionChain);
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
});
|
finally
|
||||||
}
|
{
|
||||||
finally
|
ActionExecutionWrapper.this.authenticationComponent.clearCurrentSecurityContext();
|
||||||
{
|
}
|
||||||
ActionExecutionWrapper.this.authenticationComponent.clearCurrentSecurityContext();
|
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (Throwable exception)
|
catch (Throwable exception)
|
||||||
{
|
{
|
||||||
|
@@ -103,22 +103,9 @@ public abstract class RuleTriggerAbstractBase implements RuleTrigger
|
|||||||
*/
|
*/
|
||||||
protected void triggerRules(NodeRef nodeRef, NodeRef actionedUponNodeRef)
|
protected void triggerRules(NodeRef nodeRef, NodeRef actionedUponNodeRef)
|
||||||
{
|
{
|
||||||
String userName = authenticationComponent.getCurrentUserName();
|
for (RuleType ruleType : this.ruleTypes)
|
||||||
authenticationComponent.setSystemUserAsCurrentUser();
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
for (RuleType ruleType : this.ruleTypes)
|
ruleType.triggerRuleType(nodeRef, actionedUponNodeRef);
|
||||||
{
|
|
||||||
ruleType.triggerRuleType(nodeRef, actionedUponNodeRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
authenticationComponent.clearCurrentSecurityContext();
|
|
||||||
if(userName != null)
|
|
||||||
{
|
|
||||||
authenticationComponent.setCurrentUser(userName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user