How to get the reason of login failure in clients

2019-08-09 03:13发布

问题:

We are using Grails Spring Security Rest plugin 1.5.2 with Grails 2.5.2.

Unfortunately it doesn't seem to report any reason of why a login failure occurred. The only thing we get from the login request is HTTP 401.

We have a mechanism where after a number of login failures we set the accountLocked property of the User, so the account becomes disabled/locked.

We would like to get at least a JSON response of why the login failed, like "User account is locked", "Bad credentials", "No such user", etc.

Is there a way to do this with current versions that we use?

回答1:

The plugin doesn't support that out of the box. However, you can easily workaround it by replacing RestAuthenticationFailureHandler with your own implementation and wiring it in resources.groovy as restAuthenticationFailureHandler.