wso2 / product-is

Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
727 stars 713 forks source link

500 server error when invoking the `scim2/Users` endpoint without `count` and `startIndex` > 2 in single-attribute filtering flow #20497

Closed vfraga closed 3 days ago

vfraga commented 1 month ago

Describe the issue:

While testing the pagination and filter parameters for the SCIM /Users endpoint, it was noted that during the single-attribute filtering flow, omitting the count parameter while providing a startIndex value greater than 1 results in a 500 server error response.

<!doctype html>
<html lang="en">

<head>
    <title>HTTP Status 500 – Internal Server Error</title>
<!-- . . . [omitted for brevity] . . . -->
<body>
    <h1>HTTP Status 500 – Internal Server Error</h1>
</body>

</html>

The stack trace shows a ClassCastException:

[2024-06-04 21:43:04,479] [a14c04a4-8bcf-457f-b179-4c8b0743ac52] ERROR {org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/scim2].[SCIM2Servlet]} - Servlet.service() for servlet [SCIM2Servlet] in context with path [/scim2] threw exception java.lang.ClassCastException: org.wso2.carbon.user.core.common.User cannot be cast to java.lang.Comparable
    at java.util.TreeMap.compare(TreeMap.java:1294)
    at java.util.TreeMap.put(TreeMap.java:538)
    at java.util.TreeSet.add(TreeSet.java:255)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
    at java.util.TreeSet.addAll(TreeSet.java:312)
    at java.util.TreeSet.<init>(TreeSet.java:160)
    at org.wso2.carbon.identity.scim2.common.impl.SCIMUserManager.paginateUsers(SCIMUserManager.java:4143)
    at org.wso2.carbon.identity.scim2.common.impl.SCIMUserManager.filterUsersUsingLegacyAPIs(SCIMUserManager.java:1804)
    at org.wso2.carbon.identity.scim2.common.impl.SCIMUserManager.filterUsersBySingleAttribute(SCIMUserManager.java:1292)
    at org.wso2.carbon.identity.scim2.common.impl.SCIMUserManager.filterUsers(SCIMUserManager.java:1243)
    at org.wso2.carbon.identity.scim2.common.impl.SCIMUserManager.listUsersWithGET(SCIMUserManager.java:511)
    at org.wso2.charon3.core.protocol.endpoints.UserResourceManager.listWithGET(UserResourceManager.java:354)
    at org.wso2.carbon.identity.scim2.provider.resources.UserResource.getUser(UserResource.java:215)
    . . . [omitted for brevity] . . .

This likely occurs because the TreeSet object being created [1] does not have a comparison function defined, unlike previously [2]. It appears this issue was addressed in a specific commit [3].

How to reproduce:

  1. Set up an Identity Server instance.
  2. Go to the Claim Configuration page (Claims > List > http://wso2.org/claims) and enable 'Supported by Default' for the 'Account Locked' claim.
  3. In the PRIMARY user store, create 3 users with 'Account Locked' set to 'true'.
  4. Run the following cURL command:
    curl --location --request GET 'https://localhost:9443/scim2/Users?startIndex=2&filter=urn%3Aietf%3Aparams%3Ascim%3Aschemas%3Aextension%3Aenterprise%3A2.0%3AUser%3AaccountLocked%20eq%20%22true%22' \
    --header 'Authorization: Basic YWRtaW46YWRtaW4='
  5. Notice the 500 server error message in HTML format, along with the ClassCastException in the carbon console.

Expected behavior:

There should not be an error when the pagination offset (startIndex) is greater than 1 in the single-attribute filtering flow.

Environment information:


[1] https://github.com/wso2-extensions/identity-inbound-provisioning-scim2/blob/v1.5.46/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java#L3872 [2] https://github.com/wso2-extensions/identity-inbound-provisioning-scim2/blob/v1.5.46/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java#L3848-L3849 [3] https://github.com/wso2-extensions/identity-inbound-provisioning-scim2/commit/5850fa51015d516a55c98fbc0ea87358a2740234#diff-73a583deac4360e8a5cff771ed84fa42f535a6deaace88053b8f039b2e6c26ec