Как внедрить 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
но это также не удается с аналогичным исключением.
- Как создать пользовательские методы для использования в выражениях выражения выражения весны безопасности
- Пользовательский менеджер проверки подлинности с функцией Spring Security и Java Configuration
- Как исправить роль в Spring Security?
- Spring Security с ролями и разрешениями
- Аутентификация базы данных Spring Security 3 с Hibernate
Вот конфигурация 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); } }
- При использовании Spring Security, каков правильный способ получить текущее имя пользователя (например, SecurityContext) в компоненте?
- Отключить Spring Security для OPTIONS Http Method
- Возможно ли аннулировать сеанс безопасности весны?
- Почему это приложение Spring с настройкой на основе Java не работает должным образом
- Как отключить весеннюю безопасность для определенного URL-адреса
- Как вручную установить аутентифицированного пользователя в Spring Security / SpringMVC
- Выход из режима ожидания / сеанса ожидания с весной
- JAAS для людей
Переопределить метод authenticationManagerBean
в WebSecurityConfigurerAdapter
чтобы открыть AuthenticationManager, созданный с помощью configure(AuthenticationManagerBuilder)
в качестве компонента Spring:
Например:
@Bean(name = BeanIds.AUTHENTICATION_MANAGER) @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); }