第一步:在远程数据库中建表
CREATE TABLE `t_cas_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL COMMENT '用户名',
`password` varchar(255) DEFAULT NULL COMMENT '密码',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
第二步:配置数据库源 application.properties
#######
# CAS Authentication Credentials
#
# cas.authn.accept.users=casuser::Mellon 注释配置文件的账号和密码
cas.authn.jdbc.query[0].url=jdbc:mysql://192.168.194.102:30011/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
cas.authn.jdbc.query[0].user=root
cas.authn.jdbc.query[0].password=123456
cas.authn.jdbc.query[0].sql=select * from t_cas_user where username=?
cas.authn.jdbc.query[0].fieldPassword=password
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
第三步:添加相对应的jar (cas\WEB-INF\lib)
cas-server-support-jdbc-5.1.9.jar
cas-server-support-jdbc-authentication-5.1.9.jar
cas-server-support-jdbc-drivers-5.1.9.jar
mysql-connector-java-8.0.11.jar
下载地址:Central Repository: org/apereo/cas
第四步:使用数据库的用户名和密码,验证重启
备注:平时数据库的密码都是经过加密存储的,cas也是支持的。 我们可以在配置文件中配置数据源的地方加上以下配置就支持md5加密解密
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 # 数据库密码以md5加密存储