CAS(二)CAS服务器动态验证,CAS使用MySQL数据库验证

环境要求

  • JDK 8+
  • CAS 5.2
  • tomcat 8+

步骤

一、搭建CAS服务器  --> CAS(一)搭建CAS - server服务器

 

二、修改application.properties

静态验证的配置,需要注释:

##
# CAS Authentication Credentials
#
#cas.authn.accept.users=user::123

再加入如下配置:

#Query Database Authentication 数据库查询校验用户名开始
#查询账号密码sql,必须包含密码字段
cas.authn.jdbc.query[0].sql=select * from user_info where username=?
#指定上面的sql查询字段名(必须)
cas.authn.jdbc.query[0].fieldPassword=password
#指定过期字段,1为过期,若过期不可用(可选)
#cas.authn.jdbc.query[0].fieldExpired=expired
#为不可用字段段,1为不可用,需要修改密码(可选)
#cas.authn.jdbc.query[0].fieldDisabled=disabled
#数据库方言hibernate的
cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect
#数据库驱动
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
#数据库连接
cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/crm?useUnicode=true&characterEncoding=UTF-8
#数据库用户名
cas.authn.jdbc.query[0].user=root
#数据库密码
cas.authn.jdbc.query[0].password=root
#默认加密策略,通过encodingAlgorithm来指定算法,默认NONE不加密
cas.authn.jdbc.query[0].passwordEncoder.type=DEFAULT
cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5
#Query Database Authentication 数据库查询校验用户名结束

主要配置说明:

#数据库查询用户名语句,其中user_info对应表名,username对应登录账号的字段名
cas.authn.jdbc.query[0].sql=select * from user_info where username=?
#对应密码的字段名
cas.authn.jdbc.query[0].fieldPassword=password
#密码加密策略,如果数据库表的password字段没有使用加密策略,则这一段配置可以省略
cas.authn.jdbc.query[0].passwordEncoder.type=DEFAULT
cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8
cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5

三、重新编译、启动

浏览器访问http://cas.server.com:8443/cas/login可进入cas登录界面

输入数据库中的账号和密码登录

代码托管在https://gitee.com/oumuv/cas-Demo

 

上一篇:CAS(一)搭建CAS - server服务器

下一篇:CAS(三)基于SpringMVC搭建CAS-client,SpringMVC搭建CAS客户端

希望可以帮助到有需要的人

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值