cancel
Showing results for 
Search instead for 
Did you mean: 

acegi error with Async tasks within workflow

chud
Champ in-the-making
Champ in-the-making
Hi,

I have a workflow with some nodes in it which I would like to run asynchronously. Unfortunately when changing the node to have the attribute a async="true" the workflow stops working and raises the following error:

Caused by: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:477)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:355)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:148)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy11.exists(Unknown Source)
   at org.alfresco.repo.jscript.ScriptNode.toString(ScriptNode.java:2632)
   at java.lang.String.valueOf(String.java:2826)
   at java.lang.StringBuilder.append(StringBuilder.java:115)
   at java.util.AbstractMap.toString(AbstractMap.java:490)
   at java.lang.String.valueOf(String.java:2826)
   at java.lang.StringBuilder.append(StringBuilder.java:115)
   at org.jbpm.graph.action.Script.eval(Script.java:122)
   at org.jbpm.graph.action.Script.eval(Script.java:73)
   at org.jbpm.graph.action.Script.execute(Script.java:62)
   at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:284)

I thought this might be a problem with our action so i tried testing async on a fresh install of version of 3.2r. I first fired off the adhoc workflow and it worked, I then changed adhoc_processdefinition.xml to have
<task-node name="adhoc" async="true"> and <task-node name="completed" async="true"> and then changed bootstrap-context.xml to republish the workflow:


                <props>
                    <prop key="engineId">jbpm</prop>
                    <prop key="location">alfresco/workflow/adhoc_processdefinition.xml</prop>
                    <prop key="mimetype">text/xml</prop>
                    <prop key="redeploy">true</prop>
                </props>

and this also raises the same error as above.


I managed to find another post about the same issue but with no responses:
http://forums.alfresco.com/en/viewtopic.php?f=34&t=21524&p=70772&hilit=async#p70772

Does anyone know how I can make sure that the workflow asynchronous threads are given the correct acegi authentication credentials or if I am missing something in the setup of an asynchronous workflow node?

Thanks in advance
2 REPLIES 2

matjazmuhic
Champ on-the-rise
Champ on-the-rise
Hm. Could you post the whole process definition? Not much I can guess from what you posted…

It looks like the task can't be run because no credentials are found. As far as I know the tasks must run inside user transactions and by default they do. I don't know about async tasks.
My best guess is to try adding this inside action tags:
<runas>admin</runas>

I'm just guessing….

chud
Champ in-the-making
Champ in-the-making
Thanks for your thoughts.
Sorry i should have mentioned i have tried setting the runas element in the actions and it gives the same error. Or is there a way to specify that an entire node should be run as someone?

the process definition is the exact adhoc task that comes straight out of the box but with the added attributes to make it asynchronous eg:

<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:adhoc">

   <swimlane name="initiator"/>

   <start-state name="start">
      <task name="wf:submitAdhocTask" swimlane="initiator"/>
      <transition name="" to="adhoc"/>
   </start-state>

   <swimlane name="assignee">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{bpm_assignee}</actor>
      </assignment>
   </swimlane>
  
   <task-node name="adhoc" async="true">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
            <script>
               if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
               if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
            </script>
         </event>
      </task>
      <transition name="" to="completed">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript" async="true">
           <script>
              if (wf_notifyMe)
              {
                 var mail = actions.create("mail");
                 mail.parameters.to = initiator.properties.email;
                 mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
                 mail.parameters.text = "It's done";
                 mail.execute(bpm_package);
              }
           </script>
         </action>
      </transition>
   </task-node>
  
   <task-node name="completed" async="true">
      <task name="wf:completedAdhocTask" swimlane="initiator"/>
      <transition name="" to="end"/>
   </task-node>
     
   <end-state name="end"/>
  
</process-definition>

thanks for the suggestion and any others would be great Smiley Happy