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

  • 相关阅读:
    zz java java.nio.ByteBuffer flip
    看到的应用mina做的一个实例
    命令行工具SVN
    ByteBuffer 理解
    Linux命令行下常用svn命令
    三元操作符对null 的处理
    获取最后一个字符串
    C#分割字符串
    学习Silverlight 书籍
    oralce 进行多表同步
  • 原文地址:https://www.cnblogs.com/snow365/p/6428201.html
Copyright © 2011-2022 走看看