RuoYi-Vue前后端分离版集成cas 并保留原有登录方式

RuoYi-Vue前后端分离版集成cas 并保留原有登录方式

集成CAS

最近项目里需要接入第三方CAS完成单点登录,项目基于RuoYi-Vue就找了相关方案

  1. https://blog.csdn.net/weixin_42362592/article/details/120242975
  2. https://baijiahao.baidu.com/s?id=1758262582399757480

根据以上方案成功讲CAS接入后台

保留原有登录

直接访问login页面进行登录报错

"No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken"

排查错误原因
找了到了几篇文章

  1. https://blog.csdn.net/zhouzhiwengang/article/details/112589477
  2. https://blog.csdn.net/u012760435/article/details/126558412
  3. https://blog.csdn.net/u012760435/article/details/126577799
  4. https://blog.csdn.net/u012760435/article/details/126587994

综合看了少了原有登录的AuthenticationProvider,那就配置呗

接着有考虑这算是Security多登录方式就重点参考了这方面,也找了不少资料

  1. https://blog.csdn.net/liuminglei1987/article/details/108693182
  2. https://blog.csdn.net/weixin_48343233/article/details/133817165
  3. https://blog.csdn.net/wdwlbsm1/article/details/134568479
  4. https://blog.csdn.net/ii950606/article/details/128485787#t3

看了一些方案,就找了最小改动的资料,主要都是改configure(AuthenticationManagerBuilder auth)
加上auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
原有配置

 /**
     * 身份认证接口
     */
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        if (casProperties.isCasEnable()) {
            super.configure(auth);
            auth.authenticationProvider(casAuthenticationProvider());
        } else {
            auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
        }
    }

更改后

 /**
     * 身份认证接口
     */
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        if (casProperties.isCasEnable()) {
            super.configure(auth);
            // 补充原有登录
            auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
            auth.authenticationProvider(casAuthenticationProvider());
        } else {
            auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
        }
    }

改完运行,一看还是不行,就排查看看到底provider有没有放到ProviderManager里,debug在ProviderManagerauthenticate方法里打断点

AuthenticationException lastException = null;
        AuthenticationException parentException = null;
        Authentication result = null;
        Authentication parentResult = null;
        int currentPosition = 0;
        int size = this.providers.size();
        Iterator var9 = this.getProviders().iterator();

这一查this.providers.size里就一个,DaoAuthenticationProvider,我的casAuthenticationProvider去哪了??
仔细对比了之前参考的资料发现了区别,我多了个super.configure(auth);
注释掉再运行,终于可以了。
最终只有配置

/**
     * 身份认证接口
     */
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception
    {
        if (casProperties.isCasEnable()) {
            auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
            auth.authenticationProvider(casAuthenticationProvider());
        } else {
            auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
        }
    }
  • 21
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值