CAS (14) —— CAS 更多用户信息
CAS (14) —— CAS 更多用户信息
摘要
将更多用户信息写入到service验证返回消息中
版本
tomcat版本: tomcat-8.0.29
jdk版本: jdk1.8.0_65
cas版本: 4.1.3
**cas4.1.3 (4.x还在开发过程中不是很稳定,迭代比较快,也会有些bug) **
cas-client-3.4.1
Ehcache版本: 2.10.1
内容
准备
参照下列文章配置好相关环境
配置
- 重构attributeRepository
在deployerConfigContext.xml中移除
<!--Richard move to attributeRepository.xml-->
<!--
<bean id="attributeRepository" class="org.jasig.services.persondir.support.NamedStubPersonAttributeDao"
p:backingMap-ref="attrRepoBackingMap" />
<util:map id="attrRepoBackingMap">
<entry key="uid" value="uid" />
<entry key="eduPersonAffiliation" value="eduPersonAffiliation" />
<entry key="groupMembership" value="groupMembership" />
<entry>
<key><value>memberOf</value></key>
<list>
<value>faculty</value>
<value>staff</value>
<value>org</value>
</list>
</entry>
</util:map>
-->
新增attributeRepository.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!--
Bean that defines the attributes that a service may return. This example uses the Stub/Mock version. A real implementation
may go against a database or LDAP server. The id should remain "attributeRepository" though.
+-->
<bean id="attributeRepository"
class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao">
<constructor-arg index="0" ref="authenticationDataSource" />
<constructor-arg index="1" value="SELECT ACCOUNT as account, EMPLOYEE_NAME as name, DEPT_NAME as dept, JOB_NAME as job FROM mdm.t_oa_employee t where {0}" />
<property name="queryAttributeMapping">
<map>
<entry key="username" value="ACCOUNT" />
</map>
</property>
<property name="resultAttributeMapping">
<map>
<entry key="account" value="account" />
<entry key="name" value="name" />
<entry key="dept" value="department" />
<entry key="job" value="job" />
</map>
</property>
</bean>
<util:map id="attrRepoBackingMap">
<entry key="uid" value="uid" />
<entry key="eduPersonAffiliation" value="eduPersonAffiliation" />
<entry key="groupMembership" value="groupMembership" />
<entry>
<key><value>memberOf</value></key>
<list>
<value>faculty</value>
<value>staff</value>
<value>org</value>
</list>
</entry>
</util:map>
</beans>
修改Protocol 2.0的返回模板casServiceValidationSuccess.jsp
<%@ page session="false" contentType="application/xml; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>${fn:escapeXml(principal.id)}</cas:user>
<cas:protocal>2.0</cas:protocal>
<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 test="${not empty pgtIou}">
<cas:proxyGrantingTicket>${pgtIou}</cas:proxyGrantingTicket>
</c:if>
<c:if test="${fn:length(chainedAuthentications) > 0}">
<cas:proxies>
<c:forEach var="proxy" items="${chainedAuthentications}" varStatus="loopStatus" begin="0" end="${fn:length(chainedAuthentications)}" step="1">
<cas:proxy>${fn:escapeXml(proxy.principal.id)}</cas:proxy>
</c:forEach>
</cas:proxies>
</c:if>
</cas:authenticationSuccess>
</cas:serviceResponse>
客户端使用
<%
String name = null;
String department = null;
String job = null;
if (null != request.getUserPrincipal()) {
Map<?,?> attributes = ((AttributePrincipal) request.getUserPrincipal()).getAttributes();
if( attributes == null ) {
out.println("<b>No Attributes</b>");
throw new ServletException("no attributes set by the CAS client");
}
name = (String) attributes .get("name");
department = (String) attributes .get("department");
job = (String) attributes .get("job");
} else {
out.println("<b>No User Principal</b>");
}
%>
<body>
<div class="sys_top">请选择您要进入的模块</div>
<div class="sys_list">
<h2><span><%= (department == null ? "" : department) %> </span><%= (job == null ? "" : job) %> <%= (name == null ? request.getRemoteUser() : name) %>, 欢迎您!</h2>
<div class="sys_list_item clearfix">
<%--jsrender myTemplate--%>
</div>
</div>
问题
如果遇到返回中文名字为乱码,可以在CAS Validation Filter下添加encoding
<filter>
<filter-name>CAS Validation Filter</filter-name>
<filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
<init-param>
<param-name>casServerUrlPrefix</param-name>
<param-value>https://nssotest.hoau.net/cas</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>https://authtest.hoau.net</param-value>
</init-param>
<init-param>
<param-name>redirectAfterValidation</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>useSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>acceptAnyProxy</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
测试
略
参考
参考来源:
CAS Protocol 3.0 Specification
结束
CAS (14) —— CAS 更多用户信息的更多相关文章
- 单点登录系统CAS筹建及取得更多用户信息的实现
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- [原]基于CAS实现单点登录(SSO):登录成功后,cas client如何返回更多用户信息
从cas server登录成功后,默认只能从casclient得到用户名.但程序中也可能遇到需要得到更多如姓名,手机号,email等更多用户信息的情况. cas client拿到用户名后再到数据库中查 ...
- Java并发编程入门与高并发面试(三):线程安全性-原子性-CAS(CAS的ABA问题)
摘要:本文介绍线程的安全性,原子性,java.lang.Number包下的类与CAS操作,synchronized锁,和原子性操作各方法间的对比. 线程安全性 线程安全? 线程安全性? 原子性 Ato ...
- CAS协议 - CAS URIs
http://desert3.iteye.com/blog/1703449 2.CAS URIs: CAS是一个基于HTTP的协议,这就要求其每一个组成部分可以通过特定的URIs访问到.所有相关的U ...
- CAS (15) — CAS 线上环境 Ehcache Replication 的非稳定重现错误 java.util.ConcurrentModificationException
CAS (15) - CAS 线上环境 Ehcache Replication 的非稳定重现错误 摘要 线上环境在 EhCache Replication 过程中出现 java.util.Concur ...
- (转)CAS (4) —— CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example)
CAS (4) —— CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example) tomcat版本: tomcat-8.0.29 jdk版本: jdk1.8.0 ...
- cas+tomcat+shiro实现单点登录-4-Apache Shiro 集成Cas作为cas client端实现
目录 1.tomcat添加https安全协议 2.下载cas server端部署到tomcat上 3.CAS服务器深入配置(连接MYSQL) 4.Apache Shiro 集成Cas作为cas cli ...
- CAS (13) —— CAS 使用Maven Profile支持多环境编译
CAS (13) -- CAS 使用Maven Profile支持多环境编译 摘要 CAS 使用Maven Profile支持多环境编译 版本 tomcat版本: tomcat-8.0.29 jdk版 ...
- CAS (11) —— CAS TicketRegistry使用Ehcache的集群方案
CAS (11) -- CAS TicketRegistry使用Ehcache的集群方案 摘要 CAS TicketRegistry使用Ehcache的集群方案 版本 tomcat版本: tomcat ...
随机推荐
- javascript的事件机制(百度文库)
http://wenku.baidu.com/view/9c8761e1524de518964b7d65.html http://wenku.baidu.com/view/1c3d7228bd6478 ...
- C#基础课程之一注释和控制台、一些常识
注释是程序员对代码的说明,以使程序具有可读性.源代码在编译的过程中,编译器会忽略其注释部分的内容. ()行注释 格式为:// 注释内容 用两个斜杠表示注释的开始,直到该行的结尾注释结束. ()块注释 ...
- 如何将 .net2.0注册到IIS ,重新注册IIS
打开程序-运行-cmd:输入一下命令重新注册IIS C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i 一.运行C:\ ...
- 分享十:php中并发读写文件冲突的解决方案
对于日IP不高或者说并发数不是很大的应用,一般不用考虑这些!用一般的文件操作方法完全没有问题.但如果并发高,在我们对文件进行读写操作时,很有可能多个进程对进一文件进行操作,如果这时不对文件的访问进行相 ...
- Subversion代码提交中的org.apache.subversion.javahl.ClientException: svn: E200007: Commit failed异常解决
: 在切换subversion服务器地址之后,发生的无法正确提交代码的问题org.apache.subversion.javahl.ClientException: svn: E200007: Com ...
- Android开发:SharedPreferences 存储数据、获取数据
Android开发:SharedPreferences 存储数据.获取数据 email:chentravelling@163.com 开发环境:win7 64位,Android Studio. 关于S ...
- Atitit it行业图像处理行业软件行业感到到迷茫的三大原因和解决方案
Atitit it行业图像处理行业软件行业感到到迷茫的三大原因和解决方案 1. 迷茫的原因最大原因是未知1 1.1. 我在哪里??自己的定位,1 1.2. 正确方向是什么??1 1.3. 虽然找到方向 ...
- [na]tcpdump非常实用的抓包实例
基本语法篇 常用应用: 过滤物理口 过滤某个port/ip/mac 过滤协议 显示ip/mac/port不解析等 过滤mac tcpdump -i eth0 ether host 24:DF:6A:F ...
- django rest_framework入门三-Requests和Responses
这一节,我们介绍rest_framework的Requests和Responses对象,来替代django.http的HttpRequest和HttpResponse对象 1.Requests和Res ...
- (原)ubuntu下cadvisor+influxdb+grafana+supervisord监控主机和docker的containers
ubuntu下cadvisor+influxdb+grafana+supervisord监控主机和docker的containers(运行在主机上) 适用于类ubuntu系统.amd64. 1. in ...