Spring Boot 3.0.2 登录后请求 URL 添加“继续”查询参数

Kar*_*ski 11 spring spring-security spring-boot

我刚刚将我的项目从 Spring boot 2.7.7 升级到 3.0.2,我看到了一些奇怪的行为。当我登录到我的应用程序时,Spring 将“继续”查询参数添加到 URL。2.7.7 中不是这样的。我缺少什么吗?

我使用 formLogin 并实现了 AuthenticationSuccessHandler,尽管它没有添加任何参数。

在此输入图像描述

jzh*_*aux 20

Spring Security 的迁移指南对此进行了介绍。

基本上,添加了查询参数,以便 Spring Security 知道是否针对该请求查询会话。这是一个性能优化。

RequestCache您可以通过如下配置来更改该值:

@Bean
SecurityFilterChain springSecurity(HttpSecurity http) throws Exception {
    HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
    requestCache.setMatchingRequestParameterName("mycustomparameter");
    http
        // ...
        .requestCache((cache) -> cache
            .requestCache(requestCache)
        );
    return http.build();
}
Run Code Online (Sandbox Code Playgroud)

或者,如果你不想进行这种性能优化,可以用同样的方式将其关闭:

@Bean
SecurityFilterChain springSecurity(HttpSecurity http) throws Exception {
    HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
    requestCache.setMatchingRequestParameterName(null);
    http
        // ...
        .requestCache((cache) -> cache
            .requestCache(requestCache)
        );
    return http.build();
}
Run Code Online (Sandbox Code Playgroud)