- 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:
Roy Wetherall
2006-02-11 20:50:05 +00:00
parent 681960a849
commit c4a4e7ecba
5 changed files with 85 additions and 88 deletions

View File

@@ -5,18 +5,15 @@
<!-- 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">
<ref bean="NodeService" />
</property>
<property name="policyComponent">
<ref bean="policyComponent"/>
</property>
<property name="searchService">
<ref bean="SearchService" />
</property>
<property name="transactionService">
<ref bean="transactionComponent"/>
<property name="authenticationComponent">
<ref bean="authenticationComponent" />
</property>
<property name="asynchronousActionExecutionQueue">
<ref bean="asynchronousActionExecutionQueue"/>

View File

@@ -85,6 +85,11 @@ public class ActionImpl extends ParameterizedItemImpl
*/
private String actionDefinitionName;
/**
* The run as user name
*/
private String runAsUserName;
/**
* The owning node reference
*/
@@ -377,4 +382,14 @@ public class ActionImpl extends ParameterizedItemImpl
{
return actionChain;
}
public String getRunAsUser()
{
return this.runAsUserName;
}
public void setRunAsUser(String runAsUserName)
{
this.runAsUserName = runAsUserName;
}
}

View File

@@ -28,7 +28,7 @@ import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
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.service.cmr.action.Action;
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.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.GUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -89,16 +88,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
*/
private ApplicationContext applicationContext;
/**
* The transacton service
*/
private TransactionService transactionService;
/**
* The policy component
*/
private PolicyComponent policyComponent;
/**
* The node service
*/
@@ -109,6 +98,9 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
*/
private SearchService searchService;
/** The authentication component */
private AuthenticationComponent authenticationComponent;
/**
* The asynchronous action execution queue
*/
@@ -139,16 +131,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
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
*
@@ -170,13 +152,13 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
}
/**
* 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;
}
/**
@@ -200,13 +182,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
return asynchronousActionExecutionQueue;
}
/**
* Initialise methods called by Spring framework
*/
public void initialise()
{
}
/**
* Gets the saved action folder reference
*
@@ -399,7 +374,6 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
try
{
//Set<String> currentActionChain = this.currentActionChain.get();
Set<String> origActionChain = null;
if (actionChain == null)
@@ -457,6 +431,9 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
Action compensatingAction = action.getCompensatingAction();
if (compensatingAction != null)
{
// 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);
}
@@ -481,6 +458,12 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
*/
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
ActionExecuter executer = (ActionExecuter)this.applicationContext.getBean(action.getActionDefinitionName());
executer.execute(action, actionedUponNodeRef);
@@ -1097,6 +1080,13 @@ public class ActionServiceImpl implements ActionService, RuntimeActionService, A
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
AlfrescoTransactionSupport.bindListener(this.transactionListener);

View File

@@ -24,9 +24,12 @@ import java.util.concurrent.TimeUnit;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionUtil;
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.transaction.TransactionService;
import freemarker.log.Logger;
/**
* The asynchronous action execution queue implementation
*
@@ -261,32 +264,37 @@ public class AsynchronousActionExecutionQueueImpl extends ThreadPoolExecutor imp
{
try
{
// For now run all actions in the background as the system user
ActionExecutionWrapper.this.authenticationComponent
.setCurrentUser(ActionExecutionWrapper.this.authenticationComponent.getSystemUserName());
try
// Get the run as user name
final String userName = ((ActionImpl)ActionExecutionWrapper.this.action).getRunAsUser();
if (userName == null)
{
throw new ActionServiceException("Cannot execute action asynchronously since run as user is 'null'");
}
TransactionUtil.executeInNonPropagatingUserTransaction(this.transactionService,
new TransactionUtil.TransactionWork()
{
public Object doWork()
{
ActionExecutionWrapper.this.authenticationComponent
.setCurrentUser(userName);
try
{
ActionExecutionWrapper.this.actionService.executeActionImpl(
ActionExecutionWrapper.this.action,
ActionExecutionWrapper.this.actionedUponNodeRef,
ActionExecutionWrapper.this.checkConditions, true,
ActionExecutionWrapper.this.actionChain);
return null;
}
});
}
finally
{
ActionExecutionWrapper.this.authenticationComponent.clearCurrentSecurityContext();
}
return null;
}
});
}
catch (Throwable exception)
{

View File

@@ -102,23 +102,10 @@ public abstract class RuleTriggerAbstractBase implements RuleTrigger
* the node reference that will be actioned upon by the rules
*/
protected void triggerRules(NodeRef nodeRef, NodeRef actionedUponNodeRef)
{
String userName = authenticationComponent.getCurrentUserName();
authenticationComponent.setSystemUserAsCurrentUser();
try
{
for (RuleType ruleType : this.ruleTypes)
{
ruleType.triggerRuleType(nodeRef, actionedUponNodeRef);
}
}
finally
{
authenticationComponent.clearCurrentSecurityContext();
if(userName != null)
{
authenticationComponent.setCurrentUser(userName);
}
}
}
}