Reputation: 865
I am using WebSecurityConfigurerAdapter and I want to know if there is a way to configure error handler in the WebSecurityConfigurerAdapter like it used to be in web.xml I want to catch all my UsernameNotFoundException/401 and do handle it.
example:
<error-page>
<error-code>401</error-code>
<location>/SngErrorHandler</location>
</error-page>
<error-page>
<exception-type>org.springframework.security.core.userdetails.UsernameNotFoundException</exception-type>
<location>/SngErrorHandler</location>
</error-page>
Upvotes: 0
Views: 675
Reputation: 148900
According to the javadoc of AbstractAuthenticationFilterConfigurer
(for Spring-Security 3.2.x), Spring security normally does this automatically for you redirecting to "/login?error"
If you want to redirect to another page and you are using login form authentication, you can do that by adding http.formLogin().failureUrl("/SngErrorHandler")
in the configure(HttpSecurity http)
method of your WebSecurityConfigurerAdapter
.
This has to be adapted if you are using other authentication methods.
Upvotes: 2