From c68fd4d84f8f673242044098cb9cba88007f4bf2 Mon Sep 17 00:00:00 2001 From: Klaas Dellschaft Date: Fri, 5 Aug 2022 15:45:34 +0200 Subject: [PATCH] Unify handling of unspecified count parameters for listWithGet and listWithPost In the SCIM 2.0 spec, it says that "the maximum number of results is set by the service provider" if the count parameter is left unspecified by the user. In case of the listWithPost methods, this defaulting is already done by Charon via CharonConfiguration.getInstance().getCountValueForPagination(). However, in case of listWithGet (using Integer parameters) Charon simply passes on a null value to the implementation of e.g. UserManager, where the developer has to do the defaulting in order to comply with the SCIM 2.0 spec. In order to increase consistency in Charon's handling of the count parameter, and in order to lower the implementation effort for the developer, Charon is now doing the defaulting for listWithPut as well as for listWithGet (in case of Integer parameters). --- .../wso2/charon3/core/utils/ResourceManagerUtil.java | 12 ++++-------- .../charon3/core/utils/ResourceManagerUtilTest.java | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/utils/ResourceManagerUtil.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/utils/ResourceManagerUtil.java index e09c2402d..6ba43b16f 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/utils/ResourceManagerUtil.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/utils/ResourceManagerUtil.java @@ -404,9 +404,9 @@ public static Map getAllAttributeURIs(SCIMResourceTypeSchema sc */ public static int processCount(String countStr) throws BadRequestException { - int count; + Integer count; if (countStr == null || countStr.trim().isEmpty() || !countStr.matches("\\d+")) { - count = CharonConfiguration.getInstance().getCountValueForPagination(); + count = null; } else { try { count = Integer.parseInt(countStr); @@ -415,11 +415,7 @@ public static int processCount(String countStr) throws BadRequestException { } } - if (count < 0) { - count = 0; - } - - return count; + return processCount(count); } /** @@ -432,7 +428,7 @@ public static int processCount(String countStr) throws BadRequestException { public static Integer processCount(Integer countInt) { if (countInt == null || countInt.toString().isEmpty()) { - return null; + return CharonConfiguration.getInstance().getCountValueForPagination(); } else { // All the negative values are interpreted as zero according to the specification. if (countInt <= 0) { diff --git a/modules/charon-core/src/test/java/org/wso2/charon3/core/utils/ResourceManagerUtilTest.java b/modules/charon-core/src/test/java/org/wso2/charon3/core/utils/ResourceManagerUtilTest.java index f6d688ab2..85e5f6bad 100644 --- a/modules/charon-core/src/test/java/org/wso2/charon3/core/utils/ResourceManagerUtilTest.java +++ b/modules/charon-core/src/test/java/org/wso2/charon3/core/utils/ResourceManagerUtilTest.java @@ -236,7 +236,7 @@ public Object[][] dataToProcessCountInteger() { {20, 20}, {-1, 0}, - {null, null} + {null, 0} }; }