Skip to content

Commit

Permalink
Merge pull request #493 from AnuradhaSK/handle-deletion
Browse files Browse the repository at this point in the history
Return 400 BadRequest for pre check validation failure of role deletion
  • Loading branch information
AnuradhaSK committed Oct 26, 2023
2 parents ce92add + e45fee9 commit 8913c1b
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
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;

/**
Expand Down Expand Up @@ -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(e.getErrorCode())) {
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
throw new CharonException(String.format("Error occurred while deleting the role: %s", roleID), e);
}
Expand Down Expand Up @@ -943,7 +946,8 @@ private void doUpdatePermissions(String roleId, Set<String> 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(
Expand Down

0 comments on commit 8913c1b

Please sign in to comment.