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时的登录验证方式,这时候就完美解决了我的问题。
大佬还请指教。
具体原理还在研究中,待续......
原文地址:https://www.cnblogs.com/qcq0703/p/15666544.html