1、用LDAP接口对接

1. 修改LDAP对接参数

[root@www ~]# vi /opt/shibboleth-idp/conf/ldap.properties
idp.authn.LDAP.ldapURL = ldap://ldap服务器IP地址
idp.authn.LDAP.baseDN = ou=People,dc=Test,dc=Test 
#本地ldap配置中人员所在分支
idp.authn.LDAP.bindDN = cn=Manager,dc=Test,dc=Test 
#登录本地ldap服务器的用户名
idp.authn.LDAP.bindDNCredential = 密码 
#登录本地ldap服务器的密码
idp.authn.LDAP.userFilter = (uid={user}) 
#用哪个属性唯一标识用户,即用户登录的用户名对应 LDAP 内的哪条属性。示例中为“uid”,如果您使用 AD 作为 LDAP,那么这里通常需要修改为(sAMAccountName={user})
idp.attribute.resolver.LDAP.searchFilter = (uid=$resolutionContext.principal) 
#“uid”用法与上一行相同,根据本地ldap的实际配置修改为对应的用户标识属性名

        因LDAP服务器配置差异,请和本地LDAP管理员确认以上配置,需要了解本校LDAP的目录结构以及字段定义后再做修改。以上属性在ldap.properties文件中已经定义好,请勿直接拷贝添加到ldap.properties,会造成属性重复定义,其他未提到的属性按照ldap.properties默认配置即可。

        如果LDAP中不是用“uid”来唯一区别用户,请修改成本地LDAP中采用的用户标识名。比如在使用 AD 的情况下,通常使用 sAMAccountName 作为唯一标识,则该部分的配置应该如下所示

idp.authn.LDAP.userFilter = (sAMAccountName={user})
idp.attribute.resolver.LDAP.searchFilter = (sAMAccountName=$resolutionContext.principal)

        注:强烈建议先在IdP所在的服务器上测试一下对本校LDAP的连接性,以及查看一下LDAP管理员提供的属性及其取值是否正确。华东师范大学冯骐老师分享了一个轻量级的 LDAP测试工具 https://github.com/shanghai-edu/ldap-test-tool , 可以用来进行测试。或使用类似LDAP Browser或LDAP Admin这样的工具,在IdP所在服务器进行验证,以排除环境问题的影响。

2.配置属性定义

        eduPersonScopedAffiliation属性,取值为用户在学校的身份,其中的“userType”为本地LDAP中确定用户身份的属性名称,请替换成实际使用的属性名。关于身份属性取值,需要将本地用户身份的取值(如下面代码所示的staf和std),对应到CARSI联盟标准取值,包括:faculty(教师),student(学生),staff(教工),employee(雇员),member(各类人员,包括faculty、student、staff、employee),alum(校友),affiliate(附属人员或临聘,常用),other(CARSI补充,不建议优先使用)。下文样例,将所有的本地用户区分为“staff”、“student”、“member”三种身份。学校可根据本地LDAP实际部署情况选取其中的一部分值。不同SP对用户身份的要求不同,建议配置时尽可能细化用户身份分类,避免后期修改配置。

        目前对于ldap中用目录来区分用户身份的情况,建议还是在ldap中添加描述用户身份的字段,再进行配置。

        注:只需要修改下述eduPersonScopedAffiliation属性定义即可,其他内容不需要修改

[root@www ~]# vi /opt/shibboleth-idp/conf/attribute-resolver.xml
    <AttributeDefinition xsi:type="ScriptedAttribute" id="eduPersonScopedAffiliation">
        <InputDataConnector ref="myLDAP" attributeNames="usertype"/>
        <Script><![CDATA[
        var localpart = "";
        if(usertype.getValues().get(0)=="staf") localpart = "staff";
        else if(usertype.getValues().get(0)=="std") localpart = "student";
        else localpart = "member";
        eduPersonScopedAffiliation.addValue(localpart + "@%{idp.scope}");
            ]]></Script>
        <AttributeEncoder xsi:type="SAML1String" name="urn:mace:dir:attribute-def:eduPersonScopedAffiliation" encodeType="false" />
        <AttributeEncoder xsi:type="SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" friendlyName="eduPersonScopedAffiliation" encodeType="false" />
    </AttributeDefinition>
[root@www ~]# sudo systemctl restart tomcat9

        eduPersonTargtedID是一个永久可用的用户唯一id。通过hash算法加密之后,可读性不强。适用于需要区分不同用户的应用场景,同时保护了用户个人隐私。       

        修改eduPersonTargtedID加密盐值,可以使用如下指令生成随机字符串,并将idp.persistentId.salt = xxxxxxxxxxxxxxxxxxxx中的xxxxxxxxxxxxxxxxxxxx修改成生成的随机字符串

        注意:如果是进行IdP的升级,为了保证生成的eduPersonTargtedID一致,请沿用旧IdP的加密盐值,旧的加密盐值请参考IdP3.4.7备份恢复及高可用方案

[root@www ~]# openssl rand -base64 32
aesqnxtO+Di26xM78kXY6yD2m0QCK+0p68i7j7jQL8k=
[root@www ~]# vi /opt/shibboleth-idp/conf/saml-nameid.properties
idp.persistentId.sourceAttribute = eduPersonPrincipalName
idp.persistentId.salt = xxxxxxxxxxxxxxxxxxxx
idp.persistentId.encoding = BASE64
idp.persistentId.dataSource = MyDataSource

版权所有©北京大学计算中心