Search code examples
keycloakkeycloak-serviceskeycloak-gatekeeper

Keycloak Custom message on user temporary lock


I am using Kyecloak:4.8.0, and have enabled Brute force attack for my realm. Now whenever user provides wrong credentials for 3 times user will be locked temporarily.

But still user will see "Invalid username/password".

According to this thread Keycloak have done this intentionally: https://issues.jboss.org/browse/KEYCLOAK-5284

But still i want to show user that his account has been locked.

Is there any way to customize this message?

I tried doing this by adding message in custom keycloak theme as below:

location: themes\adminlte\login\messages\messages_en.properties

accountTemporarilyDisabledMessage=Account is temporarily disabled, contact admin or try again later.

This change is not working.


Solution

  • After going through Keycloak base code what i found is: Keycloak uses Messages.INVALID_USER (invalidUserMessage) from properties which is written in AbstractFormAuthenticator class.

    This class is at the end extended by UsernamePasswordForm now to change this to custom message i Wrote Custom Authenticator (Keycloak SPI) like below

    public class CustomUsernameFormAuthenticator extends UsernamePasswordForm {
    
        @Override
        protected String tempDisabledError() {
            return Messages.ACCOUNT_TEMPORARILY_DISABLED;
        }
    }
    

    After this deploy spi Jar in keycloak and enable it in your realm. And we are done :)