Exceptiontranslationfilter catch the exception and do the appropriate processing. The processing logic is as follows:
1. First determine if the exception is springsecurity, if it is to be processed in handlespringsecurityexception (request, response, chain, ASE), otherwise throw servletexception/runtimeexception;
The 2.handleSpringSecurityException method first determines whether it is a authenticationexception exception, and if so, jumps to the login page; otherwise, if it is accessdeniedexception, First to determine whether it is an anonymous user, if yes, will also jump to the login page, if it is authenticated users, then to Accessdeniedhandler processing.
3. Jump to the login interface, Httpsessionrequestcache will save the current request URL, login authentication will go directly to the previously visited page. Using this feature does not set the <form-login> Always-use-default-target property to True, which is false by default. This logic is handled in Savedrequestawareauthenticationsuccesshandler.
4. When catching the exception jump page, you can add the corresponding error code after the URL according to the exception type to give the prompt information on the login page. A simple implementation is to inherit the Loginurlauthenticationentrypoint class and then rewrite
1 protected String determineurltouseforthisrequest (httpservletrequest request,2 HttpServletResponse response, Authenticationexception exception) {34 return Getloginformurl (); 5 }
An error code can be added to the returned result in the implementation body. For example, if you want to add a verification code on the login page, the verification code filling error throws an exception, here you can add the corresponding error code according to the exception type, and then give the corresponding prompt on the login failure page.
The role of Springsecurity-exceptiontranslationfilter