Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Security,为什么第二个WebSecurity配置适配器不工作?_Spring_Spring Security_Spring Java Config - Fatal编程技术网

Spring Security,为什么第二个WebSecurity配置适配器不工作?

Spring Security,为什么第二个WebSecurity配置适配器不工作?,spring,spring-security,spring-java-config,Spring,Spring Security,Spring Java Config,更新: 在第一个WebSecurityConfigureAdapter中添加.antMatcher(“/admin/**”),现在就可以工作了,为什么 现在,第一个WebSecurity配置适配器的配置方法是: protected void configure(HttpSecurity http) throws Exception { http .antMatcher("/admin/**")

更新:

在第一个WebSecurityConfigureAdapter中添加
.antMatcher(“/admin/**”)
,现在就可以工作了,为什么

现在,第一个WebSecurity配置适配器的配置方法是:

        protected void configure(HttpSecurity http) throws Exception {
            http
                .antMatcher("/admin/**")                 // <<<<<<<<<<<<<<--- newly added
                    .authorizeRequests()
                    .antMatchers("/admin/**").hasRole("ADM")
                    .and()
                .formLogin()
                    .loginPage("/admin/login")
                    .permitAll()
                .logout()
                    .permitAll();
        }
问题是第二个WebSecurity配置适配器不工作,如果我在浏览器中输入:/admin,它将按预期带我到/admin/login

而如果我输入/user,它将通过安全过滤器直接进入控制器中的操作


为什么会这样?

原因是first WebSecurity配置适配器

        http
            .authorizeRequests()
这将匹配所有URL,使第二个UserLoginWebSecurityConfigureAdapter无效,添加antMatcher有助于限制它可以匹配的URL,这就是为什么添加
.antMatcher(“/admin/**”)可以工作。

ref to:,几乎相同的问题,官方链接也可能有用:
        http
            .authorizeRequests()