diff --git a/src/main/java/org/wso2/scim2/operation/GroupOperations.java b/src/main/java/org/wso2/scim2/operation/GroupOperations.java index 8aaa17e..64d6af8 100644 --- a/src/main/java/org/wso2/scim2/operation/GroupOperations.java +++ b/src/main/java/org/wso2/scim2/operation/GroupOperations.java @@ -150,7 +150,15 @@ public void updateGroup() throws IdentitySCIMException { if (groupId == null) { return; } - String encodedGroup = scimClient.encodeSCIMObject((AbstractSCIMObject) scimObject, SCIMConstants.JSON); + + // get corresponding userIds + Group updatedGroup = setUserIdForMembers(); + String encodedGroup; + if (updatedGroup != null) { + encodedGroup = scimClient.encodeSCIMObject(updatedGroup, SCIMConstants.JSON); + } else { + encodedGroup = scimClient.encodeSCIMObject((AbstractSCIMObject) scimObject, SCIMConstants.JSON); + } client.setURL(groupEPURL + "/" + groupId); Scimv2GroupsApi api = new Scimv2GroupsApi(client); ScimApiResponse response = api.updateGroup(null, null, encodedGroup); @@ -176,4 +184,27 @@ public void updateGroup() throws IdentitySCIMException { throw new IdentitySCIMException("Error in provisioning 'update group' operation for user : " + userName, e); } } + + private Group setUserIdForMembers() throws AbstractCharonException, ScimApiException, IOException { + + List users = ((Group) scimObject).getMembersWithDisplayName(); + if (CollectionUtils.isEmpty(users)) { + return null; + } + //create a deep copy of the group since we are going to update the member ids + Group copiedGroup = (Group) CopyUtil.deepCopy(scimObject); + //delete existing members in the group since we are going to update it with + copiedGroup.deleteAttribute(SCIMConstants.GroupSchemaConstants.MEMBERS); + + for (String user : users) { + List filteredUsers = listWithGet(null, null, USER_FILTER + user, 1, 1, null, null, + SCIM2CommonConstants.USER); + String userId = null; + for (SCIMObject filteredUser : filteredUsers) { + userId = ((User) filteredUser).getId(); + } + copiedGroup.setMember(userId, user); + } + return copiedGroup; + } }