- 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

@@ -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)
{
TransactionUtil.executeInNonPropagatingUserTransaction(this.transactionService,
new TransactionUtil.TransactionWork()
{
public Object doWork()
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;
ActionExecutionWrapper.this.action,
ActionExecutionWrapper.this.actionedUponNodeRef,
ActionExecutionWrapper.this.checkConditions, true,
ActionExecutionWrapper.this.actionChain);
}
});
}
finally
{
ActionExecutionWrapper.this.authenticationComponent.clearCurrentSecurityContext();
}
finally
{
ActionExecutionWrapper.this.authenticationComponent.clearCurrentSecurityContext();
}
return null;
}
});
}
catch (Throwable exception)
{