No, I was just reading the requirements. I will get to it, but I will also need permission from Everett. The complete procedure will probably take a while I see.
Jesse On Tue, Apr 30, 2013 at 10:15 AM, Francesco Chicchiriccò < ilgro...@apache.org> wrote: > On 30/04/2013 10:09, Jesse van Bekkum wrote: > > Hi Francisco > > Sounds like a fine idea. My username is Jesse van Bekkum. You can give > me write access. > > > We have to wait for your ICLA to be received and notified: have you > already sent it? > > Regards. > > > On Tue, Apr 30, 2013 at 8:52 AM, Francesco Chicchiriccò < > ilgro...@apache.org> wrote: > >> On 29/04/2013 15:42, Jesse van Bekkum wrote: >> >> Hi Francesco >> >> Thanks for your help. There was one small issue with your example, >> since on user creation you do not have a usermod on the execution yet. But >> that was easily fixed. >> >> I have used the following code and rule in my workflow to get this >> working. Might I suggest that we use this in the standard deployment of >> Syncope? I think that provisioning via the workflow is functionality that >> should be included out of the box. The version I made is parameterized via >> the workflow (description of usage is included) so it is not specific to my >> project. >> >> >> Jesse, >> this sounds like a nice extension: why don't you report it in a wiki page >> under [2]? >> >> You need to: >> 1. complete and submit an ICLA [3] >> 2. create a wiki user (if not already done) and tell me the username so >> that I can grant you write access to the wiki >> >> WDYT? >> >> Regards. >> >> >> import org.activiti.engine.delegate.DelegateExecution; >> import org.activiti.engine.delegate.Expression; >> import org.apache.syncope.client.mod.UserMod; >> import org.apache.syncope.core.persistence.beans.user.SyncopeUser; >> import org.apache.syncope.core.propagation.PropagationByResource; >> import org.apache.syncope.core.workflow.ActivitiUserWorkflowAdapter; >> import org.apache.syncope.core.workflow.WorkflowException; >> import org.apache.syncope.core.workflow.activiti.AbstractActivitiDelegate; >> import org.slf4j.Logger; >> import org.slf4j.LoggerFactory; >> >> /** >> * This workflow service task allows to provision a resource to a user >> from the workflow. >> * >> * Use the following code in the workflow: >> * >> * <serviceTask id="addResource" name="Add Resource" >> >> activiti:class="org.apache.syncope.core.workflow.activiti.ProvisionResources"> >> <extensionElements> >> <activiti:field name="resource" >> stringValue="%%YOUR_RESOURCE%%"/> >> </extensionElements> >> </serviceTask> >> */ >> public class ProvisionResources extends AbstractActivitiDelegate { >> >> protected static final Logger LOG = >> LoggerFactory.getLogger(ProvisionResources.class); >> >> private Expression resource; >> >> public void setResource(Expression resource) { >> this.resource = resource; >> } >> >> @Override >> protected void doExecute(DelegateExecution execution) throws >> Exception { >> String resourceName = (String) resource.getValue(execution); >> >> if (resourceName == null || resourceName.isEmpty()) { >> throw new WorkflowException(new IllegalStateException("Please >> specify a resource")); >> } >> >> SyncopeUser user = (SyncopeUser) >> execution.getVariable(ActivitiUserWorkflowAdapter.SYNCOPE_USER); >> UserMod userMod = (UserMod) >> execution.getVariable(ActivitiUserWorkflowAdapter.USER_MOD); >> if (userMod == null) { >> userMod = new UserMod(); >> } >> >> userMod.addResourceToBeAdded(resourceName); >> >> // 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); >> >> } >> } >> >> >> On Tue, Apr 23, 2013 at 10:38 AM, Francesco Chicchiriccò < >> ilgro...@apache.org> wrote: >> >>> 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 >>> >> [2] >> https://cwiki.apache.org/confluence/display/SYNCOPE/Extending+Syncope >> [3] http://www.apache.org/dev/new-committers-guide.html#cla >> > -- > Francesco Chicchiriccò > > ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC > Memberhttp://people.apache.org/~ilgrosso/ > >