环境要求
- 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(三)基于SpringMVC搭建CAS-client,SpringMVC搭建CAS客户端

本文详细介绍了如何在CAS服务器中配置数据库认证,包括修改application.properties文件,设置SQL查询语句,指定密码字段,配置数据库方言、驱动、连接等,以及重新编译启动CAS服务器的步骤。
CAS服务器动态验证,CAS使用MySQL数据库验证&spm=1001.2101.3001.5002&articleId=84306361&d=1&t=3&u=4612a68742da4fafa6a4ec000e187dad)
3635

被折叠的 条评论
为什么被折叠?



