注入自定义身份验证管理器时出现问题

时间:2018-12-03 19:32:36

标签: spring spring-security spring-security-oauth2

我正在尝试使用自定义身份验证管理器,但是正在调用标准的提供程序管理器来进行.authenticate。我怀疑这与AuthSever或Web Config有关。任何帮助是极大的赞赏。

AuthServer配置:

@Configuration
@EnableAuthorizationServer
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {

@Autowired
private final DataSource dataSource;

@Autowired
public AuthServerConfig(DataSource dataSource){
    this.dataSource = dataSource;
}

@Autowired
MicrosJwtConfig microsJwtConfig;


@Autowired
@Qualifier("microsProviderManager")
AuthenticationManager authenticationManager;


public BCryptPasswordEncoder encoder(){
    return new BCryptPasswordEncoder(10);
}

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.jdbc(dataSource);
}


@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
    endpoints
            .tokenServices(microsJwtConfig.microsTokenServices())
            .authenticationManager(authenticationManager);
}

@Override
public void configure(AuthorizationServerSecurityConfigurer security) {
    security.allowFormAuthenticationForClients();
    security.passwordEncoder(encoder());
    security.tokenKeyAccess("permitAll()");
}
}

WebSecurity配置:

@EnableWebSecurity
@Configuration
public class WebSecConfig extends WebSecurityConfigurerAdapter {

@Autowired
private ClientDetailsService clientDetailsService;
@Autowired
private MECAuthenticationProvider mecAuthenticationProvider;

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return new MicrosProviderManager(clientDetailsService, mecAuthenticationProvider );
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests().antMatchers("actuator/health").permitAll().and()
            .authorizeRequests().antMatchers("oauth/token").permitAll().and()
            .authorizeRequests().antMatchers("actuator/info").permitAll();
}
}

0 个答案:

没有答案
相关问题