Я пытаюсь выполнить обновление до Spring Boot 3.0.0 и Spring Security 6.0.
Я обнаружил, что метод защиты запросовauthorizeRequests() устарел . А также удалены аннотации метода antMatchers() и @EnableGlobalMethodSecurity. Как я могу обновить конфигурацию безопасности?
Мой код:
Я пытаюсь выполнить обновление до Spring Boot 3.0.0 и Spring Security 6.0. Я обнаружил, что метод защиты запросовauthorizeRequests() устарел . А также удалены аннотации метода antMatchers() и @EnableGlobalMethodSecurity. Как я могу обновить конфигурацию безопасности? Мой код: [code]package org.sid.securityservice.config;
//@Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } @Bean public AuthenticationManager authenticationManager(UserDetailsService userDetailsService){ var authProvider = new DaoAuthenticationProvider(); authProvider.setPasswordEncoder(passwordEncoder); authProvider.setUserDetailsService(userDetailsService); return new ProviderManager(authProvider); }
@Bean public UserDetailsService inMemoryUserDetailsManager(){ return new InMemoryUserDetailsManager( User.withUsername("user1").password(passwordEncoder.encode("1234")).authorities("USER").build(), User.withUsername("user2").password(passwordEncoder.encode("1234")).authorities("USER").build(), User.withUsername("admin").password(passwordEncoder.encode("1234")).authorities("USER","ADMIN").build() ); } @Bean public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { return httpSecurity .csrf(csrf->csrf.disable()) .authorizeRequests(auth->auth.antMatchers("/token/**").permitAll()) .authorizeRequests(auth->auth.anyRequest().authenticated()) .sessionManagement(sess->sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt) .httpBasic(Customizer.withDefaults()) .build(); } @Bean JwtDecoder jwtDecoder(){ return NimbusJwtDecoder.withPublicKey(rsakeysConfig.publicKey()).build(); } @Bean JwtEncoder jwtEncoder(){ JWK jwk= new RSAKey.Builder(rsakeysConfig.publicKey()).privateKey(rsakeysConfig.privateKey()).build(); JWKSource jwkSource= new ImmutableJWKSet(new JWKSet(jwk)); return new NimbusJwtEncoder(jwkSource); }
} [/code] Вот что показывает мне IDE (зачеркнутоauthorizeRequests() и отсутствует antMatchers() < em>выделено красным): [img]https://i.sstatic.net/OBj6E.png[/img]