cas5.2版本是基于springboot的,一般情况下,我们是使用的 application.properties 配置文件,但是有一天,有人说我希望使用application.yml 的文件,不喜欢用properties这种方式,其实也是可以实现的,我采取的策略是,先放置一个空的application.properties文件在工程目录中,然后正常配置application.yml文件。
观察war包内容发现,其实Cas官方也是用的同样的方法,只不过cas是默认使用application.properties,把application.yml文件设置为了空内容
一、配置cas
主要是通过让application.properties空文件,替换掉默认war包的配置,然后读取完application.properties后,再读取yml文件,这样就完美的解决了通过yml启动cas了。
1、配置application.properties
用一个空的目录,来替换掉war包目录下的默认配置
## # CAS Server Context Configuration #
2、配置application.yml
推荐大家去直接使用工具将properites相互转化,自己动手写太慢了。
properties转化为yml的网站:https://www.bejson.com/devtools/properties2yaml/ 或者 http://www.toyaml.com
##
# CAS Cloud Bus Configuration
#
spring:
cloud:
bus:
enabled: false
##
# CAS AspectJ 配置
#
aop:
proxy-target-class: true
auto: true
http:
encoding:
charset: UTF-8
force: true
enabled: true
##
# CAS Thymeleaf View 配置
#
thymeleaf:
mode: HTML
cache: true
encoding: UTF-8
##
# CAS Server Context 配置
#
server:
connection-timeout: 20000
context-path: /cas
tomcat:
basedir: build/tomcat
remote-ip-header: X-FORWARDED-FOR
uri-encoding: UTF-8
protocol-header: X-Forwarded-Proto
protocol-header-https-value: https
port-header: X-Forwarded-Port
max-threads: 10
max-http-post-size: 2097152
accesslog:
pattern: '%t %a \%r\ %s (%D ms)'
suffix: .log
enabled: true
port: 8443
max-http-header-size: 2097152
##
# CAS Web Application Session 配置
#
session:
tracking-modes: COOKIE
cookie:
http-only: true
timeout: 300
context-parameters:
isLog4jAutoInitializationDisabled: true
compression:
mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain
enabled: true
error:
include-stacktrace: ALWAYS
##
# 证书配置
#
ssl:
key-password: changeit
key-store: file:/etc/cas/thekeystore
key-store-password: changeit
use-forward-headers: true
security:
basic:
path: /cas/status/**
authorize-mode: role
enabled: false
endpoints:
restart:
enabled: false
sensitive: true
shutdown:
enabled: false
enabled: false
##
# CAS 身份验证凭证
#
cas:
authn:
accept:
users: tingfeng::tingfeng
management:
security:
sessions: if_required
roles: ACTUATOR,ADMIN
enabled: true
context-path: /status
add-application-context-header: false
二、启动服务测试
#直接启动,不debug了 build.cmd run
登录成功页面
三、源码下载
源码地址:https://github.com/X-rapido/CAS_SSO_Record
四、常见问题
yml文件报错
报错的原因是%是特殊符号,表示是命令,需要加上单引号,表示是字符串
加上单引号后,就不抱错了。
未经允许请勿转载:程序喵 » Cas 5.2.x版本使用 —— 通过yml的方式配置(四)
程序喵