org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authorizationServerConfig': Unsatisfied dependency expressed through field 'authenticationManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.authentication.AuthenticationManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Hi I have spring-boot web app and I'm trying to implement login/authorization -authentication system using Spring Security and OAuth2 by following this example: https://www.youtube.com/watch?v=dTAgI_UsqMg&t=1307s
Every thing was good but when I run my application I get exception saying it can+t find bean for AuthenticationManager even thought it is there and autowired.
Looking across internet this seems like a know or common issue with Oauth2 but I can't find right workaround
Some people suggested to "expose" the AuthenticationManager bean, I'm not sure what that means in this context
This is link to my current project on github: https://github.com/chenchi13/spring-boot-cms
Can anyone help me figure this out?
class that is throwing exception:
@EnableResourceServer
@Configuration                                                      
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private AuthenticationManager authenticationManager;
    @Autowired
    private UserDetailsService customUserDetailService;
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.requestMatchers()
                .antMatchers("/login", "/oauth/authorize")
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .formLogin()
                .permitAll();
    }
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        //auth.parentAuthenticationManager(authenticationManager)
        //        .inMemoryAuthentication()
        //        .withUser("Peter")
        //        .password("peter")
        //        .roles("USER");
        auth.parentAuthenticationManager(authenticationManager)
                .userDetailsService(customUserDetailService);
    }
}
Authorization Server Config:
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
    @Autowired
    private AuthenticationManager authenticationManager;
    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.tokenKeyAccess("permitAll()")
                .checkTokenAccess("isAuthenticated()");
    }
    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients
                .inMemory()
                .withClient("ClientId")
                .secret("secret")
                .authorizedGrantTypes("authorization_code")
                .scopes("user_info")
                .autoApprove(true);
    }
    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager);
    }
}
 
     
    