CAS客户端取更多用户信息.docVIP

  • 4
  • 0
  • 约3.16万字
  • 约 10页
  • 2017-06-12 发布于河南
  • 举报
CAS客户端取更多用户信息

CAS客户端获取更多用户信息 总述 首先,我是用的CAS Server版本是3.5.2,Servlet容器是Tomcat HYPERLINK / \o 程序 \t /_blank 程序中也可能遇到客户端需要得到更多的用户信息,如姓名,手机号,email等更多用户信息的情况。 cas各种版本配置方式也不尽相同,这里讲的是3.5.2版本。 此文章中 的CAS 基础环境如下: CAS服务端:cas-server-3.5.2 CAS客户端:cas-client-3.2.1 第一种方式 服务器端配置 ? 一、首先需要配置属性attributeRepository 首先,你需要到WEB-INF目录找到? deployerConfigContext.xml文件,同时配置 attributeRepository 如下:? bean??class=org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao id=attributeRepository ????????constructor-arg index=0 ref=dataSource/ ????????constructor-arg index=1 value=select * from lead_system_user where {0}/ ????????property name=queryAttributeMapping ????????????map ????????????????entry key=username value=login_name/?? // 这里的key需写username,value对应数据库用户名字段 ????????????/map ????????/property ????????property name=resultAttributeMapping ????????????map // 在这里key代表返回数据库对应的字段名 // value对应的是客户端获取值的时候的key值 // 有的资料说返回的名称字段不能有下划线,这里特意测试了一下发现有下划线也是可以正常能拿到值的,所以如果客户端获取不到值不用担心这里的问题,可能是其它的地方导致的问题。 ????????????????entry key=user_name value=user_name/ ????????????????entry key=user_mobile value=user_mobile/ ????????????????entry key=user_email value=user_email/ ????????????/map ????????/property ????/bean 其中: queryAttributeMapping 是组装sql用的查询条件属性,上述配置后,结合封装成查询sql就是?select * from lead_system_user where login_name=#username# resultAttributeMapping 是sql执行完毕后返回的结构属性,?key对应数据库字段,value对应客户端获取参数。 ?? 二、配置用户认证凭据转化的解析器 也是在 deployerConfigContext.xml 中,找到 credentialsToPrincipalResolvers,为 UsernamePasswordCredentialsToPrincipalResolver 注入 attributeRepository,那么 attributeRepository 就会被触发并通过此类进行解析,红色为新添部分。 property name=credentialsToPrincipalResolvers ????????????list???????? ????????????????bean class=org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver ????????????????????property name=attributeRepository ref=attributeRepository/ ????????????????/bean ????????????????bean class=org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver/ ????????????/list

文档评论(0)

1亿VIP精品文档

相关文档