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

Casting patchOperation.getValues() to JSONObject causing class cast exception #314

Open
R-Zer0 opened this issue Apr 23, 2021 · 2 comments

Comments

@R-Zer0
Copy link

R-Zer0 commented Apr 23, 2021

For the following patch operation I get operation value type as JSONArray.

{
      "op": "add",
      "path": "members",
      "value": [{
        "value": "23a35c27-23d3-4c03-b4c5-6443c09e7173",
        "display": "test.user@okta.local"
}

As result I get exception:

Caused by: java.lang.ClassCastException: org.json.JSONArray cannot be cast to org.json.JSONObject
at org.wso2.charon3.core.protocol.endpoints.GroupResourceManager.isDeleteAllUsersOperationFound(GroupResourceManager.java:698)
at org.wso2.charon3.core.protocol.endpoints.GroupResourceManager.updateWithPATCH(GroupResourceManager.java:653)

@R-Zer0
Copy link
Author

R-Zer0 commented Apr 23, 2021

I think it can be replaced with :

if (patchOperation.getValues() instanceof JSONObject) {

@cb-manideep
Copy link

@R-Zer0 I'm having the same issue. But I don't think that just checking would resolve the issue

if (patchOperation.getValues() instanceof JSONObject) {

I think it should be something like this:

private boolean isDeleteAllUsersOperationFound(List<PatchOperation> patchOperations) throws JSONException {

        for (PatchOperation patchOperation : patchOperations) {
            String operation = patchOperation.getOperation();
            String path = patchOperation.getPath();
            if (!(patchOperation.getValues() instanceof String)) {
                if (operation.equals(SCIMConstants.OperationalConstants.REPLACE)) {
                    if (path != null && path.equals(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
                        return true;
                    } else if (patchOperation.getValues() instanceof JSONObject) {
                        JSONObject valuesJson = (JSONObject) patchOperation.getValues();
                        if (valuesJson.has(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
                            return true;
                        }
                    }
                } else if (operation.equals(SCIMConstants.OperationalConstants.REMOVE) && path != null
                        && path.equals(SCIMConstants.GroupSchemaConstants.MEMBERS)) {
                    return true;
                }
            }
        }
        return false;
    }

Please let me know if this makes sense, I can raise a PR for this.

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

No branches or pull requests

2 participants