java 安全配置Sping Boot 6.1错误

kgqe7b3p  于 2023-08-01  发布在  Java
关注(0)|答案(1)|浏览(211)

我在Youtube上看Amigoscode,并遵循他关于如何设置Sping Boot 安全性的教程,但它有点过时,大多数东西都被弃用了,有人能帮我设置SecurityCongifuration吗?这是我的代码(我也无法在互联网上找到很多信息如何解决它):

  1. @Bean
  2. public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
  3. http
  4. .csrf(csrf -> csrf.disable())
  5. .authorizeHttpRequests()
  6. .requestMatchers("")
  7. .permitAll()
  8. .anyRequest()
  9. .authenticated()
  10. .and()
  11. .sessionManagement()
  12. .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
  13. .and()
  14. .authenticationProvider(authenticationProvider)
  15. .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
  16. return http.build();
  17. }

字符串
这是他在教程中提供的代码。

ie3xauqp

ie3xauqp1#

这是应该的,因为不推荐使用泛函

  1. @Bean
  2. public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
  3. http
  4. .csrf(AbstractHttpConfigurer::disable)
  5. .authorizeHttpRequests(authorize -> authorize.requestMatchers("/api/v1/auth/**","/swagger-ui/**","/v3/api-docs/**").permitAll()
  6. .anyRequest()
  7. .authenticated()
  8. )
  9. .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
  10. .authenticationProvider(authenticationProvider);
  11. http.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
  12. return http.build();
  13. }

字符串

展开查看全部

相关问题