cas server mysql_cas-server配置数据库验证

本文档详细介绍了如何配置CAS服务器以利用MySQL数据库进行用户验证。首先创建了一个包含username和password字段的users表,然后编译并引入了MySQL驱动和CAS的jdbc支持jar包。接着,在deployerConfigContext.xml中配置了数据库连接池参数,并在cas.properties文件中添加了数据库连接的相关设置。此外,还调整了cas.jdbc.authn.query.sql以适应项目的查询需求,并允许了注销后的重定向。最后,修改了TGT的过期策略,使其永不失效。
摘要由CSDN通过智能技术生成

创建一个MySQL数据库,新建一张users表,添加username和password字段

c6cd8e91778eff894bd0d7d475b238f4.png

第七步、配置数据库认证

参考官方文档:https://apereo.github.io/cas/4.2.x/installation/Database-Authentication.html#database-components

首先拷贝MySQL驱动到cas-server-webapp项目的lib目录下

260ba07fa990df0cc457f2e2c65b4944.png

然后到下载的CAS源码的cas-server-support-jdbc目录下gradle build编译jdbc的支持jar包

590bbf88893715340feeb29a2b191bf4.png

编译好之后,同样到build》libs目录下拷贝cas-server-support-jdbc-4.2.7.jar包到cas-server-webapp项目的lib目录下

23215af0f092458d60da2435ac20e72e.png

f2d6c815b7777693cc6f1144756d64c6.png

打开deployerConfigContext.xml配置文件

df19d6442292a223f48c0158381f3eb7.png

将这一行注释掉

加入

48304ba5e6f9fe08f3fa1abda7d326ab.png

class="com.mchange.v2.c3p0.ComboPooledDataSource"

p:driverClass="${database.driverClass}"

p:jdbcUrl="${database.url}"

p:user="${database.user}"

p:password="${database.password}"

p:initialPoolSize="${database.pool.minSize}"

p:minPoolSize="${database.pool.minSize}"

p:maxPoolSize="${database.pool.maxSize}"

p:maxIdleTimeExcessConnections="${database.pool.maxIdleTime}"

p:checkoutTimeout="${database.pool.maxWait}"

p:acquireIncrement="${database.pool.acquireIncrement}"

p:acquireRetryAttempts="${database.pool.acquireRetryAttempts}"

p:acquireRetryDelay="${database.pool.acquireRetryDelay}"

p:idleConnectionTestPeriod="${database.pool.idleConnectionTestPeriod}"

p:preferredTestQuery="${database.pool.connectionHealthQuery}" />

48304ba5e6f9fe08f3fa1abda7d326ab.png

4714ff30e831a7726243afd3c820afc6.png

19b0a467d3c94abcf63e21bdd846a60b.png

,然后打开cas.properties,加入数据库的相关配置如下:(请修改为自己的数据库地址,用户名和密码)

48304ba5e6f9fe08f3fa1abda7d326ab.png

# == Basic database connection pool configuration ==

database.driverClass=com.mysql.jdbc.Driver

database.url=jdbc:mysql://127.0.0.1:3306/sso_test?useUnicode=true&characterEncoding=UTF-8&

database.user=root

database.password=admin

database.pool.minSize=6

database.pool.maxSize=18

# Maximum amount of time to wait in ms for a connection to become

# available when the pool is exhausted

database.pool.maxWait=10000

# Amount of time in seconds after which idle connections

# in excess of minimum size are pruned.

database.pool.maxIdleTime=120

# Number of connections to obtain on pool exhaustion condition.

# The maximum pool size is always respected when acquiring

# new connections.

database.pool.acquireIncrement=6

# == Connection testing settings ==

# Period in s at which a health query will be issued on idle

# connections to determine connection liveliness.

database.pool.idleConnectionTestPeriod=30

# Query executed periodically to test health

database.pool.connectionHealthQuery=select 1

# == Database recovery settings ==

# Number of times to retry acquiring a _new_ connection

# when an error is encountered during acquisition.

database.pool.acquireRetryAttempts=5

# Amount of time in ms to wait between successive aquire retry attempts.

database.pool.acquireRetryDelay=2000

48304ba5e6f9fe08f3fa1abda7d326ab.png

对cas.propeities进行修改,去掉“cas.jdbc.authn.query.sql=”前的注释符,改为适合项目的语句,比如:

cas.jdbc.authn.query.sql=select password from sso_user where username=?

4)   允许注销后可重定向(可选)

修改cas.propeities,去掉“cas.logout.followServiceRedirects=false”前的注释符,改为:

cas.logout.followServiceRedirects=true

5)   修改TGT为永不失效策略

修改deployerConfigContext.xml,注释掉原来的grantingTicketExpirationPolicy,修改为:

然后重启tomcat,验证登录

输入数据库的账号密码

ad3e4be5d7a5fbc37dc5daa5be0e8b0e.png

参考:https://www.cnblogs.com/wggj/p/7550361.html  和 https://www.cnblogs.com/jay763190097/p/6492005.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值