Как внедрить AuthenticationManager с использованием конфигурации Java в пользовательский фильтр

Я использую Spring Security 3.2 и Spring 4.0.1

Я работаю над преобразованием xml config в конфигурацию Java. Когда я аннотирую AuthenticationManager с @Autowired в моем @Autowired , я получаю исключение

 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 

Я попытался ввести AuthenticationManagerFactoryBean но это также не удается с аналогичным исключением.

Вот конфигурация XML, с которой я работаю

                        

Вот Java Config, который я пытаюсь

 @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private UserDetailsService userDetailsService; @Autowired private PasswordEncoder passwordEncoder; @Autowired private AuthenticationEntryPoint authenticationEntryPoint; @Autowired private AccessDeniedHandler accessDeniedHandler; @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); } @Override protected void configure(HttpSecurity http) throws Exception { http .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .exceptionHandling() .authenticationEntryPoint(authenticationEntryPoint) .accessDeniedHandler(accessDeniedHandler) .and(); //TODO: Custom Filters } } 

И это class Custom Filter. Линия, которая вызывает у меня проблемы, – это установщик для AuthenticationManager

 @Component public class TokenAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter { @Autowired public TokenAuthenticationProcessingFilter(@Value("/rest/useAuthenticationManagerr/authenticate") String defaultFilterProcessesUrl) { super(defaultFilterProcessesUrl); } @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { ... } private String obtainPassword(HttpServletRequest request) { return request.getParameter("password"); } private String obtainUsername(HttpServletRequest request) { return request.getParameter("username"); } @Autowired @Override public void setAuthenticationManager(AuthenticationManager authenticationManager) { super.setAuthenticationManager(authenticationManager); } @Autowired @Override public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler) { super.setAuthenticationSuccessHandler(successHandler); } @Autowired @Override public void setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler) { super.setAuthenticationFailureHandler(failureHandler); } } 

Переопределить метод authenticationManagerBean в WebSecurityConfigurerAdapter чтобы открыть AuthenticationManager, созданный с помощью configure(AuthenticationManagerBuilder) в качестве компонента Spring:

Например:

  @Bean(name = BeanIds.AUTHENTICATION_MANAGER) @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } 
  • Как перенаправить на домашнюю страницу, если пользователь обращается к странице входа после входа в систему?
  • Тестирование модhive с помощью Spring Security
  • Весенняя страница входа в систему безопасности
  • Сиро против SpringSecurity
  • Пользовательский фильтр Spring Security (сменить пароль)
  • Как настроить Spring Security SecurityContextHolder?
  • Spring Security 3.2 Поддержка CSRF для многопрофильных запросов
  • Как передать дополнительный параметр с помощью страницы входа в систему безопасности весны
  • Безопасность Spring и аутентификация JSON
  • Может ли Spring Security использовать @PreAuthorize для методов весенних controllerов?
  • Как управлять исключениями, сброшенными фильтрами весной?
  • Давайте будем гением компьютера.