diff --git a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java index 18e10841f..bdb80d0df 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java @@ -605,10 +605,6 @@ public UsersGetResponse listUsersWithGET(Node rootNode, Integer startIndex, Inte String sortOrder, String domainName, Map requiredAttributes) throws CharonException, NotImplementedException, BadRequestException { - // Validates the count parameter if exists. - if (count != null && IdentityUtil.isSCIM2UserMaxItemsPerPageEnabled()) { - count = validateCountParameter(count); - } // Validate NULL value for startIndex. startIndex = handleStartIndexEqualsNULL(startIndex); if (sortBy != null || sortOrder != null) { @@ -6441,24 +6437,4 @@ private String maskIfRequired(String value) { return LoggerUtils.isLogMaskingEnable ? LoggerUtils.getMaskedContent(value) : value; } - - /** - * Validate the count query parameter. - * - * @param count Requested item count. - * @return Validated count parameter. - */ - private int validateCountParameter(Integer count) { - - int maximumItemsPerPage = IdentityUtil.getMaximumItemPerPage(); - if (count > maximumItemsPerPage) { - if (log.isDebugEnabled()) { - log.debug(String.format("Given limit exceeds the maximum limit. Therefore the limit is set to %s.", - maximumItemsPerPage)); - } - return maximumItemsPerPage; - } - - return count; - } } diff --git a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java index 65ce01b3a..fa83a8447 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/test/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManagerTest.java @@ -532,8 +532,8 @@ public Object[][] listUser() throws Exception { @Test(dataProvider = "userInfoForFiltering") public void testFilteringUsersWithGET(List users, String filter, - Integer count, int expectedResultCount, - List filteredUsers) throws Exception { + int expectedResultCount, List + filteredUsers) throws Exception { Map scimToLocalClaimMap = new HashMap<>(); scimToLocalClaimMap.put("urn:ietf:params:scim:schemas:core:2.0:User:userName", @@ -570,8 +570,6 @@ public void testFilteringUsersWithGET(List testUser3Attributes = new HashMap<>(); - testUser3Attributes.put("http://wso2.org/claims/givenname", "testUser"); - testUser3Attributes.put("http://wso2.org/claims/emailaddress", "testUser3@wso2.com"); - testUser3.setAttributes(testUser1Attributes); - testUser3.setUserStoreDomain("PRIMARY"); - users.add(testUser3); - return new Object[][]{ - {users, "name.givenName eq testUser", null, 2, + {users, "name.givenName eq testUser", 2, new ArrayList() {{ add(testUser1); add(testUser2); }}}, - {users, "name.givenName eq testUser and emails eq testUser1@wso2.com", null, 1, + {users, "name.givenName eq testUser and emails eq testUser1@wso2.com", 1, new ArrayList() {{ add(testUser1); - }}}, - {users, "name.givenName eq testUser", 3, 2, - new ArrayList() {{ - add(testUser1); - add(testUser2); }}} }; } diff --git a/components/org.wso2.carbon.identity.scim2.provider/src/main/java/org/wso2/carbon/identity/scim2/provider/resources/UserResource.java b/components/org.wso2.carbon.identity.scim2.provider/src/main/java/org/wso2/carbon/identity/scim2/provider/resources/UserResource.java index 0dda9d9d2..38b898163 100644 --- a/components/org.wso2.carbon.identity.scim2.provider/src/main/java/org/wso2/carbon/identity/scim2/provider/resources/UserResource.java +++ b/components/org.wso2.carbon.identity.scim2.provider/src/main/java/org/wso2/carbon/identity/scim2/provider/resources/UserResource.java @@ -199,6 +199,11 @@ public Response getUser(@HeaderParam(SCIMProviderConstants.ACCEPT_HEADER) String throw new FormatNotSupportedException(error); } + // Validates the count parameter if exists. + if (count != null && IdentityUtil.isSCIM2UserMaxItemsPerPageEnabled()) { + count = validateCountParameter(count); + } + // obtain the user store manager UserManager userManager = IdentitySCIMManager.getInstance().getUserManager(); @@ -395,4 +400,24 @@ private void removeAskPasswordConfirmationCodeThreadLocal() { IdentityUtil.threadLocalProperties.get() .remove(IdentityRecoveryConstants.AP_CONFIRMATION_CODE_THREAD_LOCAL_PROPERTY); } + + /** + * Validate the count query parameter. + * + * @param count Requested item count. + * @return Validated count parameter. + */ + private int validateCountParameter(Integer count) { + + int maximumItemsPerPage = IdentityUtil.getMaximumItemPerPage(); + if (count > maximumItemsPerPage) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Given limit exceeds the maximum limit. Therefore the limit is set to %s.", + maximumItemsPerPage)); + } + return maximumItemsPerPage; + } + + return count; + } }