Spring Security6 设置免登录接口地址

  1. 在SecurityFilterChain中设置免登录接口地址。如果定义了多个SecurityFilterChain,并且前面的SecurityFilterChain里使用了anyRequest().authenticated(),后面的免登录可能会失效。
java 复制代码
@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests(authorize -> authorize
                .requestMatchers("/api1/**", "/api2/**").permitAll()
                .anyRequest().authenticated()
            );
        return http.build();
    }

}
  1. 使用WebSecurityCustomizer设置免登录接口地址。这里设置的免登录接口地址是优先于SecurityFilterChain进行判定的。
java 复制代码
@Configuration
public class SecurityConfiguration {
    @Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        return (web) -> web.ignoring().requestMatchers("/ignore1/**", "/ignore2/**");
    }
}
相关推荐
北斗落凡尘1 小时前
LangGraph 入门实战(9)--中断
后端·langchain
CodeSheep1 小时前
又一个华为天才少年,离职了!
前端·后端·程序员
名字还没想好☜1 小时前
Java 线上内存泄漏排查实战:jmap 导堆、MAT 找 GC Roots 与四类常见泄漏
java·开发语言·jvm·内存泄漏
IT_陈寒2 小时前
Vue的双向绑定把我坑惨了,原来这个场景不能用
前端·人工智能·后端
IT爱学堂3 小时前
尚硅谷 - 2025年3月Java+AI大模型应用开发
java·开发语言·人工智能
小贤plus4 小时前
SpringBoot 三大核心注解精讲:@ControllerAdvice、@RestControllerAdvice、@Validated 分组校验(实战)
java
31535669134 小时前
DeepSeek Harness 发布后,我没急着跑 Demo,先把 `.agents/` 翻了一遍
前端·后端·github
Nturmoils4 小时前
不在公司,也能连回办公电脑:用 Natapp 打通 Windows 远程桌面
后端
LEE4 小时前
AI Agent 都在疯狂加功能,它说:我全砍了
前端·后端
吠品4 小时前
Java byte数组与String互转:编码细节与踩坑记录
java·linux·服务器