單點登錄CAS-03:cas配置01-配置文件類型

1、前言

要了解一個框架或程序如何運行,以及如何定製運行。最好的方式就是研究它的每一個配置文件,每一個配置屬性,以及屬性的含義和用途。    

2、配置文件分類

用壓縮工具打開cas.war文件,進入cas.war\WEB-INF\classes\目錄即可看到有許多的.properties和.xml文件。列表如下:

用途 文件名 說明
web配置 apereo.properties
cas-theme-default.properties
js和css路徑配置
日誌輸出 log4j2.xml 日誌級別或路徑配置
注:在windows需改此文件,默認是linux路徑
國際化 messages.properties
messages_{地區後綴}.properties
用於控制web頁面顯示內容
SSL認證 truststore.jks 使用keyTool工具生成
使用https需要重新生成此文件
spring clound配置 bootstrap.properties 若使用spring clound則修改此文件
用戶權限 user-details.properties 定義用戶角色等,一般不會使用到。
CAS配置 application.yml
application.properties
默認.yml爲空
這是主要的配置入口

3、application.properties詳解

application.properties包含cas運行所需要的一系列參數。若要自定義此配置文件,可以創建application.properties到cas-overlay-template\src\main\resources\目錄下,然後重新執行maven構建生成war包。
不建議直接修改cas.war中的配置文件,因爲如果這樣做,當重新cas.war時,所修改的配置就會丟失了。

3.1springboot相關參數

注:內置容器是指cas.war包含了tomcat的jar包,以springboot方式運行
如果cas.war放在tomcat/webapps/下運行,以下參數無效!

3.1.1 內置容器配置

##
# CAS Server Context Configuration
# CAS服務應用上下文配置
#
#Web應用名稱
server.context-path=/cas
#應用監聽端口
server.port=8443

# 以下是SSL證書相關參數。若要禁用SSL功能請註釋掉以下參數,或者給以下參數設置空值。
#
#SSL證書(https)保存路徑
server.ssl.key-store=file:/etc/cas/thekeystore
#SSL證書密鑰庫
server.ssl.key-store-password=changeit
#SSL證書密碼
server.ssl.key-password=changeit

#單次http請求的header頭最大長度2MB=2097152/1024/1024
server.max-http-header-size=2097152
#轉發http報文時是否連header頭一起轉發?
server.use-forward-headers=true
#連接超時時長2秒=2 * 1000
server.connection-timeout=20000
#服務器發生錯誤時,錯誤信息是否要包含堆棧信息
server.error.include-stacktrace=ALWAYS

#是否壓縮http報文
server.compression.enabled=true
#要壓縮的報文格式
server.compression.mime-types=application/javascript,application/json,application/xml,text/html,text/xml,text/plain
######################################################
#               以下是tomcat相關配置
######################################################
#單次http請求的header頭最大長度2MB=2097152/1024/1024
server.tomcat.max-http-post-size=2097152
#存放Tomcat日誌、Dump等文件的臨時文件夾,默認爲系統的tmp文件夾
server.tomcat.basedir=build/tomcat
#打開Tomcat的Access日誌,並可以設置日誌格式的方法
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
server.tomcat.accesslog.suffix=.log
#tomcat初始會創建的線程數
server.tomcat.min-spare-threads=10
#tomcat最大線程數,默認爲200
server.tomcat.max-threads=200
#設定http header使用的,用來覆蓋原來port的value.
server.tomcat.port-header=X-Forwarded-Port
#設定Header包含的協議,通常是 X-Forwarded-Proto,如果remoteIpHeader有值,則將設置爲RemoteIpValve.
server.tomcat.protocol-header=X-Forwarded-Proto
#設定使用SSL的header的值,默認https.
server.tomcat.protocol-header-https-value=https
#設定remote IP的header,如果remoteIpHeader有值,則設置爲RemoteIpValve
server.tomcat.remote-ip-header=X-FORWARDED-FOR
#tomcat的默認URI解碼字符集
server.tomcat.uri-encoding=UTF-8

#springboot的http請求編碼格式
spring.http.encoding.charset=UTF-8
#是否爲springboot指定http請求的編碼
spring.http.encoding.enabled=true
#是否對springboot指定http請求編制編碼
spring.http.encoding.force=true

3.1.2 spring雲總線配置

