Work with the transition from spring xml security configuration to Java configuration in spring Security.
In my SecurityConfiguration class, which extends WebSecurityConfigurerAdapter. However, the problem is that userDetailsService is not used by security filters, namely UserPasswordAuthenticationFilter. I looked at the launch, and it seems that it was not created before spring boots creates the default InMemoryUserDetailsManager.
@Configuration @EnableWebMvcSecurity @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.userDetailsService(userDetailsService); } }
I also tried to override userDetailsServiceBean and userDetailsService in this class using a specially created ApplicationUserDetailsService application.
@Bean(name="myUserDetailsBean") @Override public UserDetailsService userDetailsServiceBean() { return userDetailsService; } @Override public UserDetailsService userDetailsService() { return userDetailsService; }
However, when I try to override authenticationManagerBean, it looks like it calls my configuration before initializing the initial spring configuration, but it throws an error (below) that there is a circular reference when initializing UserPasswordAuthenticationFilter. I really need to override authenticationManagerBean because I need to determine what is included in the UsernamePasswordAuthenticationFilter.
@Bean(name="myAuthenticationManager") @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); }
..
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter]: Circular reference involving containing bean 'securityBeansConfiguration' - consider declaring the factory method as static for independence from its containing instance. Factory method 'usernamePasswordAuthenticationFilter' threw exception; nested exception is java.lang.IllegalArgumentException: successHandler cannot be null at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] ... 70 common frames omitted
Ideas?
source share