On 06/04/2013 05:00 PM, Francesco Chicchiriccò wrote:
On 04/06/2013 16:54, German Parente wrote:

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.

Since you are performing an user update request, you must use *Mod objects (e.g. UserMod, MembershipMod, ...)- [1] has good examples for this as well; for example:

        UserTO userTO = ...; // you have this

        MembershipMod membershipMod = new MembershipMod();
        membershipMod.setRole(8L);

        UserMod userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.addMembershipToBeAdded(membershipMod);

Regards.

I understand, thanks, but I have been adviced to use rest calls instead of java api. I am including only *TO objects in my code.

Further, I had a problem including the syncope-common jar in my projects since I am using Jersey and syncope-common has some annotations which were in conflict with mines.

Is there any way to see in the logs why the request is failing ?

I am sure I am nearly there.

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("[email protected]");

        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