0

I was looking through similar questions, but did not find anything that helped:

In my spring security configuration class I configure my AuthenticationManager like this (to use a UserDetailsService implementation). I have read, that this should configure a global authentication manager to use.

@EnableWebMvc
@EnableWebSecurity
@ComponentScan
@Configuration
public class WebMvcConfig extends WebSecurityConfigurerAdapter implements WebMvcConfigurer {
    
    // Other things...

    @Autowired
    @Qualifier("authenticationManager")
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
    }

}

My question is: How to use it in a custom controller? If I try it like this ...

@Controller
@RequestMapping(value = "/perform_login", method = RequestMethod.POST)
public class LoginController {
    
    @Resource
    private AuthenticationManager authenticationManager;

    @GetMapping
    public ModelAndView login(

        // login logic using the authenticationManager
    }
    
}

... then it says, that no bean of type AuthenticationManagerBuilder is available. So please help me out: Where is my misunderstanding? How can I actually use the AuthenticationManager?

DanielBK
  • 892
  • 8
  • 23
  • Replace `@Autowired` with `@Override`, since you are implementing the `configure` method from the `WebSecurityConfigurerAdapter` superclass. --- You should remove `@Qualifier` too. – Andreas Jul 05 '20 at 12:44
  • Yeah, I tried it with Override too in the beginning. But I finally found the solution: I need to use Override AND add an extra bean method like here https://stackoverflow.com/questions/21633555/how-to-inject-authenticationmanager-using-java-configuration-in-a-custom-filter – DanielBK Jul 05 '20 at 12:51

0 Answers0