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