This example shows how to add a user to a group.
The user, group, and role are already defined, and each one is specified by ID. Note that it is not possible to add a user without a role.
final IdentityAPI identityAPI = new IdentityAccessor().getIdentityAPI(apiSession);
UserMembership membership = identityAPI.addUserMembership(userId, groupId, roleId);
UserMembership membership = identityAPI.addUserMembership(userId, groupId, roleId);