In the latest version of spring boot 3.1.1 WebSecurityConfigurerAdaptor, @EnableWebFluxSecurity, springSecurityFilterChain, .csrf(), ServerHttpSecurity & .pathMatchers() are deprecated so you have to change the code.
You can refer this code if you are using spring boot 3 :
@EnableWebSecurity
@Configuration
@RequiredArgsConstructor
public class SecurityConfig {
private final UserDetailServiceImpl userDetailsService;
private final BCryptPasswordEncoder encoder;
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(csrf -> csrf.disable())
.authorizeRequests().
requestMatchers("/category/add")
.authenticated()
.requestMatchers("/authenticate","/register").permitAll()
.anyRequest()
.authenticated()
.and().exceptionHandling(ex -> ex.authenticationEntryPoint(point))
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
http.addFilterBefore(filter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
@Bean
public AuthenticationManager authenticationManager() throws Exception {
return new CustomAuthenticationManager();
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
authenticationProvider.setUserDetailsService(userDetailsService);
authenticationProvider.setPasswordEncoder(encoder);
return authenticationProvider;
}
}
CustomAuthentcationManager :
public class CustomAuthenticationManager implements AuthenticationManager {
@Autowired
private DaoAuthenticationProvider authenticationProvider;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
return authenticationProvider.authenticate(authentication);
}
}