Hi Francesco,

In my case, I am just updating a user object, not creating a new one.

So, I modify the memberships as in the example. This time, the right roleID's are set in the object.

Anyway, I am having a 500 http error. I cannot see details in the logs of why my request have failed.

To resume:

- retrieve UserTO.

- clear memberships object.

- set a new memberships object with member's having only RoleID.

- put request of UserTO.

Thanks and sorry for the noise.

Regards,

German.


On 04/06/2013 15:34, German Parente wrote:
Hi guys,

I am trying to develop java functions to assign/unassign roles to user.

I am using objects like UserTO and MembershipTO.

When setting the Memberships of a UserTo object, I am only setting the role name, like this.


            UserTO idmUser = new UserTO();
            r = getIDMUser(userName, userPassword, idmUser);

            MembershipTO member = new MembershipTO();
            member.setRoleName(roletoassign.getName());
            memberships.add(member);

then,

          idmUser.setMemberships(memberships);

because in my own application, I am only using roleName as role object.

And of course, at doing a "put" client request, I am failing probably because I have not set the whole member object.

member.setId()
member.setRoleID();
member.setResources()

Do I need to set all this information to assign a role to a resource ?

So, should I do a get of each RoleTO object and extract the information to set into the membership ?

I am having a 500 http error but I cannot find in the logs what has been wrong.

Any idea about this ?

Hi,
you need to provide the role id (which is unique) not the role name (which is unique only among children of a given role); so for example

UserTO userTO = getUniqueSampleTO("a...@c.com");

        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(8L);
        userTO.addMembership(membershipTO);

is working: please take a look at test class [1] for more examples.

HTH
Regards.

[1] https://svn.apache.org/repos/asf/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java


Reply via email to