CAS单点登录三-客户端获取登录信息
来源:互联网 发布:云墙mac破解版 编辑:程序博客网 时间:2024/06/06 22:39
通过上篇的配置,登录是从数据库中进行验证了。http://blog.csdn.net/redstarofsleep/article/details/51144809
那么现在要解决的问题是,客户端怎么知道登录者是谁呢?如何获取登录者的信息。
首先还是打开deployerConfigContext.xml这个配置文件
找到id为attributeRepository的bean。默认这个bean配置的应该是org.jasig.services.persondir.support.StubPersonAttributeDao,要把它换成org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao
配置如下:
<!--<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 id="attributeRepository"class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao"><constructor-arg index="0" ref="dataSource"/><constructor-arg index="1" value="select * from sampleUser where {0}"/><property name="queryAttributeMapping"><map><entry key="username" value="userName"/><!--key与登录页面一致,value对应数据库--></map></property><property name="resultAttributeMapping"><map><entry key="id" value="id"/><entry key="userName" value="userName"/></map></property></bean>这里面配置一个sql语句,根据用户名查询用户属性。然后resultAttributeMapping这个属性是配置的返回结果,key对应数据库字段,value对应客户端获取时的名字。
然后再找一下credentialsToPrincipalResolvers,里面默认应该有一个
<bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" > <property name="attributeRepository" ref="attributeRepository" /></bean>没有的话,把它加上。
再下一步就是再在这个配置文件中找org.jasig.cas.services.InMemoryServiceRegistryDaoImpl这个bean。在其中的org.jasig.cas.services.RegexRegisteredService的属性中加上需要返回的字段:
<beanid="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" /><!-- ******* add start ******* --><property name="allowedAttributes"><list><value>id</value><value>userName</value></list></property><!-- ******* add end ******* --> </bean>我这里只是加了id和userName。
好了,保存这个文件。
最后找到view/jsp/protocol/2.0/casServiceValidationSuccess.jsp
在里面加一段
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><cas:authenticationSuccess><cas:user>${fn:escapeXml(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.id)}</cas:user><!-- 新加 start--><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><!-- 新加 end--><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>
好了,server端配置完成,可以重启tomcat了。
然后,客户端要获取属性这些属性,我这里是把这些属性全部遍历出来了。
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();Map<String, Object> attributes = principal.getAttributes();for (String key : attributes.keySet()) {System.out.println(key + "/" + attributes.get(key));}
转载请注明出处:http://blog.csdn.net/redstarofsleep
2 0
- CAS单点登录三-客户端获取登录信息
- Cas单点登录客户端配置
- Mvc4单点登录之三Cas 客户端配置
- 单点登录学习(3)CAS客户端配置
- 单点登录(四)cas客户端配置
- cas 单点登录服务端客户端配置
- CAS单点登录源码解析之【客户端】
- CAS单点登录python客户端分析
- CAS单点登录客户端--C++版
- CAS单点登录服务端与客户端配置
- 单点登录(八)cas支持客户端登录——客户端
- CAS客户端.NET集成单点登录获取不到登录用户信息的问题
- 单点登录(三)cas服务端配置
- CAS单点登录-配置中心(三)
- CAS 制作单点登录登录后跳转客户端页面出错
- 单点登录(七)cas支持客户端登录——服务器端
- CAS单点登录-客户端集成(cas-client)(九)
- 单点登录CAS系列8-客户端配置单点登出
- CollapsingToolbarLayout可折叠的toolbar
- java中的数据结构
- android 5.0以上获取前台应用的包名
- UIScrollView 属性(全)
- CF 122A. Lucky Division
- CAS单点登录三-客户端获取登录信息
- HTML 5 参考手册(Canvas)
- Kafka设计解析(四):Kafka Consumer解析
- Storm 1.0.0 发布
- 12年程序员职业生涯得到的12个经验教训:转
- 三、runtime之消息(三)
- Java获取两个字符串中最大相同子串
- iOS中磨砂视图的实现和总结blurEffectView
- Android 5.0以后版本打开“有权查看使用情况的应用”