Skip to content

Commit

Permalink
Improve group provission with users
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Aug 27, 2024
1 parent 7c6a62b commit 8ba25a9
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/main/java/org/wso2/scim2/operation/GroupOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> response = api.updateGroup(null, null, encodedGroup);
Expand All @@ -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<String> 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<SCIMObject> 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;
}
}

0 comments on commit 8ba25a9

Please sign in to comment.