Hi everyone,
I am using Keycloak 26.3.0 and I have enabled Brute Force Detection.
My configuration:
- Max Login Failures = 3
- Lockout permanently enabled
- I am using Direct Grant (token endpoint API) for login, not browser login
Problem
I noticed that Keycloak stores invalid login attempts in its internal cache (Infinispan). Because of this:
- The invalid attempt counter resets automatically after some time (for example after a few days)
- Even if the user is not yet permanently locked, the count goes back to zero
This behavior makes it hard to track the full history of invalid login attempts, especially for security/audit purposes.
Requirement
I need this behavior:
- Invalid login attempts should be stored permanently in the database
- Failure counter should not reset automatically
- User should be locked when failures reach the threshold
- User stays locked according to Keycloak settings
- Must work with token endpoint (/protocol/openid-connect/token)
Essentially, I want both the invalid attempt count and lock state to be persistent, not temporary cache-based.
Question
Is there any built-in configuration or recommended approach in Keycloak to persist login failure attempts permanently?
Or is a custom SPI/extension required for this use case?
Thanks for your guidance.