如何修复spring-security版本警告

3pmvbmvn  于 12个月前  发布在  Spring
关注(0)|答案(1)|浏览(167)
@Configurable
@EnableWebSecurity
@RequiredArgsConstructor
public class WebSecurityConfig {
    private final JwtAuthenticationFilter jwtAuthenticationFilter;

    @Bean
    protected SecurityFilterChain configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
            .cors().and()
            .csrf().disable()
            .httpBasic().disable()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
            .authorizeRequests()
            .requestMatchers("/", "/api/v1/auth/**").permitAll()
            .requestMatchers(HttpMethod.GET, "/api/v1/board/**").permitAll()
            .anyRequest().authenticated();

        httpSecurity.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
        return httpSecurity.getOrBuild();
    } 
}

字符串
类型HttpSecurity中的cors()、and()、csrf()、httpBasic()、sessionManagement()自版本6.1起已弃用,并标记为删除
不推荐使用ExpressionUrlAuthorizationConfigurer.AuthorizedUrl类型中的方法EARTHALL()
我如何修复这些错误?
https://youtu.be/l58zLT5l6BY?si=qei5bR1r5LaLY7tT
我在看这段视频
视频的SpringBoot版本是2.7.14我的SpringBoot版本是3.2.0
那我该改什么
我只是复制没有知识的Spring Boot :(
请帮帮我

pjngdqdw

pjngdqdw1#

根据documentationMigration Guide,您必须将当前的一个实现替换为下一个实现,以避免使用已弃用的方法:

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class WebSecurityConfig {
  private final JwtAuthenticationFilter jwtAuthenticationFilter;

  @Bean
  protected SecurityFilterChain configure(HttpSecurity httpSecurity) throws Exception {
    
    httpSecurity.cors(AbstractHttpConfigurer::disable);
    httpSecurity.csrf(AbstractHttpConfigurer::disable);
    httpSecurity.httpBasic(AbstractHttpConfigurer::disable);

    httpSecurity.sessionManagement(session -> 
            session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
    httpSecurity.authorizeHttpRequests(request -> {
      request.requestMatchers("/", "/api/v1/auth/**").permitAll();
      request.requestMatchers(HttpMethod.GET, "/api/v1/board/**").permitAll();
      request.anyRequest().authenticated();
    });
    httpSecurity.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
    return httpSecurity.getOrBuild();
  }
}

字符串
在开始做一些事情之前,我真的建议阅读相关文档,而不是观看有关它的视频。

相关问题