[NUXEO IDE] impossible to change user's group without restarting the server

Hello,

I would like to add a user to a nuxeo group with an automation operation write in IDE.

I try to do that with :

    String groupName="group";
    String user="userlogin";
    NuxeoGroup group = usermanager.getGroup(groupName);
    NuxeoPrincipal up=usermanager.getPrincipal(user); 
    List<String> userGroups = up.getGroups();
    userGroups.add(group.getName());
    up.setGroups(userGroups);
    //this part don't works
    usermanager.updatePrincipal(up);

    //same problem don't update
    DocumentModel userModel = userManager.getUserModel(user);
    userModel.setProperty("user", "groups", userGroups);
    userManager.updateUser(userModel);

    //this part works
    group.getMemberUsers().add(user);
    usermanager.updateGroup(group);

The group's user are Ok, but the user's group information is not set while I don't restart the server.

Why ? Why group is instantally set and user not?

What can I do to make this work ?

thanks

ps: try also code nuxeo code example and it failed.

ps2 : my user is a ldap user

0 votes

0 answers

975 views

ANSWER

Hi,

My 2 cents: org.nuxeo.ecm.restapi.server.jaxrs.usermanager.UserToGroupObject is showing an example to add a user to a group:

UserManager um = Framework.getLocalService(UserManager.class); principal.setGroups(groups); um.updateUser(principal.getModel());

Hope it helps

01/19/2015

Hello Vladimir, Thank you very much for this other solution. I decided to set LDAP cache to "no cache" because my user is a LDAP user, and with that it works. Maybe my problem is more a ldap problem. Or precisely a nuxeo-group-with-ldap problem. So with no cache the user ldap know is local-nuxeo-group. take care
01/19/2015