A sample application showing how to use events to lock a user account after a fixed number of failed login attempts
Items of note:
-
lockout.FailureEventListeneris registered to listen forAuthenticationFailureBadCredentialsEvent -
lockout.SuccessEventListeneris registered to listen forAuthenticationSuccessEvent -
the User domain class has
int badCredentialsCountto track failed logins -
UserServiceincrements badCredentialsCount for failures and resets to 0 on success -
secured.SecureControllerhas two annotated actions;/securerequiresROLE_USER(orROLE_ADMINsince hierarchical roles are configured) and/secure/adminrequiresROLE_ADMIN -
debug/trace logging for the plugin and Spring Security is configured but commented out in
logback.groovy -
as in all of the demo apps,
main.gspwas renamed toapplication.gspsince that’s the default name if none is specified, and the<meta>tag specifying the layout was removed from the GSPs-
note that this requires configuring the
grails.plugin.springsecurity.gsp.layoutAuthandgrails.plugin.springsecurity.gsp.layoutDeniedproperties inapplication.groovy
-