Mar*_* Ou 2 spring spring-security spring-boot
我有这个安全配置:
@Override
public void configure(HttpSecurity http) throws Exception {
http
.addFilterBefore(
new JwtLoginFilter("/login", authenticationManager()),
UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(
new JwtAuthenticationFilter(),
UsernamePasswordAuthenticationFilter.class);
http.csrf().disable()
.authorizeRequests().antMatchers("/", "/register").permitAll()
.and()
.authorizeRequests().anyRequest().authenticated();
}
Run Code Online (Sandbox Code Playgroud)
这两个过滤器正在执行身份验证工作:loginFilter 检查帖子正文中的凭据,然后将 cookie 添加到响应中。authenticationFilter 检查 auth cookie。
但是,permitAll 不会让根路由和“/register”路由通过(也就是仍然通过 authenticationFilter,我认为 permitAll 会让这些路由通过过滤器)
怎么了?
permitAll()不会忽略过滤器。它只是授予访问权限,无论在处理完所有过滤器后请求的安全上下文中是否存在身份验证。
您应该检查您的过滤器和它们使用的任何AuthenticationProvider实现,以确保它们不会通过抛出未经检查/未捕获的异常或明确发送对失败身份验证的响应来破坏 Spring Security 的执行流程。
| 归档时间: |
|
| 查看次数: |
2300 次 |
| 最近记录: |