On 22/04/2013 21:40, Jesse van Bekkum wrote:
Hi

Quick question.

How can you provision a resource to a user from the workflow? I have a workflow, and after creating a user with a rest call, I want, depending on the path through the workflow, to automatically provision a resource.

I tried this in a workflow step:

        ResourceDAO resourceDAO = CONTEXT.getBean(ResourceDAO.class);
ExternalResource idp = resourceDAO.find("IDP_RESOURCE");
        SyncopeUser user = (SyncopeUser)
execution.getVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER);
user.addResource(idp);

But after creation the user had no resources. In the past (0.7) we have used manual propagation, by retrieving the propagation handler from the context and firing it, but that seems a bit inelegant to me.

What is the preferred solution to this (I think common) scenario?

Hi Jesse,
please take a look at the Update task [1]: you could change the doExecute() method there to match the logic expressed above

SyncopeUser user = (SyncopeUser) execution.getVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER); UserMod userMod = (UserMod) execution.getVariable(ActivitiUserWorkflowAdapter.USER_MOD);

// YOUR step, e.g. add resource
userMod.addResourceToBeAdded("IDP_RESOURCE");

        // update SyncopeUser
        PropagationByResource propByRes = dataBinder.update(user, userMod);

        // report updated user and propagation by resource as result
execution.setVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER, user);
execution.setVariable(ActivitiUserWorkflowAdapter.PROP_BY_RESOURCE, propByRes);

Please note the final statements execution.setVariable() - without these the changes are not propagated back to the flow.

Regards.

[1] https://svn.apache.org/repos/asf/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/workflow/user/activiti/task/Update.java

--
Francesco Chicchiriccò

ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/

Reply via email to