创建一个MySQL数据库,新建一张users表,添加username和password字段
第七步、配置数据库认证
参考官方文档:https://apereo.github.io/cas/4.2.x/installation/Database-Authentication.html#database-components
首先拷贝MySQL驱动到cas-server-webapp项目的lib目录下
然后到下载的CAS源码的cas-server-support-jdbc目录下gradle build编译jdbc的支持jar包
编译好之后,同样到build》libs目录下拷贝cas-server-support-jdbc-4.2.7.jar包到cas-server-webapp项目的lib目录下
打开deployerConfigContext.xml配置文件
将<alias name="acceptUsersAuthenticationHandler" alias="primaryAuthenticationHandler" />这一行注释掉
加入
<alias name="queryDatabaseAuthenticationHandler" alias="primaryAuthenticationHandler" /> <alias name="dataSource" alias="queryDatabaseDataSource" /> <bean id="dataSource" 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}" />