cancel
Showing results for 
Search instead for 
Did you mean: 

Control user performing automatic task

pcuvecle
Champ in-the-making
Champ in-the-making
Hi,

Since it is possible to write automatic task in a jBPM Workflow, how is it possible to control what user will run the associated action ?

ex :


<task-node name="myNode">
      <event type="node-leave">
         <action name="myAction" class="myActionHandler"></action>
      </event>
      <transition name="tr2" to="myOtherTask"></transition>
</task-node>

In that case myActionHandler will encapsulate some code that will manipulate content in the repository and I would like to be able to define an Alfresco user to perform this task since I need to give the appropriate rights to him.

Any idea ?
Thanks in advance
7 REPLIES 7

ribz33
Champ on-the-rise
Champ on-the-rise
If i understand well, i think at the moment you cant

i had post already about this…
http://forums.alfresco.com/viewtopic.php?t=4644&highlight=

If you need it you can vote on jira ticket
http://issues.alfresco.com/browse/AR-1142

pcuvecle
Champ in-the-making
Champ in-the-making
Hi,

Thanks for your quick answer  Smiley Happy
So If I understand well, the initiator of a workflow will be the user who will run the subsequent automatic tasks ?
I guess that the manual tasks assigned to real users will be exectuted under the corresponding credentials.

To workaround this, is there a way to eventually re-impersonate the session at the begining of a jBPM Action Handler class (even by providing the target user credentials) ?

davidc
Star Contributor
Star Contributor
Workflow actions are executed as the user who signals the next step of the workflow.  So, actions hooked into the start node are executed as the initiator, and subsequent task actions are executed as the user who ends the task.

You can execute as a specific user if you're developing your own Java action.  You can retrieve any Alfresco service (including AuthenticationService) within a java action - see org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript for an example of hooking into Alfresco services.  You can use AuthenticationService and AuthenticationUtils to a run as a specific user.

pcuvecle
Champ in-the-making
Champ in-the-making
Thanks David, I'll try to use to Authentication service to reimpersonate my session  :wink:

vladimir_kovaly
Champ in-the-making
Champ in-the-making
Have you succeeded? Could you please share the sources of your ActionHandler?

pcuvecle
Champ in-the-making
Champ in-the-making
System account impersonation exemple :


// save user credentials
Authentication currentAuthentication = authenticationComponent.getCurrentAuthentication();
// authenticate as system user
authenticationComponent.setSystemUserAsCurrentUser();
UserTransaction transaction = transactionService.getUserTransaction();
try {
    transaction.begin();
   
    // your code
   
    transaction.commit();
} catch (Exception e) {
    try {
        transaction.rollback();
    } catch (IllegalStateException e1) {
        // handle exception
    } catch (SecurityException e1) {
        // handle exception
    } catch (SystemException e1) {
        // handle exception
    }
   
} finally {
    // restore user security context
    authenticationComponent.setCurrentAuthentication(currentAuthentication);
}

ribz33
Champ on-the-rise
Champ on-the-rise
I did a class to execute workflow scripts as system user.
This can help you i think.

I contribute it to JIRA :
http://issues.alfresco.com/browse/AR-1911