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

Revert "Refactor the users list limit to a common method" #565

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,6 @@ public UsersGetResponse listUsersWithGET(Node rootNode, Integer startIndex, Inte
String sortOrder, String domainName, Map<String, Boolean> 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) {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ public Object[][] listUser() throws Exception {

@Test(dataProvider = "userInfoForFiltering")
public void testFilteringUsersWithGET(List<org.wso2.carbon.user.core.common.User> users, String filter,
Integer count, int expectedResultCount,
List<org.wso2.carbon.user.core.common.User> filteredUsers) throws Exception {
int expectedResultCount, List<org.wso2.carbon.user.core.common.User>
filteredUsers) throws Exception {

Map<String, String> scimToLocalClaimMap = new HashMap<>();
scimToLocalClaimMap.put("urn:ietf:params:scim:schemas:core:2.0:User:userName",
Expand Down Expand Up @@ -570,8 +570,6 @@ public void testFilteringUsersWithGET(List<org.wso2.carbon.user.core.common.User
when(mockRealmService.getBootstrapRealmConfiguration()).thenReturn(mockedRealmConfig);
mockStatic(IdentityUtil.class);
when(IdentityUtil.isGroupsVsRolesSeparationImprovementsEnabled()).thenReturn(false);
when(IdentityUtil.getMaximumItemPerPage()).thenReturn(2);
when(IdentityUtil.isSCIM2UserMaxItemsPerPageEnabled()).thenReturn(true);

ClaimMapping[] claimMappings = getTestClaimMappings();
when(mockedClaimManager.getAllClaimMappings(anyString())).thenReturn(claimMappings);
Expand All @@ -587,7 +585,7 @@ public void testFilteringUsersWithGET(List<org.wso2.carbon.user.core.common.User
node = filterTreeManager.buildTree();
}

UsersGetResponse result = scimUserManager.listUsersWithGET(node, Integer.valueOf(1), count, null, null, null,
UsersGetResponse result = scimUserManager.listUsersWithGET(node, 1, null, null, null, null,
requiredClaimsMap);
assertEquals(result.getUsers().size(), expectedResultCount);
}
Expand Down Expand Up @@ -615,30 +613,16 @@ public Object[][] userInfoForFiltering() {
testUser2.setUserStoreDomain("PRIMARY");
users.add(testUser2);

org.wso2.carbon.user.core.common.User testUser3 = new org.wso2.carbon.user.core.common.User(UUID.randomUUID()
.toString(), "testUser3", "testUser3");
Map<String, String> testUser3Attributes = new HashMap<>();
testUser3Attributes.put("http://wso2.org/claims/givenname", "testUser");
testUser3Attributes.put("http://wso2.org/claims/emailaddress", "[email protected]");
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<org.wso2.carbon.user.core.common.User>() {{
add(testUser1);
add(testUser2);
}}},
{users, "name.givenName eq testUser and emails eq [email protected]", null, 1,
{users, "name.givenName eq testUser and emails eq [email protected]", 1,
new ArrayList<org.wso2.carbon.user.core.common.User>() {{
add(testUser1);
}}},
{users, "name.givenName eq testUser", 3, 2,
new ArrayList<org.wso2.carbon.user.core.common.User>() {{
add(testUser1);
add(testUser2);
}}}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
}
Loading