CAS5.3單點服務-登錄驗證直接調用外部接口


關於CAS的基本使用請直接看上篇文章:CAS5.3版本單點登錄服務器(支持http協議)的搭建以及連接數據庫的設置 

其實CAS有自己的驗證接口,並且提供參數,只需要修改參數就可以調整驗證用戶密碼的加密方式。

##
# CAS Authentication Credentials
# 默認的用戶名和密碼
#
cas.authn.accept.users=admin::123456
#忽略https安全協議,使用 HTTP 協議
cas.tgc.secure=false
#是否開啟json識別功能,默認為false
cas.serviceRegistry.initFromJson=true
#你自己的數據庫
cas.authn.jdbc.query[0].url=jdbc:mysql://127.0.0.1:3306/cloud2?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
#數據庫的登錄用戶名
cas.authn.jdbc.query[0].user=root
#數據庫的登錄密碼
cas.authn.jdbc.query[0].password=root
#查詢的表和條件的sql
cas.authn.jdbc.query[0].sql=select * from sys_user where username=?
#密碼在表中對應的字段
cas.authn.jdbc.query[0].fieldPassword=password
cas.authn.jdbc.query[0].driverClass=com.mysql.cj.jdbc.Driver
# 默認加密策略,通過encodingAlgorithm來指定算法,默認NONE不加密 如果你的系統是加密的 那么就必須配置以下內容 不然無法登陸 #cas.authn.jdbc.query[
0].passwordEncoder.type=DEFAULT # 加密鹽 #cas.authn.jdbc.query[0].passwordEncoder.secret=RCGTeGiH # 加密字符長度 #cas.authn.jdbc.query[0].passwordEncoder.strength=16 # 字符類型 #cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=UTF-8 # 加密算法 #cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5 # NONE|DEFAULT|STANDARD|BCRYPT|SCRYPT|PBKDF2 #cas.authn.jdbc.query[0].passwordEncoder.type=NONE

可能是我個人對於文檔理解的不夠透徹,當用戶密碼按照一定的簡單規則進行加密時,直接修改參數是沒有問題的。

然后我先說一下我現在的加密方式,也是使用MD5加鹽值進行加密,但是我的每個用戶名的鹽值是不同的,如果鹽值固定,按照上邊的參數介紹,直接配置MD5加密方式,再配置上鹽值,也沒問題,現在的情況是鹽值不是固定的,這時候貌似就不太行了。

至少我不知道該怎么做了,於是又參考了一些文檔,發現原來CAS的驗證是直接能夠調用外部接口的,代碼如下:

##
# REST 認證開始, 請求遠程調用接口(NONE不進行加密)
#
cas.authn.rest.uri=http://localhost:8448/cas-db/cas/user/login
cas.authn.rest.passwordEncoder.type=NONE
cas.authn.rest.passwordEncoder.characterEncoding=UTF-8
cas.authn.rest.passwordEncoder.encodingAlgorithm=MD5

##
# 開啟json服務注冊
#
cas.serviceRegistry.initFromJson=true
##
# Json配置
#cas.serviceRegistry.json.location=classpath:/services

#30秒掃描一遍
#cas.serviceRegistry.schedule.repeatInterval=30000

##
# 登出后允許跳轉到指定頁面
#
cas.logout.followServiceRedirects=true

# ticket過期設置
cas.ticket.st.numberOfUses=1
cas.ticket.st.timeToKillInSeconds=60
#cas.theme.defaultThemeName=app1
代碼塊中的接口http://localhost:8448/cas-db/cas/user/login,就是我們自己寫的外部接口,其實就是沒有配置CAS時的登錄驗證方式,這時候就完美解決了我的問題。
大佬還請指教。
具體原理還在研究中,待續......


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM