cas4.0 mysql_【SSO单点系列】:CAS4.0 CAS整合SpringMVC+MyBatis实现数据库校验(04)

一、准备所需jar包

cas\WEB-INF\lib中加入 c3p0-0.9.1.2.jar包、mysql-connector-java-5.1.21.jar包和cas-server-support-jdbc-4.0.0.jar包。

c3p0的jar包和mysql驱动的jar包可以在maven上拉下来,

cas-server-support-jdbc-4.0.0.jar 这个jar包可以在cas-server-4.0.0\modules目录下找到

51ed7714947fbe1cd05cc52e6bcc060e.png

二、Cas-Server(服务端)自定义验证规则

1、打开deployerConfigContext.xml

d2722922ea30414e589f111b7f3b5b46.png

找到 primaryAuthenticationHandler,因为实际开发中我们需要跟数据库做校验所以这段代码就需要注掉然后改为我们的验证规则

2、在deployerConfigContext.xml中给Cas配置数据源

3、在deployerConfigContext.xml中给定义加密方式

class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"c:encodingAlgorithm="MD5"p:characterEncoding="UTF-8" />

4、在deployerConfigContext.xml中配置查询语句,这里的p:passwordEncoder对应着加密方式 p:dataSource这个指向的就是之前配置的数据源

class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"p:dataSource-ref="dataSource"p:sql="select password from cas_user where username=? and data_status='1'"p:passwordEncoder-ref="passwordEncoder" />

5、在deployerConfigContext.xml中配置新的验证规则,找到这段代码将这段代码注掉,细心的朋友或许已经发现primaryAuthenticationHandler

这个key指向的就是Cas 提供的默认账号密码配置,也就是我们一上来就注掉的呢段

三、CAS-Client(客户端)配置

1.打开 pom.xml文件引入client(客户端)jar包

5460357d9f78103403ac6a917bb6b086.png

org.jasig.cas.client

cas-client-core

3.2.1

2、打开 web.xml配置加入cas配置

CAS Single Sign Out Filter

org.jasig.cas.client.session.SingleSignOutFilter

CAS Authentication Filter

org.jasig.cas.client.authentication.AuthenticationFilter

casServerLoginUrl

http://localhost:8080/cas/login

serverName

http://localhost:8080

CAS Validation Filter

org.jasig.cas.client.validation.Cas10TicketValidationFilter

casServerUrlPrefix

http://localhost:8080/cas

serverName

http://localhost:8080

redirectAfterValidation

true

CAS HttpServletRequest Wrapper Filter

org.jasig.cas.client.util.HttpServletRequestWrapperFilter

CAS Assertion Thread Local Filter

org.jasig.cas.client.util.AssertionThreadLocalFilter

CAS Single Sign Out Filter

/*

CAS Authentication Filter

/*

CAS Validation Filter

/*

CAS HttpServletRequest Wrapper Filter

/*

CAS Assertion Thread Local Filter

/*

org.jasig.cas.client.session.SingleSignOutHttpSessionListener

四、运行测试

1eb1fa935eb42f0fb712019392e9e14f.png

CAS自动拦截(PS:没有登录当然要拦截了)

0aaa67283537b13a1123f1335bcf3fe1.png

随便输入点信息看看验证成功没有~~

b6be2518ecc0f90e408344d30fb14100.png

b9f56b81064de1760ef8810f69143025.png

输入正确的账号密码登录系统成功

2ac12ce7eea34a70b3fae2088573b7ad.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值