Skip to content

Commit

Permalink
Fix same name v2 role user update
Browse files Browse the repository at this point in the history
  • Loading branch information
shashimalcse committed Nov 14, 2023
1 parent d389651 commit 1a70c7c
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public RoleV2 patchRole(String roleId, Map<String, List<PatchOperation>> patchOp
updateGroups(roleId, groupOperations);
}
if (CollectionUtils.isNotEmpty(memberOperations)) {
updateUsers(roleId, currentRoleName, memberOperations);
updateUsers(roleId, memberOperations);
}

HashMap<String, Boolean> requiredAttributes = new HashMap<>();
Expand Down Expand Up @@ -902,7 +902,7 @@ private void updateGroups(String roleId, List<PatchOperation> groupOperations)
}
}

private void updateUsers(String roleId, String currentRoleName, List<PatchOperation> memberOperations)
private void updateUsers(String roleId, List<PatchOperation> memberOperations)
throws BadRequestException, CharonException, ForbiddenException {

Collections.sort(memberOperations);
Expand All @@ -914,13 +914,13 @@ private void updateUsers(String roleId, String currentRoleName, List<PatchOperat
if (memberOperation.getValues() instanceof Map) {
Map<String, String> memberObject = (Map<String, String>) memberOperation.getValues();
prepareAddedRemovedUserLists(addedUsers, deletedUsers, newlyAddedUsersIds,
memberOperation, memberObject, currentRoleName);
memberOperation, memberObject, roleId);
} else if (memberOperation.getValues() instanceof List) {
List<Map<String, String>> memberOperationValues =
(List<Map<String, String>>) memberOperation.getValues();
for (Map<String, String> memberObject : memberOperationValues) {
prepareAddedRemovedUserLists(addedUsers, deletedUsers, newlyAddedUsersIds,
memberOperation, memberObject, currentRoleName);
memberOperation, memberObject, roleId);
}
}
}
Expand Down Expand Up @@ -1059,7 +1059,7 @@ private void prepareAddedRemovedGroupLists(Set<String> addedGroupsIds, Set<Strin

private void prepareAddedRemovedUserLists(Set<String> addedMembers, Set<String> removedMembers,
Set<Object> newlyAddedMemberIds, PatchOperation memberOperation,
Map<String, String> memberObject, String currentRoleName)
Map<String, String> memberObject, String roleId)
throws BadRequestException, CharonException {

try {
Expand All @@ -1085,11 +1085,16 @@ private void prepareAddedRemovedUserLists(Set<String> addedMembers, Set<String>
throw new BadRequestException("User can't be resolved from the given user Id.");
}

List<String> roleList = Arrays.asList(userStoreManager.
getRoleListOfUser(memberObject.get(SCIMConstants.RoleSchemaConstants.DISPLAY)));
List<String> roleList;
try {
roleList = roleManagementService.getRoleIdListOfUser(
memberObject.get(SCIMConstants.RoleSchemaConstants.VALUE), tenantDomain);
} catch (IdentityRoleManagementException e) {
throw new CharonException("Error occurred while retrieving the role list of user.");
}

if (SCIMConstants.OperationalConstants.ADD.equals(memberOperation.getOperation()) &&
!roleList.contains(currentRoleName)) {
!roleList.contains(roleId)) {
removedMembers.remove(memberObject.get(SCIMConstants.RoleSchemaConstants.DISPLAY));
addedMembers.add(memberObject.get(SCIMConstants.RoleSchemaConstants.DISPLAY));
newlyAddedMemberIds.add(memberObject.get(SCIMConstants.CommonSchemaConstants.VALUE));
Expand Down

0 comments on commit 1a70c7c

Please sign in to comment.