Apereo CAS 5.0.X 使用Spring Boot的方式重构了项目,配置也发生了很大的变化。配置文件都在cas项目下的WEB-INF/classes目录下面,配置文件较多,后边详细说,这里先说下Apereo CAS 5.0.X行为的配置文件application.properties。
CAS 5.0.X默认使用static

如何开启数据库认证,按照下面文档的说法
​​​ https://apereo.github.io/cas/5.0.x/installation/Database-Authentication.html#configuration​​ 引入cas-server-support-jdbc依赖,然后配置一下相关的参数就可以了。

重新编译打包

在cas-overlay-template项目中引入cas-server-support-jdbc依赖,重新打包。

静态认证

CAS 5.0.X默认的认证方式是Static Authentication,也就是在application.properties文件中,有一行配置如下,

cas.authn.accept.users=casuser::Mellon

也就是用casuser作为用户名,Mellon作为密码就能登录系统。如果要使用数据库方式认证的话,首先把这行配置注释掉,然后添加数据库认证相关的配置,就开启只有数据库认证的模式了,这种模式就可以用于生产环境了。这里的相关内容可以参考Authentication Manager相关的文档,地址如下https://apereo.github.io/cas/5.0.x/installation/Configuring-Authentication-Components.html#authentication-handlers。

配置相关参数

配置数据库认证相关的参数有四类,Query、Search、Bind、Encode,这四种的意思可以结合这篇文章理解一下。下面已Query方式为例配置。在application.properties文件中添加下面的配置。

cas.authn.jdbc.query[0].sql=SELECT login_pass FROM t_user WHERE username=?
cas.authn.jdbc.query[0].healthQuery=SELECT 1
cas.authn.jdbc.query[0].isolateInternalQueries=false
cas.authn.jdbc.query[0].url=jdbc:mysql://ip:port/castest?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
cas.authn.jdbc.query[0].failFast=true
cas.authn.jdbc.query[0].isolationLevelName=ISOLATION_READ_COMMITTED
cas.authn.jdbc.query[0].dialect=org.hibernate.dialect.MySQLDialect
cas.authn.jdbc.query[0].leakThreshold=10
cas.authn.jdbc.query[0].propagationBehaviorName=PROPAGATION_REQUIRED
cas.authn.jdbc.query[0].batchSize=1
cas.authn.jdbc.query[0].user=database-username
cas.authn.jdbc.query[0].ddlAuto=create-drop
cas.authn.jdbc.query[0].maxAgeDays=180
cas.authn.jdbc.query[0].password=database-password
cas.authn.jdbc.query[0].autocommit=false
cas.authn.jdbc.query[0].driverClass=com.mysql.jdbc.Driver
cas.authn.jdbc.query[0].idleTimeout=5000
# cas.authn.jdbc.query[0].credentialCriteria=

# cas.authn.jdbc.query[0].passwordEncoder.type=NONE|DEFAULT|STANDARD|BCRYPT
# cas.authn.jdbc.query[0].passwordEncoder.characterEncoding=
# cas.authn.jdbc.query[0].passwordEncoder.encodingAlgorithm=
# cas.authn.jdbc.query[0].passwordEncoder.secret=
# cas.authn.jdbc.query[0].passwordEncoder.strength=16

# cas.authn.jdbc.query[0].principalTransformation.suffix=
# cas.authn.jdbc.query[0].principalTransformation.caseConversion=NONE|UPPERCASE|LOWERCASE
# cas.authn.jdbc.query[0].principalTransformation.prefix=