The role of Springsecurity-exceptiontranslationfilter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.