CAS5.3.x 单点登录一--集成其他OAuth,ID格式简化

3 篇文章 0 订阅

项目场景:

使用CAS5实现单点登录,同时需要集成其他OAuth认证方式。对外提供OAuth2.0和OIDC服务,支持Client_ID及secret的动态管理,同时与业务系统进行关联。


问题描述

按照以下设置后,会出现后续无法找到对应Service的情况。CAS 5.3.X授权第三方(码云)登录_Coder_Knight的博客-CSDN博客_cas 第三方登录针对单点登录的配置,可以看我上一篇:CAS 5.3.x 单点登录https://blog.csdn.net/Coder_Knight/article/details/120720018Cas作为国外的 项目,所有集成了外网的很多第三方,github 、goole等,但是国内的第三方需要自己去配置,Cas也确实提供了配置,下面就去实现该功能吧# cas.authn.pac4j.oauth2[0].authUrl=# cas.authn.pac4j.oauth2[0].tokenUrl=# ca.https://blog.csdn.net/Coder_Knight/article/details/120740279

# 默认值false,设定true后,下面的principalAttributeId=email将作为类似主键替代ID
cas.authn.pac4j.typedIdUsed=true

#appid
cas.authn.pac4j.oauth2[0].id=
#分配秘钥
cas.authn.pac4j.oauth2[0].secret=
#授权接口
cas.authn.pac4j.oauth2[0].authUrl=
#token获取接口
cas.authn.pac4j.oauth2[0].tokenUrl=
#用户信息接口
cas.authn.pac4j.oauth2[0].profileUrl=
#返回ID的字段
cas.authn.pac4j.oauth2[0].profileAttrs.id=preferred_username
#自定义委托认证名称
cas.authn.pac4j.oauth2[0].clientName=Group4A
cas.authn.pac4j.oauth2[0].profileVerb=POST
cas.authn.pac4j.oauth2[0].usePathBasedCallbackUrl=false
#
cas.authn.pac4j.oauth2[0].principalAttributeId=id

只有typedIdUsed 设置为false,才可以正常使用。又因为返回的ID加了类名,故修改源代码:

AbstractPac4jAuthenticationHandler.java
    private String typePrincipalId(final String id, final UserProfile profile) {
/*        if (isTypedIdUsed) {
            return profile.getClass().getName() + UserProfile.SEPARATOR + id;
        }*/
        return id;
    }

同时修改:



解决方案:

        credentials.setTypedIdUsed(isTypedIdUsed);
        int n = id.indexOf( UserProfile.SEPARATOR);
        LOGGER.warn(" id=[{}] ",id);
        if(n>0) {
            if (profile.getAttributes() != null && profile.getAttributes().size() > 0) {
                String tmp = (String) profile.getAttributes().get("id");
                LOGGER.warn(" tmp= [{}]",tmp);

                if (StringUtils.isNotBlank(tmp))
                    id = tmp;
            }
            else {
                id = id.substring(n+1);
            }
        }
        LOGGER.warn("after, id= [{}]",id);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值