cas 4.0 返回更多信息

1.修改WEB-INF下的deployerConfigContext.xml
<bean id="attributeRepository" class="org.jasig.services.persondir.support.StubPersonAttributeDao"
        p:backingMap-ref="attrRepoBackingMap" />

<util:map id="attrRepoBackingMap">
    <entry key="uid" value="uid" />
    <entry key="eduPersonAffiliation" value="eduPersonAffiliation" /> 
    <entry key="groupMembership" value="groupMembership" />

</util:map>

替换为

<bean  class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao" id="attributeRepository" >         <constructor-arg index="0" ref="dataSource"/>         <constructor-arg index="1" value="SELECT id AS suid,`name`,mobile,mail FROM ebiz_mng_user where {0}"/>         <property name="queryAttributeMapping">             <map>                 <!--这里的key需写username和登录页面一致,value对应数据库用户名字段-->                 <entry key="username" value="user_name"/>             </map>         </property>         <property name="resultAttributeMapping">             <map>                 <!--key为对应的数据库字段名称,value为提供给客户端获取的属性名字,系统会自动填充值-->                 <entry key="suid" value="suid"/> <entry key="name" value="name"/> <entry key="mobile" value="mobile"/> <entry key="mail" value="mail"/>             </map>         </property>     </bean>

修改:

 <bean class="org.jasig.cas.services.RegexRegisteredService"               p:id="0" p:name="HTTP and IMAP" p:description="Allows HTTP(S) and IMAP(S) protocols"               p:serviceId="^(https?|imaps?)://.*" p:evaluationOrder="10000001"/>

--》

<bean class="org.jasig.cas.services.RegexRegisteredService"               p:id="0" p:name="HTTP and IMAP" p:description="Allows HTTP(S) and IMAP(S) protocols"               p:serviceId="^(https?|imaps?)://.*" p:evaluationOrder="10000001">

<!--允许放回属性->    <property name="allowedAttributes">     <list>     <value>suid</value>     <value>name</value>     <value>mobile</value>     <value>mail</value>     </list>   </property>     </bean>

2. 修改WEB-INF\view\jsp\protocol\2.0下的casServiceValidationSuccess.jsp

由原来的

<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationSuccess> <cas:user>${fn:escapeXml(assertion.primaryAuthentication.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:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationSuccess> <cas:user>${fn:escapeXml(assertion.primaryAuthentication.principal.id)}</cas:user>

<!--新增--> <c:if test="${fn:length(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes) > 0}">               <cas:attributes>                   <c:forEach var="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>           <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>

客服端获取:

AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
Map attributes = principal.getAttributes();
String email = (String)attributes.get("name");
参考文档:https://www.cnblogs.com/secsea/p/5177284.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当客户端应用程序使用CAS 2.0协议从CAS服务器中获取票据(ticket)时,可以使用以下步骤来验证票据并获取用户的属性信息: 1. 客户端应用程序将票据(ticket)发送到CAS服务器,以获取与该票据关联的用户属性信息。 2. CAS服务器验证票据,如果票据有效,则返回与该票据关联的用户属性信息。 3. 客户端应用程序可以解析返回的XML响应,以获取用户属性信息。 以下是一个示例XML响应: ``` <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationSuccess> <cas:user>johndoe</cas:user> <cas:attributes> <cas:firstName>John</cas:firstName> <cas:lastName>Doe</cas:lastName> <cas:email>johndoe@example.com</cas:email> </cas:attributes> </cas:authenticationSuccess> </cas:serviceResponse> ``` 在上面的示例中,`<cas:user>`元素包含与票据关联的用户名,`<cas:attributes>`元素包含其他用户属性信息。 客户端应用程序可以使用以下步骤来解析XML响应: 1. 使用XML解析器解析响应。 2. 使用XPath表达式获取所需的元素和属性。 例如,以下XPath表达式可以用于获取用户名: ``` /cas:serviceResponse/cas:authenticationSuccess/cas:user ``` 类似地,以下XPath表达式可以用于获取用户的电子邮件地址: ``` /cas:serviceResponse/cas:authenticationSuccess/cas:attributes/cas:email ``` 需要注意的是,CAS服务器返回的XML响应中可能包含不同的元素和属性,具体取决于服务器配置和应用程序要求。因此,在实际应用中,需要仔细查看CAS服务器文档,以了解响应中包含的元素和属性。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值