Customize login attempt message

Hi Team ,

Currently we are enabling cuba.bruteForceProtection.enabled
We need to customize the login attempt error message , How can we do this ?

Thanks

If I were to do it, I would extend com.haulmont.cuba.security.auth.checks.BruteForceUserCredentialsChecker class to override the original implementation or implement com.haulmont.cuba.security.auth.UserCredentialsChecker interface to add an additional implementation.

Hope it helps you too.

1 Like

Hi Team ,

Also One more concern regarding enabling cuba.bruteForceProtection.enabled

Before , when we are setting Permitted IP Mask for specific user the error message displayed was

informing user that he is not allowed to access the application from this IP

But now , he got message telling him that login attempt failed

How can i separate both messages

Hi, @abd.ibrahim.allam!

The BruteForceUserCredentialsChecker bean has a protected static final field MSG_PACK that defines the message pack and which we cannot change. Therefore, you need to create your own implementation of this bean.
Also, you must specify the order in which the onAuthenticationFailure function is called, either using an @Order annotation so that the priority is higher than in the BruteForceUserCredentialsChecker class, or using @Primary annotation .

I have created a test project to demonstrate. brute-force-protection.zip (316.9 KB)

Regards,
Gleb

1 Like

Thanks Gleb ,

I will go through it and feedback if i face any issue

Sorry, @abd.ibrahim.allam, but I demonstrated you a very long and unnecessary way. In order to change the text of messages, add your implementation to the main message pack.
For the BruteForceUserCredentialsChecker bean, the main message pack is in the core module. You need to specify the new message in the project main message pack (com/company/sample/core/messages.properties):

com.haulmont.cuba.security/LoginException.loginFailedAttemptsLeft = Custom message

I put a link to the documentation, where you can also find an example of using.

Regards,
Gleb

1 Like