CAS获取用户更多信息
来源:互联网 发布:bootcamp助理下载 mac 编辑:程序博客网 时间:2024/04/28 23:18
配置SingleRowJdbcPersonAttributeDao
基于deployerConfigContext.xml配置文件,添加SingleRowJdbcPersonAttributeDao节点,其使用jdbc连接mysql认证,并且返回更多的用户信息放到session里让客户端获取
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<
bean
id
=
"xiaokacengAttributeRepository"
class
=
"org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao"
>
<
constructor-arg
index
=
"0"
ref
=
"dataSource"
/>
<
constructor-arg
index
=
"1"
value
=
"select email,name,username,password from cas_user where {0}"
/>
<!-- 组装sql用的查询条件属性 -->
<
property
name
=
"queryAttributeMapping"
>
<
map
>
<!-- key必须是uername而且是小写否则会导致取不到用户的其它信息,value对应数据库用户名字段,系统会自己匹配 -->
<
entry
key
=
"username"
value
=
"username"
/>
</
map
>
</
property
>
<
property
name
=
"resultAttributeMapping"
>
<
map
>
<!-- key为对应的数据库字段名称,value为提供给客户端获取的属性名字,系统会自动填充值 -->
<
entry
key
=
"username"
value
=
"username"
></
entry
>
<
entry
key
=
"email"
value
=
"email"
></
entry
>
<
entry
key
=
"name"
value
=
"name"
></
entry
>
<
entry
key
=
"password"
value
=
"password"
></
entry
>
</
map
>
</
property
>
</
bean
>
配置用户认证凭据转化的解析器
在deployerConfigContext.xml中,为UsernamePasswordCredentialsToPrincipalResolver注入attributeRepository
1
2
3
<
bean
class
=
"org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver"
>
<
property
name
=
"attributeRepository"
ref
=
"xiaokacengAttributeRepository"
/>
</
bean
>
删除serviceRegistryDao节点下的配置
如果不注释掉里面的内容,将会导致客户端无法获取用户更多的信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<
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" />
</bean>
</list>
</
property
>-->
</
bean
>
添加用户信息返回
找到WEB-INF/view/jsp/protocol/2.0/casServiceValidationSuccess.jsp。此文件作用是在server验证成功后,这个页面负责生成与客户端交互的xml信息,在默认casServiceValidationSuccess.jsp中,只包括用户登录名,并不提供其他的属性信息,因此需要对页面进行扩展
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<%@ 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: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>
<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
>
<!-- 在server验证成功后,这个页面负责生成与客户端交互的xml信息,在默认的casServiceValidationSuccess.jsp中,只包括用户名,并不提供其他的属性信息,因此需要对页面进行扩展 -->
<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
>
</cas:authenticationSuccess>
</cas:serviceResponse>
客户端获取
示例基于jsp页面获取
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%@ page
import
=
" org.jasig.cas.client.util.*"
%>
<%@ page
import
=
" org.jasig.cas.client.authentication.*"
%>
<%@ page
import
=
" org.jasig.cas.client.validation.*"
%>
<%@ page
import
=
" java.util.*"
%>
<%
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
// AttributePrincipal principal = AssertionHolder.getAssertion().getPrincipal();
String loginName = principal.getName();
out.println(
"loginName:"
+ loginName);
Map<String, Object> attributes = principal.getAttributes();
out.println(
"<br>"
);
if
(attributes !=
null
)
{
out.println(
"username:"
+ attributes.get(
"username"
));
out.println(
"<br>"
);
out.println(
"password:"
+ attributes.get(
"password"
));
out.println(
"<br>"
);
out.println(
"email:"
+ attributes.get(
"email"
));
out.println(
"<br>"
);
out.println(
"name:"
+ attributes.get(
"name"
));
out.println(
"<br>"
);
}
%>
from:http://my.oschina.net/xiaokaceng/blog/182547?p=1
0 0
- CAS获取用户更多信息
- CAS登录后获取更多信息
- cas 3.5.2 登录成功后返回用户更多信息
- CAS服务端返回更多的用户登录信息
- CAS 添加更多信息配置
- cas 4.0 返回更多信息
- cas 3.5.2 登录成功后,如何返回用户更多信息?
- Cas 3.5.2 登录成功后,如何返回用户更多信息?
- CAS登录成功后返回更多信息
- CAS登录成功后返回更多信息
- 【cas】利用Map返回更多信息
- 【CAS】自定义登录页面,返回更多信息
- yale cas 3.4如何返回更多信息高级篇
- 从google中获取更多信息
- xcode获取更多崩溃调试信息
- WinPcap获取网卡的更多信息
- UMAX祝您获取更多用户
- 获取用户窗体信息
- C语言学习笔记(二)——流程控制【重点】
- Java 自动装箱与拆箱(Autoboxing and unboxing)
- RMI是什么
- Views和Adapters
- app性能测试--流量
- CAS获取用户更多信息
- Debug调试
- 【Unity】UGUI 如何使用CustomFont(自定义字体)
- linux限制磁盘使用配额
- dBm与mW的转换
- Maven基础配置
- 关于《30天编写自己的操作系统》ipl 与linux0.01的关系
- storm之2:安装部署
- iOS中获取当前时间