diff --git a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManager.java b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManager.java index 5b792e3f..889fbb6a 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManager.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManager.java @@ -771,21 +771,30 @@ private void updatePermissions(String roleId, List permissionOpe private void prepareAddedRemovedGroupLists(Set addedGroupsIds, Set removedGroupsIds, Set replacedGroupsIds, PatchOperation groupOperation, - Map groupObject, List groupListOfRole) { + Map groupObject, List groupListOfRole) + throws BadRequestException { + + String value = groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE); + + if (StringUtils.isBlank(value)) { + throw new BadRequestException( + "Updating groups of the role by display name is not supported. Update using group id instead.", + ResponseCodeConstants.INVALID_SYNTAX); + } switch (groupOperation.getOperation()) { case (SCIMConstants.OperationalConstants.ADD): - removedGroupsIds.remove(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); - if (!isGroupExist(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE), groupListOfRole)) { - addedGroupsIds.add(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); + removedGroupsIds.remove(value); + if (!isGroupExist(value, groupListOfRole)) { + addedGroupsIds.add(value); } break; case (SCIMConstants.OperationalConstants.REMOVE): - addedGroupsIds.remove(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); - removedGroupsIds.add(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); + addedGroupsIds.remove(value); + removedGroupsIds.add(value); break; case (SCIMConstants.OperationalConstants.REPLACE): - replacedGroupsIds.add(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); + replacedGroupsIds.add(value); break; } } diff --git a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java index 63cfab4b..d1905551 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java @@ -1125,7 +1125,7 @@ private void doUpdateGroups(String roleId, Set newGroupIDList, Set(deleteGroupIDList), tenantDomain); } catch (IdentityRoleManagementException e) { if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(); } throw new CharonException( String.format("Error occurred while updating groups in the role with ID: %s", roleId), e); @@ -1214,19 +1214,27 @@ private List getUserIDList(List userList, String tenantDomain) t private void prepareInitialGroupLists(Set givenAddedGroupsIds, Set givenRemovedGroupsIds, Set givenReplacedGroupsIds, PatchOperation groupOperation, - Map groupObject) { + Map groupObject) throws BadRequestException { + + String value = groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE); + + if (StringUtils.isBlank(value)) { + throw new BadRequestException( + "Updating groups of the role by display name is not supported. Update using group id instead.", + ResponseCodeConstants.INVALID_SYNTAX); + } switch (groupOperation.getOperation()) { case (SCIMConstants.OperationalConstants.ADD): - givenRemovedGroupsIds.remove(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); - givenAddedGroupsIds.add(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); + givenRemovedGroupsIds.remove(value); + givenAddedGroupsIds.add(value); break; case (SCIMConstants.OperationalConstants.REMOVE): - givenAddedGroupsIds.remove(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); - givenRemovedGroupsIds.add(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); + givenAddedGroupsIds.remove(value); + givenRemovedGroupsIds.add(value); break; case (SCIMConstants.OperationalConstants.REPLACE): - givenReplacedGroupsIds.add(groupObject.get(SCIMConstants.CommonSchemaConstants.VALUE)); + givenReplacedGroupsIds.add(value); break; default: break;