spring boot 2.7 記述方法
spring boot 2.6までは、WebSecurityConfigurerAdapterを使用していました。しかし、spring boot 2.7 (Spring Security 5.7)になってからは、WebSecurityConfigurerAdapterを使用していましたを使用が推奨されません。
書き換え方法は、
に記述されています。
しかし、AuthenticationManagerの記述方法は、ドキュメントに記述されているが、ドキュメント通りに記述し直してもうまくいきませんでした。
いろいろしらべ、以下の記述方法で、うまく動いています。
@Configuration
public class SecurityConfiguration {
@Bean
public AuthenticationManager authenticationManager(
final AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
AuthenticationManagerの設定方法
パラメータに AuthenticationConfigurationを設定して、AuthenticationManager を生成すると、うまく動きます。
stackoverflowを参考にしました。