cas shrio 不同系统单点登陆

不同系统使用不同的登陆名和账号,在做cas中心验证 使用数据库验证就比较纠结,因为登录名和密码两边不一样,后来请教大神,两个系统使用相同的登录名,密码可以不一样,然后在cas的
验证db 设置两个系统的数据源只要一个验证通过就把用户信息放到seession,完成登陆。

参考:https://github.com/coder-huang/sso-shiro-cas

deployerConfigContext.xml

<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
<entry key-ref="primaryAuthenticationHandler1" value-ref="primaryPrincipalResolver1" />

<!-- 通过数据库验证身份, hr 人事系统的登陆 -->
<bean id="primaryAuthenticationHandler"
class="com.distinct.cas.jdbc.QueryDatabaseAuthenticationHandler"
p:dataSource-ref="dataSource"
p:passwordEncoder-ref="passwordEncoder"
p:sql="select usr_pwd from users where Usr_LoginID=?" />


<!-- 通过数据库验证身份,培训 系统的登陆 -->
<bean id="primaryAuthenticationHandler1"
class="com.distinct.cas.jdbc.QueryDatabaseAuthenticationHandler"
p:dataSource-ref="dataSource1"
p:passwordEncoder-ref="passwordEncoder"
p:sql="select usr_pwd from users where Usr_LoginID=? " />



<!-- 设置数据源hr -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://127:3306/db_hr?useUnicode=true&characterEncoding=utf8"></property>
<property name="username" value="db_hr_user"></property>
<property name="password" value="123456"></property>
</bean>


<!-- 设置数据源traning -->
<bean id="dataSource1" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://128:3306/db_training?useUnicode=true&characterEncoding=utf8"></property>
<property name="username" value="db_trainning"></property>
<property name="password" value="123456"></property>
</bean>


UserRealm.java

/**
* 1、CAS认证 ,验证用户身份,培训系统 和 hr 系统采用相同的登录名,进行关联
* 2、将用户基本信息设置到会话中
*/
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {

AuthenticationInfo authc = super.doGetAuthenticationInfo(token);
String account = (String) authc.getPrincipals().getPrimaryPrincipal();

User user = this.loginDao.getUser(account);
if(user!=null){
List<UserResource> userResources=this.loginDao.getAllMenusByUser(user);
SecurityUtils.getSubject().getSession().setAttribute(Constants.USER_RESOURCE, userResources);
}
SecurityUtils.getSubject().getSession().setAttribute(Constants.SESSION_USER, user);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值