Q:

Grails Spring Security failed login not redirecting to login view

Having a customised login where username + password + organisation are needed to login. Both login success and login fail cases are working from the authentication perspective, but the failed login is not redirecting to the login page as expected. Instead it's showing a 401 error page, with a message like this:
HTTP Status 401 - Authentication Failed: No matching account
What should I do to correct the redirect to show the login page instead of the HTTP status page?
The URL I see on failed login is: 
localhost/myapp/j_ehrserver_security_check
Here is the code of my login implementation:

https://github.com/ppazos/cabolabs-ehrserver/tree/security/src/groovy/com/cabolabs/security
https://github.com/ppazos/cabolabs-ehrserver/tree/security/src/java/com/cabolabs/security

A:

Solved adding the URL mapping corresponding to the 401 HTTP Status like @Vinay suggested, but I used the controller instead of the view:
"401"(controller:'login')

Edit
I found a springish solution:
Configuring the authenticationFailureHandler bean into my customized authFilter. With that /login/authfail is called, and there the AuthenticationException is handled and converted into flash.message, so I can show feedback to the user.
This was tough to understand because of all the dependency injection from Spring but it worked!
Now my spring/resources.groovy looks like:
import com.cabolabs.security.AuthFilter
import com.cabolabs.security.AuthProvider
beans = {

   authProvider(AuthProvider) {
      passwordEncoder = ref("passwordEncoder") // from plugin
   }

   authFilter(AuthFilter) {
      authProvider = ref("authProvider")
      authenticationManager = ref("authenticationManager")
      sessionAuthenticationStrategy = ref('sessionAuthenticationStrategy')
      authenticationSuccessHandler = ref('authenticationSuccessHandler')
      authenticationFailureHandler = ref('authenticationFailureHandler')
      rememberMeServices = ref("rememberMeServices")
      requiresAuthenticationRequestMatcher = ref('filterProcessUrlRequestMatcher')
   }
}

