获取java客户端:
attributeprincipalprincipal=(attribute principal ) request.getUserPrincipal );
string username=principal.getname (;
获取php客户机
$ username=PHP cas :3360 getuser (;
我们的程序可能需要获取更多的用户信息,包括姓名、手机号码和电子邮件。 cas
每个版本的配置方法也不同,但这里介绍当前的最新版本3.4.4。 配置方法如下,
一.必须首先配置属性属性资料档案库。 首先,必须在WEB-INF目录中找到
在deployerConfigContext.xml文件中,按如下方式设置属性存储库:
//这里的密钥必须写为username,value对应于数据库的用户名字段
其中,queryAttributeMapping是用于构建sql的查询条件属性,如下表所示
封装到查询sql中是select * fromuserinfowhereloginname=# username #,resultAttributeMapping是sql执行完成后返回的结构属性,key是
二、构成用户认证证书转换的解析器也在deployerConfigContext.xml中
为credentialstoprincipalresolvers,usernamepasswordcredentialstoprincipalresolver注入属性存储库时,属性存储库
三、修改we B- INF/view/JSP/protocol/2.0/casservicevalidationsuccess.JSP,server验证成功后,此页面生成与客户端交互的xml信息
$ { fn : escape XML (assertion.chainedauthentications (fn : length (assertion.chainedauthentications (-1 ) ).princ
${fn:ESCAPEXML(attr.value ) }
${pgtIou}
$ { fn : escape XML (proxy.principal.id ) }
上述三个步骤的配置完成后,服务器端工作完成。 那么,如何在客户端获取这些信息呢? 以下说明:
获取java客户端:
attributeprincipalprincipal=(attribute principal ) request.getUserPrincipal );
map attributes=principal.get attributes (;
string email=attributes.get (email );
php客户端;
$ email=PHP cas :3360 getattribute (' email );
这里补充一下, 提供返回功能的attributeRepository在名为person-directory-impl-1.5.0-rc6.jar的jar包中执行查询的是类org.ja SIG.service 在ersonattributedao.Java中,如果返回值有其他请求,则需要调用web服务
list results=this.simplejdbctemplate.query (querysql,rowMapper,params );
//List中存储在results中的对象是贴图类型,因此进行自定义
//Map map=new HashMap ();
//map.put('id ',3 );
//map.put(loginname,) allen );
//map.put (密码,) 123456 );
//map.put (添加时间,(2010-11-29 00:00:00.0 );
//map.put('state ',0 );
//map.put(mobile,) 123456789 );
//map.put(email )、test@126.com);
//results.add(map;
returnparseattributemapfromresults (results,queryUserName );
最后,在上述结构也不能得到返回值的情况下,可以通过调试源代码使源代码中的
在编译org.ja SIG.cas.centralauthenticationserviceimpl.Java后注释掉cas-server-core-3.4.4.jar中第360-368行的代码
金融服务:注册服务(for )
361//.getAllowedAttributes (
362//finalobjectvalue=principal.get attributes (
363//attribute;
364//
365//if (值!=空) {
366//attributes.put(attribute,value );
367//}
368//}