博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CAS 5.3.1系列之支持JDBC认证登录(二)
阅读量:2040 次
发布时间:2019-04-28

本文共 3143 字,大约阅读时间需要 10 分钟。

CAS 5.3.1系列之支持JDBC认证登录(二)

在项目中,我们肯定是不能用默认的静态账号密码,所以我们需要实现对jdbc或者其它认证方式的支持,将cas-overlay-template-5.2\pom.xml复制到项目里,将application.properties复制到resources文件夹

org.apereo.cas
cas-server-support-jdbc
${cas.version}
org.apereo.cas
cas-server-support-jdbc-drivers
${cas.version}

注意5.3.1版本的cas-server-support-jdbc-drivers数据库驱动是mysql8左右的,所以如果是mysql5版本的,就不使用自适配驱动,自己加上:

mysql
mysql-connector-java
5.1.27

ok,然后需要在application.properties加上:

### JDBC Authentication## 查询账号密码SQL,必须包含密码字段cas.authn.jdbc.query[0].sql=select * from sys_user where username=?# 指定上面的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://192.168.0.159:3306/jeeplatform?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8# 数据库dialect配置cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect# 数据库用户名cas.authn.jdbc.query[0].user=root# 数据库用户密码cas.authn.jdbc.query[0].password=root# 数据库事务自动提交cas.authn.jdbc.query[0].autocommit=false# 数据库驱动cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver# 超时配置cas.authn.jdbc.query[0].idleTimeout=50000# 默认加密策略,通过encodingAlgorithm来指定算法,默认NONE不加密# NONE|DEFAULT|STANDARD|BCRYPT|SCRYPT|PBKDF2cas.authn.jdbc.query[0].passwordEncoder.type=NONE#cas.authn.jdbc.query[0].passwordEncoder.type=org.muses.jeeplatform.cas.authentication.encode.MD5PasswordEncoder# 字符类型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密码可以如下设置

# NONE|DEFAULT|STANDARD|BCRYPT|SCRYPT|PBKDF2cas.authn.jdbc.query[0].passwordEncoder.type=DEFAULTcas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=MD5

也可以自定义加密方式:

import org.springframework.security.crypto.password.PasswordEncoder;/** * 
 *   自定义PasswordEncoder * 
* *
 * @author mazq * 修改记录 *    修改后版本:     修改人:  修改日期: 2020/04/24 17:02  修改内容: * 
*/public class MD5PasswordEncoder implements PasswordEncoder { @Override public String encode(CharSequence charSequence) { return charSequence.toString(); } @Override public boolean matches(CharSequence charSequence, String s) { String encodeStr = charSequence.toString() + "aa"; if (encodeStr.equals(s)) { return true; } return false; }}

然后修改配置:

cas.authn.jdbc.query[0].passwordEncoder.type=org.muses.jeeplatform.cas.authentication.encode.MD5PasswordEncoder

在这里插入图片描述

在这里插入图片描述

代码例子参考:

详情可以参考官方文档:https://apereo.github.io/cas/5.3.x/installation/Configuration-Properties.html

优质参考博客:

https://www.cnblogs.com/jpeanut/tag/CAS/
https://blog.csdn.net/anumbrella/category_7765386.html

你可能感兴趣的文章
如何避免创建不必要的对象
查看>>
老司机入职一周,给我们解读 Spring Boot 最流行的 16 条实践
查看>>
maven删除不必要的依赖;优化pom依赖研究
查看>>
不同类型接口的异常处理规范
查看>>
2017 年你不能错过的 Java 类库
查看>>
Java 异常处理的误区和经验总结
查看>>
浅析bootstrap原理及优缺点
查看>>
MVVM模式中ViewModel和View、Model有什么区别
查看>>
面向切面编程的两种实现
查看>>
Java笔记——面向切面编程(AOP模式)
查看>>
算法----五大算法之分支限界法
查看>>
Docker 在分布式和大数据框架中的应用
查看>>
javaweb学习总结——获得MySQL数据库自动生成的主键
查看>>
【zabbix教程三】——centos7 安装zabbix客户端并监控
查看>>
SpringMVC
查看>>
多线程
查看>>
设计模式之一适配器模式
查看>>
MVC、MVP、MVVM之间的关系
查看>>
计算机网络--HTTP协议(二)
查看>>
Spring 手动提交事务
查看>>