Spring boot Security Config - authenticationManager must be specified
In order to keep Component annotation you have to override setAuthenticationManager from AbstractAuthenticationProcessingFilter and autowire the parameter like this:
@Component
public class TokenProcessingFilter extends UsernamePasswordAuthenticationFilter {
//...
@Override
@Autowired
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
super.setAuthenticationManager(authenticationManager);
}
//...
}
You need to set the AuthenticationManager
on TokenProcessingFilter
. Instead of using @Component on TokenProcessingFilter, just create it in the SecurityConfig.
@Bean
TokenProcessingFilter tokenProcessingFilter() {
TokenProcessingFilter tokenProcessingFilter = new TokenProcessingFilter();
tokenProcessingFilter.setAuthenticationManager(authenticationManager());
return tokenProcessingFilter;
}
and
protected void configure(HttpSecurity http) throws Exception {
...
.addFilter(tokenProcessingFilter())