• Now all data be ready for publish, We had made our blog alive now. Haha.

  • These days CCP GFW blocked all the IPs from US and when I switch my IP in google Cloud, the disk data cannot be restore again. I have to restart my blog totally, Now the website is still building…

How To Inject AuthenticationManager using Java Configuration in a Custom Filter- Stack Overflow

Java PingBook 1 months ago (10-23) 17 0


I’m using Spring Security 3.2 and Spring 4.0.1

I’m working on converting an xml config into a Java config. When I annotate AuthenticationManager with @Autowired in my Filter, I’m getting an exception

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: {}

I’ve tried injecting AuthenticationManagerFactoryBean but that also fails with a similar exception.

Here is the XML configuration I’m working from

Here is the Java Config I’m attempting

public class SecurityConfig extends WebSecurityConfigurerAdapter {

private UserDetailsService userDetailsService;

private PasswordEncoder passwordEncoder;

private AuthenticationEntryPoint authenticationEntryPoint;

private AccessDeniedHandler accessDeniedHandler;

protected void configure(AuthenticationManagerBuilder auth) throws Exception {

protected void configure(HttpSecurity http) throws Exception {
//TODO: Custom Filters

And this is the Custom Filter class. The line giving me trouble is the setter for AuthenticationManager

public class TokenAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter {

public TokenAuthenticationProcessingFilter(@Value(“/rest/useAuthenticationManagerr/authenticate”) String defaultFilterProcessesUrl) {

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”);

public void setAuthenticationManager(AuthenticationManager authenticationManager) {

public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler) {

public void setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler) {


Override method authenticationManagerBean in WebSecurityConfigurerAdapter to expose the AuthenticationManager built using configure(AuthenticationManagerBuilder) as a Spring bean:

For example:

public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();

Copyright from PingBook Blog, If not specified, they are original. This site uses BY-NC-SAProtocol authenticated.
For reprinting, please indicate the link of the original text:How To Inject AuthenticationManager using Java Configuration in a Custom Filter- Stack Overflow
LIKE (0)
We create, We sharing! Tag every value data your sharing
Submit comments
Cancel comments
emoji picture bold strikethrough center italic check in

Hi,you need to provide your name and email adress!

  • Name (Required)
  • Email (Required)
  • Website