#Spring versions
7 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @weak sundial! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
WebSecurityConfigurerAdapter has been deprecated and removed in Spring Security 6/Spring Boot 3
instead, you should create a SecurityFilterChain bean
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http){
return http
//...
.build();
}
I have tried to implement it:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Autowired
private UserDetailsService userDetailsService;
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider provider
= new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService);
provider.setPasswordEncoder(new BCryptPasswordEncoder());
return provider;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
return authConfig.getAuthenticationManager();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/home").hasAuthority("USER")
.requestMatchers("/admin").hasAuthority("ADMIN")
.anyRequest().authenticated()
);
return http.build();
}
}
But it is giving the error:
Field userDetailsService in WebSecurityConfig required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found.