Работа с переходом с весны безопасности xml конфигурации на Java Config в Spring Security.Spring boot, spring security override UserDetailsService
В моем классе SecurityConfiguration, который расширяет WebSecurityConfigurerAdapter. Однако проблема заключается в том, что userDetailsService не используется фильтрами безопасности, а именно UserPasswordAuthenticationFilter. Я посмотрел на запуск, и кажется, что это не создано до того, как Spring boots создаст по умолчанию InMemoryUserDetailsManager.
@Configuration
@EnableWebMvcSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http)
throws Exception {
http.userDetailsService(userDetailsService);
}
}
Я также попытался переопределить userDetailsServiceBean и UserDetailsService в этом классе, используя пользовательские впрыскивается ApplicationUserDetailsService.
@Bean(name="myUserDetailsBean")
@Override
public UserDetailsService userDetailsServiceBean() {
return userDetailsService;
}
@Override
public UserDetailsService userDetailsService() {
return userDetailsService;
}
Однако, когда я пытаюсь переопределить authenticationManagerBean, похоже, он вызывает мою конфигурацию до конфигурации пружины загрузки инициализирует но он выдает ошибку (ниже), что существует циклическая при инициализации UsernamePasswordAuthenticationFilter. Мне действительно нужно переопределить authenticationManagerBean, потому что мне нужно определить, что входит в 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
Идеи?