You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
There is an wrong behaviour with the SCIM2 User paginated search whenever you apply a filter to the search that causes totalResults pagination metadata to return an incorrect value: instead of reporting the actual total results count, it just reports your current result size both in the itemsPerPage and totalResults parameters.
When you call POST /Users/.search or GET /Users, SCIMUserManager.listUsersWithGET() method is internally called.
List<Object> scimUsers = getUserDetails(coreUsers, requiredAttributes);
if (totalUsers != 0) {
users.set(0, Math.toIntExact(totalUsers)); // Set total number of results to 0th index.
} else {
users.set(0, scimUsers.size());
}
users.addAll(scimUsers); // Set user details from index 1.
However, when filterUsers() is called, whether it calls filterUsersBySingleAttribute() or getMultiAttributeFilteredUsers() it is using the current search result size as a total result.
In the case of filterUsersBySingleAttribute(), a getDetailedUsers() method is called after retrieving users:
privateList<Object> filterUsersBySingleAttribute(ExpressionNodenode, Map<String, Boolean> requiredAttributes,
intoffset, intlimit, StringsortBy, StringsortOrder,
StringdomainName) throwsCharonException {
Set<org.wso2.carbon.user.core.common.User> users;
if (log.isDebugEnabled()) {
log.debug(String.format("Listing users by filter: %s %s %s", node.getAttributeValue(), node.getOperation(),
node.getValue()));
}
// Check whether the filter operation is supported by the users endpoint.if (isFilteringNotSupported(node.getOperation())) {
StringerrorMessage =
"Filter operation: " + node.getOperation() + " is not supported for filtering in users endpoint.";
thrownewCharonException(errorMessage);
}
domainName = resolveDomainName(domainName, node);
try {
// Check which APIs should the filter needs to follow.if (isUseLegacyAPIs(limit)) {
users = filterUsersUsingLegacyAPIs(node, limit, offset, domainName);
} else {
users = filterUsers(node, offset, limit, sortBy, sortOrder, domainName);
}
} catch (NotImplementedExceptione) {
StringerrorMessage = String.format("System does not support filter operator: %s", node.getOperation());
thrownewCharonException(errorMessage, e);
}
returngetDetailedUsers(users, requiredAttributes);
}
privateList<Object> getDetailedUsers(Set<org.wso2.carbon.user.core.common.User> coreUsers,
Map<String, Boolean> requiredAttributes)
throwsCharonException {
List<Object> filteredUsers = newArrayList<>();
// 0th index is to store total number of results.filteredUsers.add(0);
// Set total number of filtered results.filteredUsers.set(0, coreUsers.size());
// Get details of the finalized user list.filteredUsers.addAll(getFilteredUserDetails(coreUsers, requiredAttributes));
returnfilteredUsers;
}
...and it sets search size as total result.
On the other hand, getMultiAttributeFilteredUsers() sets directly total results (List[0]) as users size:
privateList<Object> getMultiAttributeFilteredUsers(Nodenode, Map<String, Boolean> requiredAttributes, intoffset,
intlimit, StringsortBy, StringsortOrder, StringdomainName)
throwsCharonException {
List<Object> filteredUsers = newArrayList<>();
// 0th index is to store total number of results.filteredUsers.add(0);
Set<org.wso2.carbon.user.core.common.User> users;
// Handle pagination.if (limit > 0) {
users = getFilteredUsersFromMultiAttributeFiltering(node, offset, limit, sortBy, sortOrder, domainName);
filteredUsers.set(0, users.size());
filteredUsers.addAll(getFilteredUserDetails(users, requiredAttributes));
} else {
intmaxLimit = getMaxLimit(domainName);
if (StringUtils.isNotEmpty(domainName)) {
users = getFilteredUsersFromMultiAttributeFiltering(node, offset, maxLimit, sortBy,
sortOrder, domainName);
filteredUsers.set(0, users.size());
filteredUsers.addAll(getFilteredUserDetails(users, requiredAttributes));
} else {
inttotalUserCount = 0;
// If pagination and domain name are not given, then perform filtering on all available user stores.while (carbonUM != null) {
// If carbonUM is not an instance of Abstract User Store Manger we can't get the domain name.if (carbonUMinstanceofAbstractUserStoreManager) {
domainName = carbonUM.getRealmConfiguration().getUserStoreProperty("DomainName");
users = getFilteredUsersFromMultiAttributeFiltering(node, offset, maxLimit,
sortBy, sortOrder, domainName);
totalUserCount += users.size();
filteredUsers.addAll(getFilteredUserDetails(users, requiredAttributes));
}
carbonUM = (AbstractUserStoreManager) carbonUM.getSecondaryUserStoreManager();
}
//set the total resultsfilteredUsers.set(0, totalUserCount);
}
}
returnfilteredUsers;
}
Description:
There is an wrong behaviour with the SCIM2 User paginated search whenever you apply a filter to the search that causes totalResults pagination metadata to return an incorrect value: instead of reporting the actual total results count, it just reports your current result size both in the itemsPerPage and totalResults parameters.
When you call POST /Users/.search or GET /Users, SCIMUserManager.listUsersWithGET() method is internally called.
This method calls listUsers() when there's no informed filter, and filterUsers() when there's one.
Internally, listUsers() calculates total count and then sets it in response (List[0]):
However, when filterUsers() is called, whether it calls filterUsersBySingleAttribute() or getMultiAttributeFilteredUsers() it is using the current search result size as a total result.
In the case of filterUsersBySingleAttribute(), a getDetailedUsers() method is called after retrieving users:
...and it sets search size as total result.
On the other hand, getMultiAttributeFilteredUsers() sets directly total results (List[0]) as users size:
So, when we make the following request:
It gives us a result like this:
When the actual total results is 3, as seen in the example below (where a count of 10 is requested):
Suggested Labels:
Suggested Assignees:
Affected Product Version:
From 5.10.0 to latest (master)
OS, DB, other environment details and versions:
Windows, H2, WSO2IS-KM-5.10.0
Steps to reproduce:
And it will return a totalResults count with the same value as the itemsPerPage attribute:
Related Issues:
The text was updated successfully, but these errors were encountered: