• 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")来获取。

  • 相关阅读:
    【flutter BottomNavigationBar 】selectedLabelStyle: TextStyle(fontSize: 22) 更新后使用方法
    学术论文中的参考文献格式
    word2016中写出伪代码
    基于RPLiDAR A2的cartographer建图
    第 7 章 系统效果评测与监控
    Linux TOP 命令详解
    mysql-canal-rabbitmq 安装部署教程
    第 6 章 用户画像系统
    Elasticsearch 模块
    Kibana 插件环境搭建教程
  • 原文地址:https://www.cnblogs.com/snow365/p/6428201.html
Copyright © 2020-2023  润新知