CAS SERVER返回更多用户信息给客户端

1、casServiceValidationSuccess.jsp文件
此文件是将用户登录成功后,将信息生成XML传递给客户端,原文件是只包含name信息,所以需要修改:
<%@page pageEncoding="UTF-8"%><%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<cas:serviceResponsexmlns:cas='http://www.yale.edu/tp/cas'>
<!--
    <cas:authenticationSuccess>
        <cas:user>${fn:escapeXml(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.id)}</cas:user>
<c:if test="${not empty pgtIou}">
        <cas:proxyGrantingTicket>${pgtIou}</cas:proxyGrantingTicket>
</c:if>
<c:if test="${fn:length(assertion.chainedAuthentications) > 1}">
        <cas:proxies>
<c:forEach var="proxy" items="${assertion.chainedAuthentications}" varStatus="loopStatus" begin="0" end="${fn:length(assertion.chainedAuthentications)-2}" step="1">
            <cas:proxy>${fn:escapeXml(proxy.principal.id)}</cas:proxy>
</c:forEach>
        </cas:proxies>
</c:if>
    </cas:authenticationSuccess>
</cas:serviceResponse>-->
 
    <cas:authenticationSuccess>
        <cas:user>${fn:escapeXml(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.id)}</cas:user>               
        <c:iftest="${not empty pgtIou}">
                <cas:proxyGrantingTicket>${pgtIou}</cas:proxyGrantingTicket>
        </c:if>
        <c:iftest="${fn:length(assertion.chainedAuthentications) > 1}">
                <cas:proxies>
                <c:forEachvar="proxy"items="${assertion.chainedAuthentications}"varStatus="loopStatus"begin="0"end="${fn:length(assertion.chainedAuthentications)-2}"step="1">
                            <cas:proxy>${fn:escapeXml(proxy.principal.id)}</cas:proxy>
                </c:forEach>
                </cas:proxies>
        </c:if>
        <!-- 在server验证成功后,这个页面负责生成与客户端交互的xml信息,在默认的casServiceValidationSuccess.jsp中,只包括用户名,并不提供其他的属性信息,因此需要对页面进行扩展 -->
        <c:iftest="${fn:length(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes) > 0}">  
            <cas:attributes>  
                <c:forEachvar="attr"items="${assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes}">                            
                    <cas:${fn:escapeXml(attr.key)}>${fn:escapeXml(attr.value)}</cas:${fn:escapeXml(attr.key)}>                                
                </c:forEach>    
            </cas:attributes>  
        </c:if>
    </cas:authenticationSuccess>
</cas:serviceResponse>

2、deployerConfigContext.xml文件
注释这个bean:
<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>
</bean>
添加这个bean:
<bean id="attributeRepository" class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao">
        <constructor-arg index="0" ref="dataSource" />
        <constructor-arg index="1" value="SELECT * FROM users WHERE {0}" />
        <property name="queryAttributeMapping">
            <map>
                <entry key="username" value="username" />           注:此处key为数据表users中的列属性,value为自定义;下同
            </map>
        </property>
        <property name="resultAttributeMapping">
            <map>
                <entry key="username" value="username" />
                <entry key="company" value="company" />
                <entry key="email" value="email" />
            </map>
        </property>
    </bean>
3、org.jasig.cas.services.InMemoryServiceRegistryDaoImpl,这里特别重要,此bean中的ignoreAttributes属性默认是不添加用户信息
private boolean ignoreAttributes = true;//决定是否添加attributes属性内容,影响向客户端传递更多信息

<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>username</value>
<value>company</value>
<value>email</value>
</list>
</property>-->
<property name="ignoreAttributes" value="true" /> 
                    </bean>
在serviceRegistryDao这个bean中默认没有<property name="ignoreAttributes" value="true" />,添加到所示位置
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值