cas返回mysql数据_CAS 登录成功后返回的值实现根据不同的条件查询不同的表或者数据库...

我们都知道CAS在登录成功后会返回一些我们所需要的值来提供给各个客户端,有一种情况就是根据不同的情况我们要查询不同的表来进行反馈信息,比如说 当 是管理员登录的时候返回的可能是从A表中查询的数据,当普通用户登录的时候可能返回的是B表中的信息,CAS怎么才能实现这种需求呢?现在我们就实现这种需求,需要修改deployerConfigContext.xml 配置文件,也需要修改源码,现在我们现讲怎么修改配置文件,其实很简单 我们配置返回登录信息的配置如下:

下面是配置的attributeRepsoitory和attributeRepsoitory1两个Bean

class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao"

id="attributeRepository">

value="select * from A where {0}" />

class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao"

id="attributeRepository1">

value="select * from B where {0}" />

以上就是配置文件部分的修改(该部分修改时基于原来返回信息的配置基础上增加的一个attributeReponsitory1 而已)

下面讲一下源码怎么修改

在org.jasig.cas.authentication.principal.AbstractPersonDirectoryCredentialsToPrincipalResolver这个类中有如下代码:

@NotNull

private IPersonAttributeDao attributeRepository = new StubPersonAttributeDao(new HashMap>());

看到上述代码相比就知道了上述配置文件中

这句话的作用了,所以我们就参照这个attributeRepository 的定义,我们也定义一个类似的 attributeRepository1,如下:

private IPersonAttributeDao attributeRepository1 = new StubPersonAttributeDao(new HashMap>());

public final void setAttributeRepository(final IPersonAttributeDao attributeRepository1) {

this.attributeRepository1 = attributeRepository1;

}

这样注入Bean 就完成了,下面就可以具体的应用了,还是在这个类中,找到下面的代码:

final IPersonAttributes personAttributes = this.attributeRepository.getPerson(principalId);

这句代码的作用就是根据username查询返回的信息,

根据配置我们可以这样改造这句话,假定有一个loginrole 参数 为1的时候执行attributRepository1这个bean

int loginrole = 1;

final IPersonAttributes personAttributes = loginrole ==1?this.attributeRepository1.getPerson(principalId):this.attributeRepository.getPerson(principalId);

//这样就完成了如果查不同的表返回登录信息

以上纯属个人应用总结的方法,不一定是最合适的也不一定是最正确的。



分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2013-11-23 15:43

浏览 441

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值