From 78a8572c42fd81c6807f7aed891d05f2e5db01fd Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Fri, 28 Jun 2024 21:23:56 +0530 Subject: [PATCH 1/2] Fix the null pointer for operation json list. --- .../wso2/charon3/core/encoder/JSONDecoder.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java index 0b790254..7ace1c51 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java @@ -746,13 +746,26 @@ private ComplexAttribute buildComplexValue(AttributeSchema attributeSchema, */ public ArrayList decodeRequest(String scimResourceString) throws BadRequestException { - ArrayList operationList = new ArrayList(); try { //decode the string into json representation JSONObject decodedJsonObj = new JSONObject(new JSONTokener(scimResourceString)); //obtain the Operations values JSONArray operationJsonList = (JSONArray) decodedJsonObj.opt(SCIMConstants.OperationalConstants.OPERATIONS); + + //check if operationJsonList is null + if (operationJsonList == null) { + + //throw appropriate exception based on the key check + if (decodedJsonObj.has(StringUtils.lowerCase(SCIMConstants.OperationalConstants.OPERATIONS))) { + throw new BadRequestException("Invalid JSON schema.", ResponseCodeConstants.INVALID_SYNTAX); + } + + //if the key with lowercase name does not exist, throw this exception + throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX); + } + + //for each operation, create a PatchOperation object and add the relevant values to it for (int count = 0; count < operationJsonList.length(); count++) { JSONObject operation = (JSONObject) operationJsonList.get(count); From be0c9f73fa2541c69d1f959367f18b011edb747c Mon Sep 17 00:00:00 2001 From: Malith-19 Date: Fri, 28 Jun 2024 22:05:22 +0530 Subject: [PATCH 2/2] Update the comments. --- .../main/java/org/wso2/charon3/core/encoder/JSONDecoder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java index 7ace1c51..cd1cbb6f 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java @@ -756,12 +756,11 @@ public ArrayList decodeRequest(String scimResourceString) throws //check if operationJsonList is null if (operationJsonList == null) { - //throw appropriate exception based on the key check + //check if operations field present in lowercase if (decodedJsonObj.has(StringUtils.lowerCase(SCIMConstants.OperationalConstants.OPERATIONS))) { throw new BadRequestException("Invalid JSON schema.", ResponseCodeConstants.INVALID_SYNTAX); } - //if the key with lowercase name does not exist, throw this exception throw new BadRequestException(ResponseCodeConstants.INVALID_SYNTAX); }