IdP433: 2. 用CAS接口对接

        采用CAS提供CARSI身份认证功能,CARSI IdP通过CAS接口与学校身份认证系统对接。IdP自动安装脚本已经完成基本配置,与学校部署情况相关、需要修改的部分如下。

1.修改CAS对接参数

[carsi@www ~]$ sudo vi /opt/shibboleth-idp/conf/authn/authn.properties

#修改第102行配置,修改external.jsp为/Authn/External
idp.authn.External.externalAuthnPath = contextRelative:/Authn/External

#新增
idp.authn.flows = External

#CAS服务器访问地址
shibcas.casServerUrlPrefix = https://xxx.xxx.xxx.xxx/cas
shibcas.casServerLoginUrl = ${shibcas.casServerUrlPrefix}/login

#设置IdP的域名 ,例如https://idp.pku.edu.cn
shibcas.serverName = https://xxx.xxx.xxx.xxx
 
# CAS的协议默认为3.0,如果贵校CAS协议为2.0(请咨询CAS负责人),则增加以下配置:
shibcas.ticketValidatorName = cas20

2.配置属性定义

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

       注:需要修改下述principalAttributeName="userType"属性定义,此处userType是CAS服务器用于定义用户身份的字段,请咨询CAS服务器管理员并依据学校实际情况进行修改。 除了身份属性定义外,其他部分不需要修改。

[carsi@www ~]$ sudo vi /opt/shibboleth-idp/conf/attribute-resolver.xml
    
    <AttributeDefinition xsi:type="ScriptedAttribute" id="eduPersonScopedAffiliation">
        <InputAttributeDefinition ref="employeeType" />
        <Script><![CDATA[
		scopedValueType = Java.type("net.shibboleth.idp.attribute.ScopedStringAttributeValue");
        var localPart = "";
        if(typeof(employeeType)=="undefined"){
            localPart = "other";
        }else{
            if(employeeType.getValues().get(0)=="staff") localPart = "staff"; # if条件中“staff”为本地用户管理系统中属性取值,可能是“staf”或其他
			else if(employeeType.getValues().get(0)=="student") localPart = "student"; # if条件中“student”为本地用户管理系统中属性取值,可能是“stu”或其他
            else if(employeeType.getValues().get(0)=="faculty") localPart = "faculty"; # if条件中“faculty”为本地用户管理系统中属性取值,可能是“faculty”或其他
			else localPart = "member";
        }
        eduPersonScopedAffiliation.addValue(new scopedValueType(localPart, "%{idp.scope}"));
            ]]></Script>
        </AttributeDefinition>

    <AttributeDefinition xsi:type="SubjectDerivedAttribute" id="employeeType" principalAttributeName="userType"></AttributeDefinition>

[carsi@www ~]$ sudo systemctl restart jetty

下面是某学校属性配置文件样本,在下面的属性配置文件中,principalAttributeName="userType",其中userType是IdP从CAS服务器拿到的用户属性字段名称,该字段用于区别用户身份,请咨询CAS服务器管理员并获得该字段名称。

[carsi@www ~]$ sudo cat attribute-resolver.xml
<?xml version="1.0" encoding="UTF-8"?>

<AttributeResolver
        xmlns="urn:mace:shibboleth:2.0:resolver"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:mace:shibboleth:2.0:resolver http://shibboleth.net/schema/idp/shibboleth-attribute-resolver.xsd">


    <AttributeDefinition xsi:type="ScriptedAttribute" id="eduPersonScopedAffiliation">
        <InputAttributeDefinition ref="employeeType" />
        <Script><![CDATA[
		scopedValueType = Java.type("net.shibboleth.idp.attribute.ScopedStringAttributeValue");
        var localPart = "";
        if(typeof(employeeType)=="undefined"){
            localPart = "member";
        }else{
            if(employeeType.getValues().get(0)=="faculty") localPart = "faculty";
            else if(employeeType.getValues().get(0)=="std") localPart = "student";
            else localPart = "member";
        }
        eduPersonScopedAffiliation.addValue(new scopedValueType(localPart, "%{idp.scope}"));
            ]]></Script>
    </AttributeDefinition>

    <AttributeDefinition xsi:type="SubjectDerivedAttribute" id="employeeType" principalAttributeName="userType"></AttributeDefinition>

    <AttributeDefinition xsi:type="Scoped" id="eduPersonPrincipalName" scope="%{idp.scope}">
        <InputAttributeDefinition ref="uid"/>
    </AttributeDefinition>

    <AttributeDefinition id="uid" xsi:type="PrincipalName" />

    <AttributeDefinition id="eduPersonPrincipalName" xsi:type="Scoped" scope="%{idp.scope}">
        <InputAttributeDefinition ref="uid"/>
    </AttributeDefinition>

    <AttributeDefinition id="eduPersonTargetedID" xsi:type="SAML2NameID"
                         nameIdFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">
        <InputDataConnector ref="myStoredID" attributeNames="persistentID"/>
        <AttributeEncoder xsi:type="SAML1XMLObject" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" encodeType="false"/>
        <AttributeEncoder xsi:type="SAML2XMLObject" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10"
                          friendlyName="eduPersonTargetedID" encodeType="false"/>
    </AttributeDefinition>

    <AttributeDefinition id="samlPairwiseID" xsi:type="Scoped" scope="%{idp.scope}">
        <InputDataConnector ref="myStoredID" attributeNames="persistentID"/>
    </AttributeDefinition>

    <DataConnector id="myStoredID" xsi:type="StoredId" generatedAttributeID="persistentID"
                   salt="%{idp.persistentId.salt}" queryTimeout="0">
        <InputAttributeDefinition ref="eduPersonPrincipalName"/>
        <BeanManagedConnection>MyDataSource</BeanManagedConnection>
    </DataConnector>

    <AttributeDefinition id="eduPersonEntitlement" xsi:type="Simple">
        <InputDataConnector ref="staticAttributes" attributeNames="eduPersonEntitlement"/>
    </AttributeDefinition>

    <DataConnector id="staticAttributes" xsi:type="Static">
        <Attribute id="eduPersonEntitlement">
            <Value>urn:mace:dir:entitlement:common-lib-terms</Value>
        </Attribute>
    </DataConnector>


</AttributeResolver>

3. 配置属性释放

        IdP安装脚本已经完成属性释放配置,可不修改。

4. 检查并导入CAS Server证书

        为了保证IdP和CAS的通信安全,CARSI项目组建议采用https对接CAS服务端。

        如果访问CAS系统时,浏览器地址栏最左边为灰色小锁,表示证书正常。无需执行以下操作。

        如果CAS使用自签证书,浏览器显示红色三角图标,需在IdP端导入CAS证书,以保证IdP和CAS服务端正常通信。具体操作步骤如下:

1)通过浏览器访问CAS服务端,点击URL左边的红色三角,点击证书链接并查看详情。

2)点击右下角“导出”按钮,选择DER格式导出。

3)将导出的证书导入到IdP服务器的证书库中($JAVA_HOME/lib/security/cacerts)。可以使用keytool工具导入(需要先将上面导出的证书上传到IdP 服务器)

sudo keytool -importcert -keystore /$JAVA_HOME/lib/security/cacerts -storepass changeit -file ~/cert_file.der -alias "cas_cert"

4)重启Jetty。

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