LoginSignup
7
5

More than 1 year has passed since last update.

Spring boot 2.7 (Spring Security 5.7)のAuthenticationManagerの設定

Posted at

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を参考にしました。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5