A small reason to use Webmvcconfigureradapter for login, failure

Source: Internet
Author: User

 PackageCom.github.carter659.spring13;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;Importjavax.servlet.http.HttpSession;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;Importorg.springframework.web.servlet.config.annotation.InterceptorRegistration;ImportOrg.springframework.web.servlet.config.annotation.InterceptorRegistry;ImportOrg.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;ImportOrg.springframework.web.servlet.handler.HandlerInterceptorAdapter;/*** Login Configuration Blog Source:http://www.cnblogs.com/GoodHelper/ * */@Configuration Public classWebsecurityconfigextendsWebmvcconfigureradapter {/*** Login Session key*/     Public Final StaticString Session_key = "User"; @Bean Publicsecurityinterceptor Getsecurityinterceptor () {return NewSecurityinterceptor (); }     Public voidaddinterceptors (Interceptorregistry registry) {Interceptorregistration Addinterceptor=Registry.addinterceptor (Getsecurityinterceptor ()); //Exclude ConfigurationAddinterceptor.excludepathpatterns ("/error"); Addinterceptor.excludepathpatterns ("/login**"); //interception ConfigurationAddinterceptor.addpathpatterns ("/**"); }    Private classSecurityinterceptorextendsHandlerinterceptoradapter {@Override Public BooleanPrehandle (httpservletrequest request, httpservletresponse response, Object handler)throwsException {HttpSession session=request.getsession (); if(Session.getattribute (session_key)! =NULL)                return true; //Jump LoginString url = "/login";            Response.sendredirect (URL); return false; }    }}
Exclude configuration there, do not send the past to verify the login URL, also to intercept, this reason, tossing me half an hour

Exclude Configuration
Addinterceptor.excludepathpatterns ("/login**");

Https://www.cnblogs.com/GoodHelper/p/6343190.html

A small reason to use Webmvcconfigureradapter for login, failure

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.