摘要,cas 下载
基于maven的版本,数据库MySQL
jar
找到 cas-overlay-template-5.3/pom.xml文件,加入
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-jdbc</artifactId>
<version>${cas.version}</version>
</dependency>
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-support-jdbc-drivers</artifactId>
<version>${cas.version}</version>
</dependency>
数据库配置
具体其他的配置项,点击
打开 cas-overlay-template-5.3\etc\cas\config\cas.properties ,新建如下配置
#禁用掉原始账号 casuser 密码 Mellon
cas.authn.accept.users=
#查询账号密码SQL,必须包含密码字段,由于使用md5加密了,数据库存的是大写,所以查询出来转换为小写
cas.authn.jdbc.query[0].sql=select lower(password) as password from user where phone=?
#指定上面的SQL查询字段名(必须)
cas.authn.jdbc.query[0].fieldPassword=password
#指定过期字段,1为过期,若过期不可用
#cas.authn.jdbc.query[0].fieldExpired=expired
#为不可用字段段,1为不可用,需要修改密码
#cas.authn.jdbc.query[0].fieldDisabled=disabled
#数据库连接
cas.authn.jdbc.query[0].url=jdbc:mysql://localhost:3306/commdb?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false
#数据库dialect配置
cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect
#数据库用户名
cas.authn.jdbc.query[0].user=yfap
#数据库用户密码
cas.authn.jdbc.query[0].password=rES5TeTDtkOMP9Cs
#数据库事务自动提交
cas.authn.jdbc.query[0].autocommit=false
#数据库驱动
cas.authn.jdbc.query[0].driverClass=com.mysql.cj.jdbc.Driver
#超时配置
#cas.authn.jdbc.query[0].idleTimeout=5000
#默认加密策略,通过encodingAlgorithm来指定算法,默认NONE不加密
# NONE|DEFAULT|STANDARD|BCRYPT|SCRYPT|PBKDF2
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
# 加密盐
#cas.authn.jdbc.query[0].passwordEncoder.secret=
# 加密字符长度
#cas.authn.jdbc.query[0].passwordEncoder.strength=16
MD5那里是因为LZ数据库存的密码是MD5加密了的,如没有的加密,注释掉即可
提示
上面只是根据手机号码查询的,如要邮箱或者其他的方式查询用户,则可以写个函数,调用即可
cas.authn.jdbc.query[0].sql=call user_login(?)
函数如下
CREATE DEFINER=`user`@`%` PROCEDURE `user_login`(in uid varchar(50))
BEGIN
SELECT lower(password) as password, name, gender, avatar, phone, email, im as im FROM user where email=uid or phone=uid;
END
问题
如登录过程中出现底下的错误
The server time zone value '???ú±ê×??±??' is unrecognized or represents
则在数据库连接url那里加上serverTimezone=GMT即可,如是gmt+8时区,则改成GMT%2B8