Repository navigation
Handle async processing of the brute force detection when counting login failures - #52429
Merged
stianst merged 1 commit intoSep 7, 2026
Conversation
…gin failures Closes keycloak#52428 Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused test change correctly addresses the documented race without altering production behavior.
Pull request overview
Stabilizes the brute-force detection integration test by waiting for asynchronous failure processing between login attempts.
Changes:
- Adds per-user failure-count waits between requests.
- Extracts polling into
awaitNumFailures.
File summaries
| File | Description |
|---|---|
tests/base/src/test/java/org/keycloak/tests/admin/AttackDetectionResourceTest.java |
Prevents concurrent login attempts from racing with failure processing. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ahus1
marked this pull request as ready for review
September 4, 2026 10:59
mabartos
approved these changes
Sep 4, 2026
stianst
approved these changes
Sep 7, 2026
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.
Closes #52428
Summary
Stabilizes
AttackDetectionResourceTest.testby waiting for each brute force failure to be fully processed before sending the next login request for the same user.Root cause
DefaultBlockingBruteForceProtectortracks concurrent login attempts per user in aloginAttemptsmap. When a second request for the same user arrives while the first is still being processed:isTemporarilyDisabled()returnstrue(login in progress)ValidateUsernamecallscontext.forceChallenge()(notfailureChallenge())FORCE_CHALLENGEdoes not calllogFailure()/failedLogin()(unlikeFAILURE_CHALLENGE)This means
numFailuresstays at 1 instead of reaching the expected 2 — permanently, not just slowly. Increasing the awaitility timeout would not help.Fix
After sending each login request, poll
bruteForceUserStatusuntilnumFailuresreaches the expected value before sending the next request for the same user. This ensures the async executor task has completed and theloginAttemptsentry has been cleared.For
testUser(3 requests,failureFactor=2):numFailures=1numFailures=2(user is now locked)For
testUser2(2 requests):numFailures=1These waits can be removed once brute force processing is synchronous (#52128).