Repository navigation
[26.6] Realm session limit is exceeded - #48105
Merged
Merged
Conversation
keycloak#48064) * when the realm session limit is exceeded and behavior is set to Terminate oldest session, the authenticator calls handleLimitExceeded(userSessionsForClient, userClientLimit) first. if the user has fewer existing sessions for the current client than userClientLimit - 1, getNumberOfSessionsThatNeedToBeLoggedOut() returns a negative value and Stream.limit(negative) throws IllegalArgumentException, producing a 500 on every login to that client. This change ensures that getNumberOfSessionsThatNeedToBeLoggedOut returns 0 if the calculated value is negative. The dependent execution steps remain unchanged. A result of 0 sessions to be purged from the current client triggers the removal of the oldest sessions across all clients. also added a regression test in UserSessionLimitsTest that reproduces the scenario: realm limit=2, client limit=3, two logins on client-a to saturate the realm, then login on client-b (0 existing client sessions). Fixes keycloak#48040 --------- Signed-off-by: Martin Krcka <martin.krcka@adesso.de> Signed-off-by: Martin Bartoš <mabartos@redhat.com> Co-authored-by: Mateen Anjum <mateenali66@gmail.com> Co-authored-by: Martin Bartoš <mabartos@redhat.com> (cherry picked from commit 953cd26)
1 of 2 tasks
ahus1
approved these changes
Apr 15, 2026
ahus1
enabled auto-merge (squash)
April 15, 2026 14:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
handleLimitExceeded(userSessionsForClient, userClientLimit) first.
if the user has fewer existing sessions for the current client than userClientLimit - 1, getNumberOfSessionsThatNeedToBeLoggedOut() returns a negative value and Stream.limit(negative) throws
IllegalArgumentException, producing a 500 on every login to that client.
This change ensures that getNumberOfSessionsThatNeedToBeLoggedOut returns 0 if the calculated value is negative.
The dependent execution steps remain unchanged.
A result of 0 sessions to be purged from the current client triggers the removal of the oldest sessions across all clients.
also added a regression test in UserSessionLimitsTest that reproduces the scenario: realm limit=2, client limit=3, two logins on client-a to saturate the realm, then login on client-b (0 existing client sessions).
Fixes #48040
Signed-off-by: Martin Krcka martin.krcka@adesso.de
Signed-off-by: Martin Bartoš mabartos@redhat.com
Co-authored-by: Mateen Anjum mateenali66@gmail.com
Co-authored-by: Martin Bartoš mabartos@redhat.com
(cherry picked from commit 953cd26)
@ahus1 IMHO, it might be backported to the 26.6.