java 如何从Spring Security 5.x迁移到Spring 6.1.x?[已关闭]

r1zhe5dt  于 2023-09-29  发布在  Java
关注(0)|答案(2)|浏览(145)

**已关闭。**此问题需要debugging details。它目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
昨天关门了。
Improve this question
我想将此代码迁移到Spring Security 6.1.x

@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests().requestMatchers("/").permitAll();
        http.cors().and().csrf().disable();
        return http.build();
    }

}

我尝试使用authorizeHttpRequests,但它给了我403错误

wtzytmuj

wtzytmuj1#

在stackoverflow上有很多关于如何迁移的帖子,但你也应该阅读下一个参考:

  1. Migration Guide
  2. spring-security-without-the-websecurityconfigureradapter
  3. Deprecated List
    另外,您提供的filterChain将具有下一个主体:
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
  http.authorizeHttpRequests(request -> {
    request.requestMatchers("/**").permitAll();
  });
  http.cors(Customizer.withDefaults());

  http.csrf(AbstractHttpConfigurer::disable);

  http.httpBasic(Customizer.withDefaults());

  return http.build();
}
3xiyfsfu

3xiyfsfu2#

欢迎来到Stack Overflow!
在第一个问题中,问题在于requestMatcher模式。您应该将其更改为"/**",因为Spring MVC的模式匹配是相对于servlet路径的。这意味着,如果您将任何servletMap到以“/”开头且大于1的路径,则应使用此模式。
正如this answer正确建议的那样,您可以将authorizeHttpRequests与lambda函数一起使用。

相关问题