Keycloak Custom Authentication methods not being invoked

149 Views Asked by At

I am trying to return a custom message for account temporarily disabled in keycloak. I have these classes:

public class CustomAuthenticator extends UsernamePasswordForm {

    private static final Logger logger = Logger.getLogger(CustomAuthenticator.class);


    @Override
    public String disabledByBruteForceError() {
        
        return Messages.ACCOUNT_TEMPORARILY_DISABLED;
    }


}
public class CustomAuthenticatorFactory implements AuthenticatorFactory , ConfigurableAuthenticatorFactory {
    public static final String PROVIDER_ID = "custom-authenticator";
    private static final CustomAuthenticator SINGLETON = new CustomAuthenticator();
    @Override
    public String getDisplayType() {
        return "Custom authenticator";
    }

    @Override
    public String getReferenceCategory() {
        return null;
    }

    @Override
    public boolean isConfigurable() {
        return false;
    }

    @Override
    public AuthenticationExecutionModel.Requirement[] getRequirementChoices() {
        return new AuthenticationExecutionModel.Requirement[] { AuthenticationExecutionModel.Requirement.REQUIRED };
    }

    @Override
    public boolean isUserSetupAllowed() {
        return false;
    }

    @Override
    public String getHelpText() {
        return null;
    }

    @Override
    public List<ProviderConfigProperty> getConfigProperties() {
        return null;
    }

    @Override
    public Authenticator create(KeycloakSession keycloakSession) {
        return SINGLETON;
    }

    @Override
    public void init(Config.Scope scope) {

    }

    @Override
    public void postInit(KeycloakSessionFactory keycloakSessionFactory) {

    }

    @Override
    public void close() {

    }

    @Override
    public String getId() {
        return PROVIDER_ID;
    }
}

And I also provided org.keycloak.authentication.AuthenticatorFactory file where I put the "CustomAuthenticatorFactory" class path in src/main/resources/META-INF/services directory. Then created jar and put it to providers directory of keycloak-20. My jar is registered and I added the execution to the browser flow but the overriden method is not being called.

I also tried overriding authenticate method which is also not being called. Can someone tell me where the problem is? I also tried this process using keycloak-22. Then downgraded to keycloak-20 to see if this is working, but nothing works.

0

There are 0 best solutions below