Spring Security without web.xml

前端 未结 7 1397
不思量自难忘°
不思量自难忘° 2021-01-30 15:06

What is the recommended way to add Spring Security to a web application that is using Spring\'s new WebApplicationInitializer interface instead of the web.xml file?

7条回答
  •  囚心锁ツ
    2021-01-30 15:14

    public class SIServerSecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
    
        @Override
        protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
            Dynamic registration = servletContext.addFilter("TenantServletFilter", TenantServletFilter.class);
            EnumSet dispatcherTypes = getSecurityDispatcherTypes();
            registration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
        }
    
    }
    

    This scenario is for executing a filter before executing other filters. If you want to execute a filter after other filers pass true in registration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");. Also check the DispatcherType ASYNC, FORWARD etc.

提交回复
热议问题