【问题标题】:Get LDAP user attributes from CAS从 CAS 获取 LDAP 用户属性
【发布时间】:2013-12-14 15:08:52
【问题描述】:

我现在在将 CAS 与 LDAP 结合使用时遇到了一些问题。我想为多个应用程序实施 SSO 解决方案。到目前为止,身份验证效果很好。我们希望根据用户在 LDAP 中配置的角色来授权用户。问题是 CAS 不提供用户角色。

到目前为止,我知道deployerConfigContext.xml 需要配置。我还找到了各种教程,大多数都使用了错误版本的 CAS,或者没有按照我的意愿去做。

我们的用户位于cn=admin,cn=users,dc=manager,dc=local,群组位于cn=admins,ou=groups,dc=manager,dc=local。 CAS版本是3.5.2

我尝试过像这样插入:

<bean id="attributeRepository" class="org.jasig.services.persondir.support.StubPersonAttributeDao">
    <property name="backingMap">
        <map>
            <entry key="uid" value="uid" />
            <entry key="eduPersonAffiliation" value="eduPersonAffiliation" />
            <entry key="groupMembership" value="groupMembership" />
        </map>
    </property>
    <property name="query" value="(uid={0})" />
    <property name="contextSource" ref="contextSource" />
    <property name="ldapAttributesToPortalAttributes">
        <map>
            <entry key="cn" value="Name" />
            <entry key="home" value="homeDirectory" />
        </map>
    </property>
</bean>

CAS 告诉我他不喜欢 querycontextSourceldapAttributesToPortalAttributes 的属性。我想获取“简单”属性 homeDirectory。

你们中的任何人都可以给我一些关于如何配置那个邪恶的 xml 文件的提示吗?如果你愿意,我也可以提供完整的 xml 文件。

更新

经过一番摆弄,我尝试在此站点上配置attributeRepositoryhttps://wiki.jasig.org/display/CASUM/Attributes 在章节Populate Principal's attributes with LDAP repository 中。结果是 CAS 没有启动,而是给了我消息

Bean property 'ldapAttributesToPortalAttributes' is not writable or has an invalid setter method.

我的attributeRepository 看起来像这样:

<bean id="attributeRepository"  class="org.jasig.services.persondir.support.ldap.LdapPersonAttributeDao">
    <property name="ldapAttributesToPortalAttributes">
        <map>
            <entry key="cn" value="Name" />
            <entry key="home" value="homeDirectory" />
        </map>
    </property>
</bean>

【问题讨论】:

    标签: ldap single-sign-on cas ldap-client


    【解决方案1】:

    我有以下豆

    <bean id="attributeRepository"
        class="org.jasig.services.persondir.support.ldap.LdapPersonAttributeDao">
        <property name="baseDN" value="ou=groups,dc=manager,dc=local"/>     
        <property name="contextSource" ref="contextSource" />
        <property name="requireAllQueryAttributes" value="true"/>
        <property name="queryAttributeMapping">
            <map>
                <entry key="username" value="sAMAccountName" />
            </map>
        </property>     
        <property name="resultAttributeMapping">
            <map>               
                <entry key="displayName" value="cn" />
            </map>
        </property>
    </bean>
    

    您将 displayName 属性映射为 cn。在你的 deployerConfigContext.xml 下面的行你会发现 allowedAttributes,如果它不存在你可以添加。使用它,您将在会话中加载该信息。

    <bean
        id="serviceRegistryDao"
        class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
            <property name="registeredServices">
                <list>
                    <bean class="org.jasig.cas.services.RegexRegisteredService">
                        <property name="id" value="0" />
                        <property name="name" value="HTTP and IMAP" />
                        <property name="description" value="Allows HTTP(S) and IMAP(S) protocols" />
                        <property name="serviceId" value="^(https?|imaps?)://.*" />
                        <property name="evaluationOrder" value="10000001" />
                        <property name="allowedAttributes">
                            <list>
                                <value>cn</value>
                            </list>
                        </property> 
                    </bean>                    
                </list>
            </property>
        </bean>
    

    为了从 CAS 中返回这些值,请修改 casServiceValidationSuccess.jsp(位于 WEB-INF/view/jsp/protocol/2.0)

    <cas:attributes>
    <c:forEach var="auth" items="${assertion.chainedAuthentications}">
    <c:forEach var="attr" items="${auth.principal.attributes}" >
    <cas:${fn:escapeXml(attr.key)}>${fn:escapeXml(attr.value)}        </cas:${fn:escapeXml(attr.key)}>
    </c:forEach>
    </c:forEach>
    </cas:attributes>
    

    【讨论】:

    • 我将 bean 与我在 deployerContext.xml 中的设置进行了比较,并将缺少的属性“allowedAttributes”添加到 serviceRegistryDao。现在我可以打开 CAS“管理服务”页面并在我的应用程序中分配我需要的属性。这样可行。有没有办法通过配置文件来做这个分配?
    • 如果您想从 ldap 返回更多值,请在 attributeRepository bean 中的此属性 resultAttributeMapping 中添加更多条目并将它们放置别名。这些别名必须映射到 serviceRegistryDao bean 中的 allowedAttributes
    • 我将serviceRegistryDao改成使用数据库进行配置存储。见这里:wiki.jasig.org/display/CASUM/Configuring
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 2011-06-20
    • 2017-08-05
    相关资源
    最近更新 更多