0

I currently want to implemenet something like this:

    @Resource
    private UserDetailsService userDetailsService;

    @Bean
    public DaoAuthenticationProvider authProvider() {
        DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
        authProvider.setUserDetailsService(userDetailsService);
        authProvider.setPasswordEncoder(passwordEncoder());
        return authProvider;
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authProvider());
    }

But in we will focus on the authProvider() method and configure()

With recent news, WebSecurityConfigurerAdapter is deprecated. And after researching a bit i found out suck a thing:

@Configuration
@EnableWebSecurity
public class SpringSecurity {
    @Resource
    private UsersService usersService;

    @Bean
    public Argon2PasswordEncoder passwordEncoder() {
        return new Argon2PasswordEncoder();
    }

    @Bean
    public DaoAuthenticationProvider authProvider() {
        DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
        authProvider.setUserDetailsService(usersService);
        authProvider.setPasswordEncoder(passwordEncoder());
        return authProvider;
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authProvider());
    }
.......

So i also had to do

@EnableAsync(proxyTargetClass = true)
@EnableCaching(proxyTargetClass = true)

This resolved another issue. But moving on, i get this error now.

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
...
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
...
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'springSecurity': Requested bean is currently in creation: Is there an unresolvable circular reference?

also here is my UsersService

@Service
public class UsersService implements UserDetailsService {
    @Autowired
    private UsersRepository usersRepository;
...

You guys mind helping me resolve this issue! Thanks :)

I'd also like to mention i have not found my answer online

Ryan The Ghost
  • 116
  • 1
  • 13
  • Does this answer your question? [How to add an additional AuthenticationProvider without using WebSecurityConfigurerAdapter](https://stackoverflow.com/questions/72458298/how-to-add-an-additional-authenticationprovider-without-using-websecurityconfigu) – Eleftheria Stein-Kousathana Jul 27 '22 at 11:21

1 Answers1

0

This question talks about the fact that WebSecurityConfigurerAdapter is now deprecated - while also using a UserDetailsService.

Maybe it can help.

hugoalexandremf
  • 166
  • 1
  • 1
  • 9