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

/users/count endpoint with search field has different behavior than /users query endpoint #17620

Closed
2 tasks done
99graciamanel opened this issue Mar 13, 2023 · 1 comment · Fixed by #17669
Closed
2 tasks done
Labels
area/account/api area/storage Indicates an issue that touches storage (change in data layout or data manipulation) kind/bug Categorizes a PR related to a bug team/rh-iam
Milestone

Comments

@99graciamanel
Copy link

99graciamanel commented Mar 13, 2023

Before reporting an issue

  • I have searched existing issues
  • I have reproduced the issue with the latest release

Area

admin/api

Describe the bug

/users/count endpoint with search field has different behavior than /users query endpoint because of the JpaUserProvider implementation.

In the method

searchForUserStream(RealmModel realm, Map<String, String> attributes, Integer firstResult, Integer maxResults)

the search key/value attribute is trimmed to treat spaces as different search predicates:

                case UserModel.SEARCH:
                    for (String stringToSearch : value.trim().split("\\s+")) {
                        predicates.add(builder.or(getSearchOptionPredicateArray(stringToSearch, builder, root)));
                    }
                    break;

In the methods

getUsersCount(RealmModel realm, String search, Set<String> groupIds)

and

getUsersCount(RealmModel realm, String search)

the search attribute is used as a unique predicate:

                predicates.add(builder.or(getSearchOptionPredicateArray(search, builder, root)));

Version

18.0.0

Expected behavior

Having the user with representation:

    {
        "username": "john.doe",
        "firstName": "John",
        "lastName": "Doe Smith",
        "email": "john.doe@keycloak.org",
    }

calling the endpoint:

/users/count?search=jo do

I expect result to be 1.

Actual behavior

Result is 0

How to Reproduce?

Call the endpoint:

curl --location --request GET 'https://{mydomain}/auth/admin/realms/{myrealm}/users/?search=jo do' \
--header 'Authorization: Bearer Token'

and

curl --location --request GET 'https://{mydomain}/auth/admin/realms/{myrealm}/users/count?search=jo do' \
--header 'Authorization: Bearer Token'

Anything else?

No response

@99graciamanel 99graciamanel added kind/bug Categorizes a PR related to a bug status/triage labels Mar 13, 2023
@pedro-hos
Copy link
Contributor

Same behavior was on 21.0.1.

@vramik vramik added area/storage Indicates an issue that touches storage (change in data layout or data manipulation) team/store and removed status/triage team/other labels Mar 17, 2023
@vramik vramik added this to the 22.0.0 milestone Mar 21, 2023
pedro-hos added a commit to pedro-hos/keycloak that referenced this issue Mar 22, 2023
mhajas pushed a commit that referenced this issue Mar 24, 2023
@stianst stianst modified the milestones: 22.0.0, 21.1.0 Apr 14, 2023
jonkoops pushed a commit to jonkoops/keycloak that referenced this issue Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/account/api area/storage Indicates an issue that touches storage (change in data layout or data manipulation) kind/bug Categorizes a PR related to a bug team/rh-iam
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants