Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Getting 500 error response for client errors in SCIM/Groups PATCH #478

Merged

Conversation

PasinduYeshan
Copy link
Contributor

Purpose

This PR aims to address the issues mentioned in wso2/product-is#16097.

Goals

The goals of this PR are to:

  • Change the error responses when adding a member to a group with invalid display name.
  • Change the error responses when adding a member to a group with invalid id.
  • Change the error responses when a user is added with mismatching id and display name.
  • Change the error response when removing a non-existent user from a group
  • Fix the issue of receiving a 400 error when attempting to remove and add a user scenario by using the user ID. However, this was working with the user display name.

@PasinduYeshan PasinduYeshan changed the title Fix Getting 500 error response for client errors in SCIM/Groups PATCH #387 Fix Getting 500 error response for client errors in SCIM/Groups PATCH Jul 31, 2023
@@ -3366,6 +3367,11 @@ private void doPatchGroup(String groupId, String currentGroupName, Map<String, L
temporaryMembers.clear();

for (String member : deletedMembers) {
if (addedMembers.isEmpty() && (member == null || member.isEmpty())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's refactor this.

eg:

for (String member : deletedMembers) {
    if (addedMembers.isEmpty() && StringUtils.isBlank(member)) {
        throw new BadRequestException(ResponseCodeConstants.INVALID_VALUE);
    } 

    if (StringUtils.isNotBlank(member)) {
        String username = UserCoreUtil.addDomainToName(UserCoreUtil.removeDomainFromName(member), userStoreDomainForGroup);
        temporaryMembers.add(username);
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored in this fedd887

@PasinduYeshan PasinduYeshan marked this pull request as ready for review August 3, 2023 06:39
@@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
java-version: [ 11, 17 ]
java-version: [ 11.0.19+7 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for removing java version 17?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include jdk-17.0.7+7 as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in bea2a6a

if (e instanceof org.wso2.carbon.user.core.UserStoreException && StringUtils
.equals(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_NON_EXISTING_USER.getCode(),
((org.wso2.carbon.user.core.UserStoreException) e).getErrorCode())) {
throw new BadRequestException(ResponseCodeConstants.INVALID_VALUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why aren't we passing the throwable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public class BadRequestException extends AbstractCharonException {
    public BadRequestException() {
        this("invalid request");
    }

    public BadRequestException(String scimType) {
        this("Request is unparsable, syntactically incorrect, or violates schema.", scimType);
    }

    public BadRequestException(String details, String scimType) {
        super(400, details, scimType);
    }
}

This is the implementation of BadRequestException. There's no way to pass the throwable to the BadRequestException.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a log with the throwable as suggested offline.

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/5806539649

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/5806539649
Status: failure

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/5808197251

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/5808197251
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/5808197251

@Kanapriya Kanapriya merged commit 39ce7d2 into wso2-extensions:master Aug 10, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants