CAS 4.2.1单点登录(三) 配置连接数据库

cas默认是读取cas-server-webapp下的cas.properties文件中的

accept.authn.users=casuser::Mellon

作为登录的用户名和密码的


下面我们修改使cas从数据库中获取用户名和密码

1.cas-server-webapp下的cas.properties

添加

# == Basic database connection pool configuration ==
database.driverClass=com.mysql.jdbc.Driver
database.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8
database.user=root
database.password=root
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

cas.jdbc.authn.query.sql=select password from test_a where name=?

注:查询的sql固定格式为cas.jdbc.authn.query.sql=select 密码字段 from 表名 where 用户名字段=?

2.cas-server-webapp下deployerConfigContext.xml中

添加

<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}" />

<alias name="queryDatabaseAuthenticationHandler" alias="primaryAuthenticationHandler" />
<alias name="dataSource" alias="queryDatabaseDataSource" />

<alias name="dataSource" alias="queryEncodeDatabaseDataSource" />

注释或删除

<!--<alias name="acceptUsersAuthenticationHandler" alias="primaryAuthenticationHandler" />-->
3.主目录下的build.gradle文件的dependencies属性中添加
compile ("mysql:mysql-connector-java:5.1.24")

这里使用的是mysql数据库

4.cas-server-webapp下的build.gradle的dependencies添加
compile project(':cas-server-support-jdbc')

因为deployerConfigContext.xml中添加的queryDatabaseAuthenticationHandler是属于cas-server-support-jdbc模块的,因此要在cas-server-webapp中添加对cas-server-support-jdbc的依赖

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值