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 5b792e3f1..8a9f0a9e3 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 @@ -127,7 +127,7 @@ public Role createRole(Role role) throws CharonException, ConflictException, Bad if (StringUtils.equals(ROLE_ALREADY_EXISTS.getCode(), e.getErrorCode())) { throw new ConflictException(e.getMessage()); } else if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } throw new CharonException( String.format("Error occurred while adding a new role: %s", role.getDisplayName()), e); @@ -500,7 +500,7 @@ private void doUpdatePermissions(Role oldRole, Role newRole) throws BadRequestEx roleManagementService.setPermissionsForRole(oldRole.getId(), newRolePermissions, tenantDomain); } catch (IdentityRoleManagementException e) { if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) { throw new BadRequestException(e.getMessage()); } @@ -709,7 +709,7 @@ private void doUpdateUsers(Set newUserList, Set deletedUserList, new ArrayList<>(deletedUserIDList), tenantDomain); } catch (IdentityRoleManagementException e) { if (INVALID_REQUEST.getCode().equals(e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } if (OPERATION_FORBIDDEN.getCode().equals(e.getErrorCode())) { throw new ForbiddenException(e.getMessage()); @@ -761,7 +761,7 @@ private void updatePermissions(String roleId, List permissionOpe roleManagementService.setPermissionsForRole(roleId, newRolePermissions, tenantDomain); } catch (IdentityRoleManagementException e) { if (INVALID_REQUEST.getCode().equals(e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } throw new CharonException( String.format("Error occurred while updating permissions for role: %s", roleId), e); @@ -814,7 +814,8 @@ private void prepareAddedRemovedUserLists(Set addedMembers, Set } if (memberObject.get(SCIMConstants.RoleSchemaConstants.DISPLAY) == null) { - throw new BadRequestException("User can't be resolved from the given user Id."); + throw new BadRequestException("User can't be resolved from the given user Id.", + ResponseCodeConstants.INVALID_VALUE); } List roleList = Arrays.asList(userStoreManager. @@ -867,7 +868,7 @@ private void doUpdateGroups(String roleId, Set newGroupIDList, Set(deleteGroupIDList), tenantDomain); } catch (IdentityRoleManagementException e) { if (INVALID_REQUEST.getCode().equals(e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } throw new CharonException( String.format("Error occurred while updating groups in the role: %s", roleId), e); 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 2d3a04aa2..9c76a9ddc 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 @@ -178,7 +178,7 @@ public RoleV2 createRole(RoleV2 role) if (StringUtils.equals(ROLE_ALREADY_EXISTS.getCode(), e.getErrorCode())) { throw new ConflictException(e.getMessage()); } else if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } else if (INVALID_AUDIENCE.getCode().equals(e.getErrorCode()) || INVALID_PERMISSION.getCode().equals(e.getErrorCode())) { throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); @@ -836,7 +836,7 @@ private void doUpdatePermissions(RoleV2 oldRole, RoleV2 newRole) throws BadReque tenantDomain); } catch (IdentityRoleManagementException e) { if (StringUtils.equals(RoleConstants.Error.INVALID_REQUEST.getCode(), e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } else if (RoleConstants.Error.INVALID_PERMISSION.getCode().equals(e.getErrorCode())) { throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) { @@ -1102,7 +1102,7 @@ private void doUpdatePermissions(String roleId, Set addedPermissions, Se tenantDomain); } catch (IdentityRoleManagementException e) { if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } else if (RoleConstants.Error.INVALID_PERMISSION.getCode().equals(e.getErrorCode())) { throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } @@ -1122,7 +1122,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(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } throw new CharonException( String.format("Error occurred while updating groups in the role with ID: %s", roleId), e); @@ -1139,7 +1139,7 @@ private void doUpdateIdPGroups(String roleId, List newGroupIDList, Lis roleManagementService.updateIdpGroupListOfRole(roleId, newGroupIDList, deleteGroupIDList, tenantDomain); } catch (IdentityRoleManagementException e) { if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } throw new CharonException( String.format("Error occurred while updating groups in the role with ID: %s", roleId), e); @@ -1164,7 +1164,7 @@ private void doUpdateUsers(Set newUserList, Set deletedUserList, new ArrayList<>(deletedUserIDList), tenantDomain); } catch (IdentityRoleManagementException e) { if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } else if (OPERATION_FORBIDDEN.getCode().equals(e.getErrorCode())) { throw new ForbiddenException(e.getMessage()); } @@ -1292,7 +1292,8 @@ private void prepareAddedRemovedUserLists(Set addedMembers, Set } if (memberObject.get(SCIMConstants.RoleSchemaConstants.DISPLAY) == null) { - throw new BadRequestException("User can't be resolved from the given user Id."); + throw new BadRequestException("User can't be resolved from the given user Id.", + ResponseCodeConstants.INVALID_VALUE); } List roleList; diff --git a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java index ebff95c5a..f9edc8c0b 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java @@ -297,7 +297,7 @@ public User createUser(User user, Map requiredAttributes) } else { throw new BadRequestException( "The claim value for " + primaryLoginIdentifier + " " + - "and username should be same."); + "and username should be same.", ResponseCodeConstants.INVALID_VALUE); } } else { claimsInLocalDialect.put(getPrimaryLoginIdentifierClaim(), @@ -1582,7 +1582,8 @@ private String resolveDomainNameInAttributeValue(String domainName, ExpressionNo .equalsIgnoreCase(domainName)) { throw new BadRequestException(String.format( " Domain name %s in the domain parameter does not match with the domain name %s in search " - + "attribute value of %s claim.", domainName, extractedDomain, attributeName)); + + "attribute value of %s claim.", domainName, extractedDomain, attributeName), + ResponseCodeConstants.INVALID_VALUE); } if (StringUtils.isEmpty(domainName) && StringUtils.isNotEmpty(extractedDomain)) { if (log.isDebugEnabled()) @@ -2377,7 +2378,7 @@ private void checkForPaginationSupport(Condition condition) throws UserStoreExce if (hasBothIdentityClaimAndDefaultClaims && !paginationEnabled) { String errorMessage = "Pagination support is not enabled for multi attribute filtering with both identity claims and default claims"; - throw new BadRequestException(errorMessage); + throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE); } } @@ -3871,7 +3872,7 @@ private boolean isSCIMEnabled(String userStoreName) throws BadRequestException { UserStoreManager userStoreManager = carbonUM.getSecondaryUserStoreManager(userStoreName); if (userStoreManager == null) { - throw new BadRequestException("Invalid user store name."); + throw new BadRequestException("Invalid user store name.", ResponseCodeConstants.INVALID_VALUE); }else { try { return userStoreManager.isSCIMEnabled(); @@ -4362,7 +4363,7 @@ private void appendDomainToMembers(Group group, String userStoreDomain) throws C SCIMConstants.CommonSchemaConstants.DISPLAY); if (displayNameAttribute == null) { throw new BadRequestException("Display name attribute of a member is empty while adding to " + - "the group: " + group.getDisplayName()); + "the group: " + group.getDisplayName(), ResponseCodeConstants.INVALID_VALUE); } String displayName = AttributeUtil.getStringValueOfAttribute(displayNameAttribute.getValue(), @@ -5973,7 +5974,7 @@ private void validateExtractedDomain(String domainName, String attributeName, St throw new BadRequestException(String.format( " Domain name: %s in the domain parameter does not match with the domain name: %s in " + "search attribute value of %s claim.", domainName, extractedDomain, - attributeName)); + attributeName), ResponseCodeConstants.INVALID_VALUE); } // Check whether the domain name is an actually existing domain name. @@ -6000,7 +6001,7 @@ private void validateExtractedDomain(String domainName, String attributeName, St } if (((UserStoreManager) userStoreManager).getSecondaryUserStoreManager(extractedDomain) == null) { throw new BadRequestException("The provided domain name: " + extractedDomain + ", must be a valid " + - "user-store domain"); + "user-store domain", ResponseCodeConstants.INVALID_VALUE); } } catch (UserStoreException e) { throw resolveError(e, "Unable to retrieve user realm for the tenant domain: " + tenantDomain);