Home > Back-end >  What is the alternative to the authenticationManagerBean function after the WebSecurityConfigurerAda
What is the alternative to the authenticationManagerBean function after the WebSecurityConfigurerAda

Time:09-29

In Spring Boot 2.7.4, the WebSecurityConfigurerAdapterclass which contains the authenticationManagerBean function is deprecated

What is the alternative?

CodePudding user response:

I have been facing the same problem as you these days, the only solution found is this

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}

But this is causing me an exception in testing. I posted a spring-boot issue on GitHub. Take a look to keep up to date. https://github.com/spring-projects/spring-framework/issues/29215 It could be a bug

CodePudding user response:

I found that the alternative is the getAuthenticationManager function in the AuthenticationConfiguration class


    @Bean
    protected SecurityFilterChain configure(final HttpSecurity http,
                                            final AuthenticationManagerBuilder auth,
                                            final AuthenticationConfiguration authenticationConfiguration) throws Exception {
        // set the authentication provider
        auth.authenticationProvider(daoAuthenticationProvider());

        // set the authorization and authentication rules
        return http
                .csrf().disable()
                // Make sure that the session is stateless because we are using JWT
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                // Add the JWT filter (my custom filter)
                .addFilter(new JwtFilter(authenticationConfiguration.getAuthenticationManager()))
                .build();
}
  • Related