8000 Advanced query language to search for users by nicolasiannarilli · Pull Request #15998 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Advanced query language to search for users - #15998

Closed
nicolasiannarilli wants to merge 1 commit into
keycloak:mainfrom
nicolasiannarilli:feature/add-search-user-json-query
Closed

nicolasiannarilli wants to merge 1 commit into
keycloak:mainfrom
nicolasiannarilli:feature/add-search-user-json-query

Conversation

@nicolasiannarilli
@nicolasiannarilli nicolasiannarilli commented Dec 14, 2022 •
Copy link
Copy Markdown

Feature summary

This enhancement would add a new way to create queries for searching users. Using a JSON description of the search criteria, one would be able to craft complex queries like:

{
    "operator": "and",
    "values": [
        {
            "operator": "equals",
            "property": "username",
            "value": "sjohn"
        },
        {
            "operator": "like",
            "property": "firstName",
            "value": "*jo*"
        }
    ]
}

See #14478 for more information.

@nicolasiannarilli
nicolasiannarilli force-pushed the feature/add-search-user-json-query branch from 4df6073 to 6b4ca89 Compare December 21, 2022 13:29
@sschu
sschu commented Dec 21, 2022
Copy link
Copy Markdown
Contributor

In general, I think having a more flexible queries might be nice. However, aren't there standard languages for these kinds of queries?

@nicolasiannarilli
Copy link
Copy Markdown
Author

Except for LDAP-like queries I'm not aware of any language like that, are you thinking of something in particular? Our implementation in JSON is quite flexible and extensible if needeed.

@dalbani
dalbani commented Dec 22, 2022
Copy link
Copy Markdown
Contributor

Just saying, there do exist many query languages, like on https://github.com/AnanthaRajuC/List-of-programming-language-lists/blob/master/language-files/Query%20language.md – and this list is only the tip of the iceberg.

@nicolasiannarilli
Copy link
Copy Markdown
Author

Thanks for your interest in this PR.

Although I believe the JSON expression proposed is not a really a language, but just a data structure representing the search criteria, I also recognize that a concise way of expressing the search criteria can be useful.

I understand that developping a custom language from scratch is not good idea, but with complex query language, adding a new dependency to the keycloak project may cause maintenance issues. By using a JSON structure, we can benefit from the Jackson library. Because it is widespread, this format is quite easy to read and understand for any tech user, whereas a new language need learning.
One drawback from JSON would be long queries with extra quotes and braces could go past the GET request size limit (although it also could occur with any other language).

I looked around for a query language that could fit and found "RSQL/FIQL", which seems to be a good candidate. There's already a java library to parse this language (https://github.com/jirutka/rsql-parser) (but it seems to not be maintained anymore).

What do you suggest, should we add a new language or go along with the PR as it is ?

@sschu
sschu commented Jan 6, 2023
Copy link
Copy Markdown
Contributor

What you linked has not been touched in the last 7 years, so it is probably not the best option. Personally, I would have looked at GraphQL. However, this would more or less mean adding a whole new API.

@nicolasiannarilli
Copy link
Copy Markdown
Author

You're right, I think it'd be best avoiding unmaintained solutions. Supporting GraphQL would require a major overhaul of the KC API, which is far exceeding the scope of this PR.

That's why I still think the proposed JSON structure is a good compromise. I could maybe refactor my code to implement a visitor pattern and allow future implementations of a query language.

@dalbani
dalbani commented Jan 10, 2023
Copy link
Copy Markdown
Contributor

Independently of what the solution should be in the end, I'd very much welcome a way to do some advanced queries in Keycloak.
Like the simple use case of searching for users by attributes with an OR operator, instead of the implicit AND operator that Keycloak now uses.

@nicolasiannarilli
nicolasiannarilli force-pushed the feature/add-search-user-json-query branch from 6b4ca89 to c690dae Compare January 30, 2023 08:50
@sschu
sschu commented Jan 30, 2023
Copy link
Copy Markdown
Contributor

@dalbani You can use multiple requests as a workaround. I agree it's not ideal and I would appreciate better querying capabilities.

@nicolasiannarilli I am not sure it makes sense to continue working on this without feedback from the maintainers.

@thomasdarimont
Copy link
Copy Markdown
Contributor

I think the right thing to do here would be to add support for SCIM https://bookstack.soffid.com/books/scim/page/scim-query-syntax

@stianst
stianst commented Jul 21, 2025
Copy link
Copy Markdown
Contributor

Closing this as it is not something we'll consider for the current Admin APIs. We should consider some form of advanced queries as part of Admin v2 APIs, see https://github.com/keycloak/keycloak/discussions/categories/api-guidelines to join discussions around that.

We also do have plans on adding SCIM, which should also support SCIM query syntax.

@stianst stianst closed this Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0