zoukankan      html  css  js  c++  java
  • cas4.0 session中返回更多的用户信息

    实现思路:
    新增AccoutAttributeDao类继承StubPersonAttributeDao,重写getPerson方法。实际应用中我们只需要修改getPersion方法中的内容,根据实际情况,修改查询语句。需要哪些字段通过attributes.put存放进去。
    注意:中文需要使用URLEncoder.encode进行编码,在使用的地方使用URLDecode.decode进行解码

    //uid对应的是登录页面的username
    public IPersonAttributes getPerson(String uid) {
      String sql = "";
      sql = "select * from sys_right_user where user_account =?";
      final Map values = jdbcTemplate.queryForMap(sql, uid);
      Map<String, List<Object>> attributes = new HashMap<String, List<Object>>();
      List<Object> o = Collections.singletonList((Object)URLEncoder.encode(String.valueOf(values.get("user_name"))));
      
      attributes.put("username",o);
      attributes.put("email",Collections.singletonList((Object) values.get("email")));
      attributes.put("mobile",Collections.singletonList((Object) values.get("mobile")));
      attributes.put("userid",Collections.singletonList((Object) values.get("user_id")));
      return new AttributeNamedPersonImpl(attributes);
    }

    修改deployerConfigContext.xml 中 attributeRepository的class :
    并配置好jdbcTemplate
        <bean id="attributeRepository" class="org.jasig.services.persondir.support.AccoutAttributeDao" >
         <property name="jdbcTemplate" ref="jdbcTemplate"></property>
        </bean>
         <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">  
           <property name="dataSource">  
                <ref bean="queryDatabaseDataSource" />  
            </property>  
        </bean>

    修改viewjspprotocol2.0casServiceValidationSuccess.jsp,参考附件中的页面。
    获取变量的方法:
    Object object =session.getAttribute("_const_cas_assertion_");
    Assertion assertion =(Assertion)object;
    Map<String, Object> map  = assertion.getPrincipal().getAttributes()
    通过map.get("email")来获取。

  • 相关阅读:
    Swift流程控制之循环语句和判断语句详解
    框架内的文件集合
    十分钟让你明白Objective-C的语法(和Java、C++的对比)
    Swift版音乐播放器(简化版),swift音乐播放器
    通过数字电视通过宽带网络取代互联网电视机顶盒应用
    JS学习笔记-OO创建怀疑的对象
    如果不能显示真正的考验个别车型toast问题解决
    swift 它们的定义TabBarItem
    NSUserDefaults API简单的介绍和使用英文文件
    FZU 1686 龙之谜 重复覆盖
  • 原文地址:https://www.cnblogs.com/snow365/p/6428201.html
Copyright © 2011-2022 走看看