#Spring versions

7 messages · Page 1 of 1 (latest)

weak sundial
#

Hello.
I am trying to use WebSecurityConfigurerAdapter in spring. However I read somewhere that I need to downgrade 'org.springframework.boot' below 2.7.0. But when I do that it is not possible to resolve symbol 'jakarta'.
What can I do?

full pikeBOT
#

This post has been reserved for your question.

Hey @weak sundial! Please use /close or the Close Post button 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.

elder scroll
#

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();
}
weak sundial
# elder scroll instead, you should create a `SecurityFilterChain` bean

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.