I'm getting the issue "Error creating bean with name 'webSecurityConfiguration': Requested bean is currently in creation: Is there an unresolvable circular reference?"
And i'm not sure how to solve it as i tried to use @Lazy all over, tried to figure out the bean structure, could you help me out?
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration {
private final UserService userService;
public WebSecurityConfiguration(UserService userService) {
this.userService = userService;
}
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// Using lambdas
http.
authorizeHttpRequests((authorize) -> authorize
.requestMatchers("/registration").fullyAuthenticated().anyRequest().denyAll()
.requestMatchers("/admin/**").hasRole(String.valueOf(Role.ADMIN))
.requestMatchers("/").permitAll()
.anyRequest().authenticated()
)
.formLogin((formLogin) -> formLogin
.loginPage("/login")
.defaultSuccessUrl("/")
.permitAll()
)
.logout((logout) ->logout
.logoutUrl("/logout")
.logoutSuccessUrl("/")
.permitAll());
return http.build();
}
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService).passwordEncoder(bCryptPasswordEncoder());
}
}