Issue
In Spring Boot 2.7.4, the WebSecurityConfigurerAdapter
class which contains the authenticationManagerBean
function is deprecated
What is the alternative?
Solution
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();
}
Answered By - Anas Elgarhy
Answer Checked By - David Goodson (JavaFixing Volunteer)