摘要,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