Skip to content

Allow to query users with both search and q parameters#48852

Draft
matlipowski wants to merge 1 commit into
keycloak:mainfrom
matlipowski:main
Draft

Allow to query users with both search and q parameters#48852
matlipowski wants to merge 1 commit into
keycloak:mainfrom
matlipowski:main

Conversation

@matlipowski

@matlipowski matlipowski commented May 9, 2026

Copy link
Copy Markdown

Closes #45345

Change is super simple and has no breaking changes, so I'm just throwing it in. Refer to issue and many related closed issues for more details.

I'm not sure if I should update anything in documentation, since old behavior is not mentioned there.

I used Codex AI agent for assistance.

@matlipowski
matlipowski marked this pull request as ready for review May 9, 2026 09:09
@matlipowski
matlipowski requested a review from a team as a code owner May 9, 2026 09:09
Copilot AI review requested due to automatic review settings July 18, 2026 10:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables combining general user search with custom-attribute filters.

Changes:

  • Merges q attributes into user search and count parameters.
  • Adds integration coverage for combined filtering.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
UsersResource.java Combines search and attribute filters.
UserSearchTest.java Tests combined list and count queries.

Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Copilot AI review requested due to automatic review settings July 18, 2026 12:53
@matlipowski
matlipowski requested review from a team as code owners July 18, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Copilot AI review requested due to automatic review settings July 18, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
Copilot AI review requested due to automatic review settings July 18, 2026 18:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java:330

  • The non-q filters above are still included in this map, so providers now apply them together with search even though this endpoint documents that only q is combined. For example, a no-import LDAP request with search and emailVerified now returns no users because LDAP treats emailVerified as an unmapped filter; construct this branch from SEARCH and searchAttributes only.
                attributes.putAll(searchAttributes);

services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java:464

  • The count path has the same regression as the listing path: enabled, emailVerified, and creation-time parameters are now applied with search, contrary to the retained API contract that other criteria are ignored. Keep only SEARCH plus fields originating from q so count and list preserve the same semantics across storage providers.
            parameters.putAll(searchAttributes);

Comment thread services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java Outdated
…ameters (keycloak#45345)

Signed-off-by: Mateusz Lipowski <matlipowski@gmail.com>
Copilot AI review requested due to automatic review settings July 18, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java:538

  • This makes an exact id:, username:, or email: lookup run an unbounded realm-wide q search and materialize every matching ID just to check a small candidate list. For a broad attribute value this can query—and for LDAP potentially import—large user populations despite the endpoint's max limit; constrain the attribute query to the candidate IDs or evaluate the candidate set directly instead.
        Set<String> matchingIds = session.users().searchForUserStream(realm, searchAttributes)
                .map(UserModel::getId)
                .filter(candidateIds::contains)
                .collect(Collectors.toSet());

@matlipowski
matlipowski marked this pull request as draft July 18, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance user search to include custom attributes

3 participants