yangzongzhuan / RuoYi-Vue

:tada: (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统,同时提供了 Vue3 的版本
http://ruoyi.vip
MIT License
2.32k stars 1.28k forks source link

spring security配置多个WebSecurityConfigurerAdapter后,如何在service层获得AuthenticationManager实例? #27

Closed mcyustc closed 3 years ago

mcyustc commented 3 years ago
@Override
protected void configure(AuthenticationManagerBuilder auth) {
    DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
    daoAuthenticationProvider.setUserDetailsService(userDetailsService);
    daoAuthenticationProvider.setPasswordEncoder(new BCryptPasswordEncoder());
    auth.authenticationProvider(daoAuthenticationProvider);
}

如果向若依一样注入bean会导致启动失败

@Bean(name = "sellerAuthenticationManager")
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

所以这段代码只好删除。

那么如何在service层注入生效的AuthenticationManager呢?请大佬指点不胜感激

yangzongzhuan commented 3 years ago

这种问题和框架无关,可以自己去网上查询一下相关资料spring security配置多个实例