From 1997ed786fcc19673444ce48b09c6873ae89c47a Mon Sep 17 00:00:00 2001 From: Nils Sperling Date: Mon, 17 Oct 2022 13:53:51 +0200 Subject: [PATCH 1/3] PCS-2420: decode incoming requests independent of case of attribute names like userName --- .../org/wso2/charon3/core/encoder/JSONDecoder.java | 14 ++++++++++---- .../protocol/endpoints/MeResourceManagerTest.java | 2 +- 2 files changed, 11 insertions(+), 5 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 118dbbcbd..5c918ca65 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 @@ -51,10 +51,7 @@ import org.wso2.charon3.core.utils.codeutils.SearchRequest; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.wso2.charon3.core.schema.SCIMDefinitions.DataType.BINARY; import static org.wso2.charon3.core.schema.SCIMDefinitions.DataType.BOOLEAN; @@ -306,6 +303,15 @@ public T decodeResource(String scimResourceString //user may define the attribute by its fully qualified uri attributeValObj = decodedJsonObj.opt(attributeSchema.getURI()); } + if (attributeValObj == null) { + String attributeSchemaName = attributeSchema.getName().toLowerCase(); + for (Iterator it = decodedJsonObj.keys(); it.hasNext(); ) { + String key = (String) it.next(); + if (key.toLowerCase().equals(attributeSchemaName)) { + attributeValObj = decodedJsonObj.get(key); + } + } + } SCIMDefinitions.DataType attributeSchemaDataType = attributeSchema.getType(); if (attributeSchemaDataType.equals(STRING) || attributeSchemaDataType.equals(BINARY) || diff --git a/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java b/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java index c11606783..962d65774 100644 --- a/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java +++ b/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java @@ -1247,7 +1247,7 @@ public void testGetUserName(Object objectUser, String scimObjectString) public Object[][] dataToTestGetUsernameErrorInGettingTheUsernameFromTheAnonymousRequest() { String scimObjectString = "{\n" + - "UserName: John,\n" + + "UsrName: John,\n" + "}"; return new Object[][]{ {scimObjectString} From 58677aabc9e4aafefbb7dbfe20952f1457a3c1c5 Mon Sep 17 00:00:00 2001 From: Nils Sperling Date: Mon, 17 Oct 2022 15:08:52 +0200 Subject: [PATCH 2/3] PCS-2420: use equalsIgnoreCase() and InvalidUserName --- .../main/java/org/wso2/charon3/core/encoder/JSONDecoder.java | 3 +-- .../charon3/core/protocol/endpoints/MeResourceManagerTest.java | 2 +- 2 files changed, 2 insertions(+), 3 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 5c918ca65..8fbb9deb8 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 @@ -304,10 +304,9 @@ public T decodeResource(String scimResourceString attributeValObj = decodedJsonObj.opt(attributeSchema.getURI()); } if (attributeValObj == null) { - String attributeSchemaName = attributeSchema.getName().toLowerCase(); for (Iterator it = decodedJsonObj.keys(); it.hasNext(); ) { String key = (String) it.next(); - if (key.toLowerCase().equals(attributeSchemaName)) { + if (key.equalsIgnoreCase(attributeSchema.getName())) { attributeValObj = decodedJsonObj.get(key); } } diff --git a/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java b/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java index 962d65774..1fb8f0c97 100644 --- a/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java +++ b/modules/charon-core/src/test/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManagerTest.java @@ -1247,7 +1247,7 @@ public void testGetUserName(Object objectUser, String scimObjectString) public Object[][] dataToTestGetUsernameErrorInGettingTheUsernameFromTheAnonymousRequest() { String scimObjectString = "{\n" + - "UsrName: John,\n" + + "InvalidUserName: John,\n" + "}"; return new Object[][]{ {scimObjectString} From f276f8939dd7f4b86a9fd0054fc09866cd753124 Mon Sep 17 00:00:00 2001 From: Nils Sperling Date: Mon, 20 Mar 2023 11:16:07 +0100 Subject: [PATCH 3/3] Replace * imports by more granular ones --- .../java/org/wso2/charon3/core/encoder/JSONDecoder.java | 6 +++++- 1 file changed, 5 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 8fbb9deb8..98f4269d4 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 @@ -51,7 +51,11 @@ import org.wso2.charon3.core.utils.codeutils.SearchRequest; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import static org.wso2.charon3.core.schema.SCIMDefinitions.DataType.BINARY; import static org.wso2.charon3.core.schema.SCIMDefinitions.DataType.BOOLEAN;