From 8bb898348f00c243c728667750c7dd698bd093e6 Mon Sep 17 00:00:00 2001 From: AnuradhaSK Date: Thu, 26 Oct 2023 00:48:32 +0530 Subject: [PATCH 1/3] handle 400 for deletion failure on associated apps --- .../scim2/common/impl/SCIMRoleManagerV2.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 38a052b9d..c21463226 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 @@ -74,12 +74,13 @@ import java.util.stream.Collectors; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; -import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_AUDIENCE; import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_PERMISSION; -import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_REQUEST; import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.OPERATION_FORBIDDEN; -import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_ALREADY_EXISTS; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_MANAGEMENT_ERROR_CODE_PREFIX; import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_NOT_FOUND; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_AUDIENCE; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_REQUEST; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_ALREADY_EXISTS; /** * Implementation of the {@link RoleV2Manager} interface to manage RoleResourceV2. @@ -277,6 +278,8 @@ public void deleteRole(String roleID) throws CharonException, NotFoundException, throw new NotFoundException(e.getMessage()); } else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) { throw new BadRequestException(e.getMessage()); + } else if (INVALID_REQUEST.getCode().equals(ROLE_MANAGEMENT_ERROR_CODE_PREFIX + e.getErrorCode())) { + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } throw new CharonException(String.format("Error occurred while deleting the role: %s", roleID), e); } @@ -943,7 +946,8 @@ private void doUpdatePermissions(String roleId, Set addedPermissions, Se } catch (IdentityRoleManagementException e) { if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) { throw new BadRequestException(e.getMessage()); - } else if (RoleConstants.Error.INVALID_PERMISSION.getCode().equals("RMA-" + e.getErrorCode())) { + } else if (RoleConstants.Error.INVALID_PERMISSION.getCode() + .equals(ROLE_MANAGEMENT_ERROR_CODE_PREFIX + e.getErrorCode())) { throw new BadRequestException(e.getMessage()); } throw new CharonException( From 2d913c6a78be78e6cfce20663c8fa3dc76075e20 Mon Sep 17 00:00:00 2001 From: AnuradhaSK Date: Thu, 26 Oct 2023 00:59:03 +0530 Subject: [PATCH 2/3] fix error code match --- .../carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c21463226..278105d33 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 @@ -278,7 +278,7 @@ public void deleteRole(String roleID) throws CharonException, NotFoundException, throw new NotFoundException(e.getMessage()); } else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) { throw new BadRequestException(e.getMessage()); - } else if (INVALID_REQUEST.getCode().equals(ROLE_MANAGEMENT_ERROR_CODE_PREFIX + e.getErrorCode())) { + } else if (INVALID_REQUEST.getCode().equals(e.getErrorCode())) { throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } throw new CharonException(String.format("Error occurred while deleting the role: %s", roleID), e); From e45fee9f54de7dfa4b47aeac3258748f4224aa44 Mon Sep 17 00:00:00 2001 From: AnuradhaSK Date: Thu, 26 Oct 2023 01:06:28 +0530 Subject: [PATCH 3/3] fix import order --- .../identity/scim2/common/impl/SCIMRoleManagerV2.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 278105d33..889359100 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 @@ -74,13 +74,13 @@ import java.util.stream.Collectors; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_AUDIENCE; import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_PERMISSION; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_REQUEST; import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.OPERATION_FORBIDDEN; +import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_ALREADY_EXISTS; import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_MANAGEMENT_ERROR_CODE_PREFIX; import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_NOT_FOUND; -import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_AUDIENCE; -import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_REQUEST; -import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_ALREADY_EXISTS; /** * Implementation of the {@link RoleV2Manager} interface to manage RoleResourceV2.