#是否啓用spring雲總結。默認false
spring.cloud.bus.enabled=false

# 指示是否用本機屬性覆蓋雲總線的配置
#如果想要遠程配置優先級高,那麼allowOverride設置爲false,如果想要本地配置優先級高那麼allowOverride設置爲true。默認爲true。
spring.cloud.config.allow-override=true

#外部配置是否可覆蓋本機的配置.
spring.cloud.config.override-system-properties=false

# When allowOverride is true, external properties should take lowest priority, and not override any
# existing property sources (including local config files).
#外部源配置是否不覆蓋任何源
spring.cloud.config.override-none=false

#是否動態刷新總線配置
# spring.cloud.bus.refresh.enabled=true
#是否啓用環境變化事件
# spring.cloud.bus.env.enabled=true
#總線使用的隊列或主題名稱
# spring.cloud.bus.destination=CasCloudBus
#是否啓用總線ack消息確認,若不確認成功則重發
# spring.cloud.bus.ack.enabled=true

#如CAS訪問地址是http://localhost/cas
#則默認訪問http://localhost/cas/status/dashboard會提示沒權限。
#要打開status需要修改下面的配置。
在application.properties中修改和增加如下的信息:
#enabled要設置爲true, sensitive要設置爲false
endpoints.enabled=false
endpoints.sensitive=true

endpoints.restart.enabled=false
endpoints.shutdown.enabled=false
##

3.1.3安全管理


# Control the security of the management/actuator endpoints
# The 'enabled' flag below here controls the rendering of details for the health endpoint amongst other things.
#啓用安全管理
management.security.enabled=true
#安全管理的角色:執行者,管理員
management.security.roles=ACTUATOR,ADMIN
#安全管理session
management.security.sessions=if_required
#安全管理上下文(應用名)
management.context-path=/status
#在每個響應中添加“X-Application-Context”HTTP頭
management.add-application-context-header=false
# Define a CAS-specific "WARN" status code and its order
#管理健康狀態的順序
management.health.status.order=WARN, DOWN, OUT_OF_SERVICE, UNKNOWN, UP

# Control the security of the management/actuator endpoints
# With basic authentication, assuming Spring Security and/or relevant modules are on the classpath.
#安全基礎鑑權模式:通過角色鑑權
security.basic.authorize-mode=role
#安全基礎路徑
security.basic.path=/cas/status/**
#安全基礎啓用
# security.basic.enabled=true
#安全用戶名
# security.user.name=casuser
#安全用戶密碼
# security.user.password=

3.1.4CAS Web應用會話配置

##
# CAS Web Application Session Configuration
#
#會話超時時長,默認300
server.session.timeout=300
#是否設置Cookie沒有安全標誌
#如果在Cookie中設置了"HttpOnly"屬性,那麼通過程序(JS腳本、Applet等)將無法讀取到Cookie信息,這樣能有效的防止XSS攻擊。
server.session.cookie.http-only=true
#設定Session的追蹤模式(cookie, url, ssl)
server.session.tracking-modes=COOKIE

3.1.5 thymeleaf模板引擎配置

##
# CAS Thymeleaf View Configuration
#
#模板編碼格式,默認UTF-8
spring.thymeleaf.encoding=UTF-8
#是否啓用模板緩存。默認true
spring.thymeleaf.cache=true
#模板格式校驗(LEGACYHTML5,HTML5,HTML)
#LEGACYHTML5——嚴格校驗
spring.thymeleaf.mode=HTML
##Thymeleaf模板解析器在解析器鏈中的順序。默認情況下,它排第一位。順序從1開始,只有在定義了額外的TemplateResolver Bean時才需要設置這個屬性。
spring.thymeleaf.template-resolver-order=100

3.1.6 log4j配置

##
# CAS Log4j Configuration
#
# logging.config=file:/etc/cas/log4j2.xml
#是否禁用log4j自動初始化?
server.context-parameters.isLog4jAutoInitializationDisabled=true

3.1.7 CAS切面配置

##
# CAS AspectJ Configuration
#
#是否自動啓用aop切面
spring.aop.auto=true
#是否使用切面代理目標類
spring.aop.proxy-target-class=true

3.2 CAS 登錄帳號配置

##
# CAS Authentication Credentials
# 用戶名:casuser,密碼:Mellon
cas.authn.accept.users=casuser::Mellon
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章