Tag: spring security

spring web,security + web.xml + mvc dispatcher + Bean创建两次

我有如下的Web.xml: mvc-dispatcher org.springframework.web.servlet.DispatcherServlet 1 mvc-dispatcher / springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /api/secure/* [编辑] 在我添加了spring security后,我收到了错误! java.lang.IllegalStateException:找不到WebApplicationContext:没有注册ContextLoaderListener? 然后我补充道 contextConfigLocation /WEB-INF/mvc-dispatcher-servlet.xml org.springframework.web.context.ContextLoaderListener 然后它似乎工作正常,但然后1)问题是豆被创建两次! 如果我只删除它: contextConfigLocation /WEB-INF/mvc-dispatcher-servlet.xml 但是留下然后Web应用程序根本不运行 [额外] 完整的Web.xml如下: Spring MVC Application mvc-dispatcher org.springframework.web.servlet.DispatcherServlet 1 mvc-dispatcher / springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /api/secure/* contextConfigLocation /WEB-INF/mvc-dispatcher-servlet.xml org.springframework.web.context.ContextLoaderListener 这是我的mvc-dispatcher-servlet.xml

注册为Spring bean时,过滤调用两次

我想将@Autowire与Filter一起使用。 所以我在SecurityConfig定义了我的filter,如下所示: @Override protected void configure(HttpSecurity http) throws Exception { http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); http.addFilterBefore(getA(), BasicAuthenticationFilter.class); http.csrf().disable(); } @Bean public A getA(){ return new A(); } 这个filterA扩展了Spring的GenericFilterBean 。 当我调用控制器时,我得到低于输出,这显示filter命中两次。 filter A before filter A before mycontroller invoke filter A after filter A after 我的观察是,这个额外的调用使用Spring容器调用,因为如果filter没有注册为bean,它只会被命中一次。 是什么原因,我该如何解决?

Spring Security:多个HTTP配置不起作用

我正在尝试使用Spring Security,我有一个用例,我想要保护不同的登录页面和不同的URL集。 这是我的配置: @Configuration @Order(1) public static class ProviderSecurity extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers(“/”, “/home”).permitAll() .antMatchers(“/admin/login”).permitAll() .antMatchers(“/admin/**”).access(“hasRole(‘BASE_USER’)”) .and() .formLogin() .loginPage(“/admin/login”).permitAll() .defaultSuccessUrl(“/admin/home”) .failureUrl(“/admin/login?error=true”).permitAll() .usernameParameter(“username”) .passwordParameter(“password”) .and() .csrf() .and() .exceptionHandling().accessDeniedPage(“/Access_Denied”); } } @Configuration @Order(2) public static class ConsumerSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { […]