You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@syncope.apache.org by te...@net-c.com on 2020/10/23 09:25:19 UTC

How to remove a group from a user using the Java API

Hi all,

I try to implement in the user lifecycle a check about its groups between state 'create' and 'activate'.

In the Flowable process definition, I added a service task implemented as a Java Delegate class as following ("currentProfile" is one of the user groups set on creation).

After the execution of this service task, all groups seems to be always associated to the user. 



Can you help me ? Am I using a wrong API ?

Thanks for your help !

Christophe



@Component
public class RemoveProfile extends FlowableServiceTask {

    @Autowired
    private UserDataBinder dataBinder;

    @Override
    protected void doExecute(final DelegateExecution execution) {
        
        MembershipTO currentProfile = execution.getVariable("currentProfile", MembershipTO.class);
        System.out.println("Profile courant à retirer: " + currentProfile);

        User user = execution.getVariable(FlowableRuntimeUtils.USER, User.class);
        
        UserPatch userPatch = new UserPatch();
        MembershipPatch membershipPatch = new MembershipPatch();
        membershipPatch.setGroup(currentProfile.getGroupName());
        membershipPatch.setOperation(PatchOperation.DELETE);
        userPatch.getMemberships().add(membershipPatch);
        
        dataBinder.update(user, userPatch);

    }
}



Re: How to remove a group from a user using the Java API

Posted by te...@net-c.com.
Any idea ??


Did I do something wrong there ?


De : tempo@net-c.com
À : user@syncope.apache.org
Sujet : How to remove a group from a user using the Java API
Date : 23/10/2020 11:25:19 Europe/Paris

Hi all,

I try to implement in the user lifecycle a check about its groups between state 'create' and 'activate'.

In the Flowable process definition, I added a service task implemented as a Java Delegate class as following ("currentProfile" is one of the user groups set on creation).

After the execution of this service task, all groups seems to be always associated to the user. 



Can you help me ? Am I using a wrong API ?

Thanks for your help !

Christophe



@Component
public class RemoveProfile extends FlowableServiceTask {

    @Autowired
    private UserDataBinder dataBinder;

    @Override
    protected void doExecute(final DelegateExecution execution) {
        
        MembershipTO currentProfile = execution.getVariable("currentProfile", MembershipTO.class);
        System.out.println("Profile courant à retirer: " + currentProfile);

        User user = execution.getVariable(FlowableRuntimeUtils.USER, User.class);
        
        UserPatch userPatch = new UserPatch();
        MembershipPatch membershipPatch = new MembershipPatch();
        membershipPatch.setGroup(currentProfile.getGroupName());
        membershipPatch.setOperation(PatchOperation.DELETE);
        userPatch.getMemberships().add(membershipPatch);
        
        dataBinder.update(user, userPatch);

    }
}