8000 KEYCLOAK-19894 Working with case-insensitivity on user_entity.username by guusdk · Pull Request #9111 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

KEYCLOAK-19894 Working with case-insensitivity on user_entity.username - #9111

Closed
guusdk wants to merge 2 commits into
keycloak:mainfrom
guusdk:KEYCLOAK-19894_Remove-lowercase-userentity-username
Closed

guusdk wants to merge 2 commits into
keycloak:mainfrom
guusdk:KEYCLOAK-19894_Remove-lowercase-userentity-username

Conversation

@guusdk
@guusdk guusdk commented Dec 13, 2021 •
Copy link
Copy Markdown
Contributor

Values in the username column of the user_entity database table are stored there as lower-case values.

When querying those values, the database-stored values should not be transformed to lower-case (by wrapping them in lower()), because they already are lower-case. Converting them again prevents database indices from being used during execution of the query.

Conversely, search query input values should be transformed to lower-case. Otherwise, the query is sure to not return any data if the input contains anything that isn't lower-case.

More context for this PR is provided in https://keycloak.discourse.group/t/code-change-suggestion-to-improve-performance-for-user-entity-lookups/ and https://issues.redhat.com/projects/KEYCLOAK/issues/KEYCLOAK-19894

@guusdk
guusdk force-pushed the KEYCLOAK-19894_Remove-lowercase-userentity-username branch from 4f304d6 to 7a7be63 Compare December 17, 2021 08:54
@guusdk
guusdk force-pushed the KEYCLOAK-19894_Remove-lowercase-userentity-username branch from 7a7be63 to 002b5c7 Compare January 10, 2022 10:36
@guusdk
guusdk commented Jan 10, 2022
Copy link
Copy Markdown
Contributor Author

I've rebased this on the current head of the main branch.

@guusdk
guusdk force-pushed the KEYCLOAK-19894_Remove-lowercase-userentity-username branch from 002b5c7 to a21bf1d Compare January 17, 2022 13:40
…red value

The values in the 'username' column of the 'user_entity' table are stored as lower-case values.

When querying that column, the column value in a 'where' condition (unlike the provided search value) needs not be transformed to lower-case again (as it already is). With a transformation in place, indices cannot be used, which hurts performance.

This commit removes the to-lower-case transformation of the 'username' column value on the 'user_entity' table.
The values in the 'username' column of the 'user_entity' table are stored as lower-case values.

When querying that column, any input that contains anything but lowercase values will fail.

The existing code-base seems to inconsistently transform input values to lower case. This commit adds to-lower-case transformations in places where that did not yet occur.
@guusdk
guusdk force-pushed the KEYCLOAK-19894_Remove-lowercase-userentity-username branch from a21bf1d to 83dd829 Compare February 21, 2022 14:17
@guusdk
guusdk commented Feb 21, 2022
Copy link
Copy Markdown
Contributor Author

I've rebased this on the current head of the main branch, resolving a merge conflict with org.keycloak.models.jpa.entities.UserEntity.

@guusdk
guusdk commented Apr 22, 2022
Copy link
Copy Markdown
Contributor Author

This is largely been resolved by #8893

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.

1 participant

0