cas返回更多用户信息_第1页
cas返回更多用户信息_第2页
cas返回更多用户信息_第3页
cas返回更多用户信息_第4页
cas返回更多用户信息_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

让CAS返回更多用户信息XML修改(deployerConfigContext.xml1.找到serviceRegistryDao这个节点,将里面的内容全部注释掉:Xml代码1.<beanid="serviceRegistryDao"class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">2.<!--<propertyname="registeredServices">3.<list>4.<beanclass="org.jasig.cas.services.RegisteredServiceImpl5.6.7.">〈property<property<propertyname="id"value="0"/>name="name"value="HTTP"/>name="description"value="OnlyAllowsHTTPUrls"/>8.9.<property</bean>name8.9.<property</bean>name="serviceId"value="http://**"/>10.11.<beanclass="org.jasig.cas.services.RegisteredServiceImpl11.">12.<propertyname="id"value="1"/>13.<propertyname="name"value12.<propertyname="id"value="1"/>13.<propertyname="name"value="HTTPS"/>14.<propertyname="description"value="OnlyAllowsHTTP15.16.SUrls"/><property</bean>name="serviceId"value="https://**"/>17.18.<beanclass="org.jasig.cas.services.RegisteredServiceImpl18.">19.<propertyname="id"value="2"/>20.<propertyname="name"value19.<propertyname="id"value="2"/>20.<propertyname="name"value="IMAPS"/>21.<propertyname="description"value="OnlyAllowsHTTP22.23.SUrls"/><property</bean>name="serviceId"value="imaps://**"/>24.25.<beanclass="org.jasig.cas.services.RegisteredServiceImpl25.">26.〈propertyname="id"value="3"26.〈propertyname="id"value="3"/>27.<propertyname="name"value="IMAP"/>28.〈propertyname="description"value="OnlyAllowsIMAPUrls"/>29.30.〈property</bean>29.30.〈property</bean>name="serviceId"value="imap://**"/>31.</list>31.P32. </property>-->33.</bean>此节点的作用为:如果你在<list>中加入了bean,并设定了serviceld的value,那么通过CAS你只能访问这个url地址,其他的url地址将不能访问,**代表的意思就是指该协议下所有的都允许被访问。但是在实际操作中,加入如果不注释掉里面的内容,将会在客户端无法获取到用户更多的登录信息。2.<beanclass="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver”/>改为:<beanclass="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver”><propertyname="attributeRepository"ref="attributeRepository"/></bean>数据库获取更多信息配置如下:然后在配置文件的根节点(<beans>)下加入以下XML配置:Xml代码两1.<beanid="attributeRepository"class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao">2.<constructor-argindex="0"ref="dataSource"/>3.<constructor-argindex="1"value="select*fromportal_userwhere{0}"/>4.<propertyname="queryAttributeMapping">5. <map><entrykey="username"value="id"/></map></property><propertyname="resultAttributeMapping">10. <map>11. <entry key="id"value="UserId"/>12.13. <entry key="sessionid"value="UserName"/>14. <entry key="uclass"value="UserClass"/>15. </map>16.</property>17.</bean>其中的sql语句可以根据自己的情况来写。下面resultAttributeMapping中的参数解释如下:<entrykey="id"value="UserId"/>key代表的是你数据库中的字段,Value是客户端通过AttributePrincipal获取时的参数LDAP获取更多信息配置如下<beanid="attributeRepository”class="org.jasig.services.persondir.support.ldap.LdapPersonAttributeDao"><propertyname="contextSource"ref="contextSource"/><propertyname="baseDN"value="ou=honest,dc=archer06,dc=com”/><propertyname="requireAllQueryAttributes"value="true”/><!--Attributemappingbeetweenprincipal(key)andLDAP(value)namesusedtoperformtheLDAPsearch.Bydefault,multiplesearchcriteriaareANDedtogether.SetthequeryTypepropertytochangetoOR.--><propertyname="queryAttributeMapping"><map><entrykey="username"value="cn”/></map></property><propertyname="resultAttributeMapping"><map><!--MappingbeetweenLDAPentryattributes(key)andPrincipal's(value)--><entrykey="sn"value="sn”/><entrykey="userIp"value="userIp"/><entrykey="userPassword"value="userPassword"/><entryvalue="Telephone"key="telephoneNumber"/><entryvalue="Fax"key="facsimileTelephoneNumber"/></map></property></bean>CAS登录获取更多用户信息的JSP修改仅仅是修改xml是不够的,你必须修改他的casServiceValidationSuccess.jsp,路径为:X:\tomcat-cas-server\webapps\cas\WEB-INF\view\jsp\protocol\2.0在其中紧接着加入以下代码:(红色部分)<%@pagesession="false”%><%@taglibprefix="c”uri="/jsp/jstl/core"%><%@tagliburi="/jsp/jstl/functions"prefix="fn”%><cas:serviceResponsexmlns:cas='/tp/cas'><cas:authenticationSuccess><cas:user>${fn:escapeXml(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.id)}</cas:user><c:iftest="${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:attribute><cas:name>${fn:escapeXml(attr.key)}</cas:name><cas:value>${fn:escapeXml(attr.value)}</cas:value></cas:attribute></c:forEach></cas:attributes></c:if><c:iftest="${notemptypgtIou}"><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></cas:authenticationSuccess></cas:serviceResponse>客户端获取返回信息通过完成上面三个步骤的配置后,server端的工作就完成了,那么如何在客户端获取这些信息呢?下面进行说明:获取远程用户request.getRemoteUser。获取其他信息AttributePrincipalprincipal=(AttributePrincipal)request.getUserPrincipal();Mapattributes=principal.getAttributes();备注:总体来说,cas的代码结构不是很完善,尤其是客户端,从2.x到3.x,代码结构基本是进行了翻天覆地的重构,另外获取客户端信息时,也是只有最新版本的3.1.1才支持,之前的版本是不支持的,请一定要注意。对于2.x版本的要获取用户的返回信息需要重新解析xml修改客户端的源码,3.x版本忽略一下内容返回的格式如下response=<cas:serviceResponsexmlns:cas='/tp/cas'><cas:authenticationSuccess><cas:user>admin</cas:user><cas:attributes><cas:attribute><cas:name>user

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论