栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

项目场景:

使用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) {

        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);
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1006287.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号