Spring Security,为什么第二个WebSecurity配置适配器不工作?
更新: 在第一个WebSecurityConfigureAdapter中添加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/**")
.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()