單點登錄CAS-03:cas配置02-開啓/status

1、前言

CAS官方推薦使用/status/dashboard來管理CAS的配置,見https://apereo.github.io/cas/5.3.x/installation/Configuration-Management.html
在這裏插入圖片描述
點擊上圖的鏈接,進入文檔頁:https://apereo.github.io/cas/5.3.x/installation/Monitoring-Statistics.html
此頁面有一個應用映射表格列述如下:

應用路徑 作用描述
/status/dashboard The control panel to CAS server functionality and management
CAS服務器功能與管理的【控制面板】.
/status Monitor CAS status and other underlying components.
監控CAS狀態及其它底層組件
/status/sso Describes if there exists an active SSO session for this request tied to this browser session.
描述此請求是否存在綁定到此瀏覽器會話的活動SSO會話
/status/swf Describes the current configured state of CAS webflow in JSON.
描述JSON中CAS webflow的當前配置狀態
/status/stats Visual representation of CAS statistics with graphs and charts, etc.
CAS統計的圖形、圖表等可視化表示
/status/logging Monitor CAS logs in a streaming fashion and review the audit log.
以流式方式監視CAS日誌並查看審覈日誌
/status/config Visual representation of application properties and configuration.
應用程序屬性和配置的可視化表示
/status/ssosessions Reports active SSO sessions. Examine attributes, services and log users out.
報告活動的SSO會話。檢查屬性、服務並註銷用戶
/status/services Reports the collection of applications registered with CAS.
報告在CAS註冊的應用程序的集合
/status/trustedDevs Reports on the registered trusted devices/browsers.
關於註冊的受信任設備/瀏覽器的報告
/status/authnEvents When enabled, reports on the events captured by CAS.
啓用後,報告由CAS捕獲的事件
/status/attrresolution Examine resolution of user attributes via CAS attribute resolution.
通過CAS屬性解析檢查用戶屬性的解析
/status/discovery Advertises the CAS server’s profile, features and capabilities for auto-configuration of client applications.
宣傳CAS服務器的配置文件、功能和自動配置客戶端應用程序的功能

2、開啓/status/dashboard

CAS默認情況下,是禁用/status路徑的訪問的,如下圖:
在這裏插入圖片描述

2.1找到相關的配置項參數

在https://apereo.github.io/cas/5.3.x/installation/Configuration-Management.html頁面,點擊鏈接
在這裏插入圖片描述
進入到https://apereo.github.io/cas/5.3.x/installation/Configuration-Properties.html#cas-endpoints此處可看到需要配置的參數列表。
在這裏插入圖片描述
在頁面上按Ctrl+F查找"/status"可以看到有一段這樣的文字“The following properties describe access controls and settings for the /status endpoint of CAS which provides administrative functionality and oversight into the CAS software. These endpoints are specific to Spring Boot”。大意是說以下的屬性描述/status節點的訪問控制
在這裏插入圖片描述
綜上所述,我們找到了開啓/status權限需要了兩上配置列表,我將其列在下面,並且寫上備註以便理解。

2.1.1 Spring Boot Endpoints屬性列表

# Globally control whether endpoints are enabled
# 全局控制是否開啓endpoints節點
# or marked as sensitive to require authentication.
# 或標記sensitive爲要求授權(即設置爲true)

#所有終結點打開。默認爲false
#經驗證此選項爲true時,/cas/status/config能看到屬性列表,否則看不到
 endpoints.enabled=true
#所有終結點敏感。默認爲true
 endpoints.sensitive=true

#管理上下文路徑,默認爲/status。
management.contextPath=/status
#是否開啓管理安全,默認爲true
management.security.enabled=true
#管理安全用戶角色,默認爲ACTUATOR,ADMIN
management.security.roles=ACTUATOR,ADMIN
#是否管理安全會話,默認爲if_required
management.security.sessions=if_required

# Each of the below endpoints can either be disabled
# 以下每個endpoints既可禁用(enabled=false),
# or can be marked as 'sensitive' (or not)
# 也可以標記爲sensive即敏感項。
# to enable authentication. The global flags above control
# 來開啓授權。以上所列述是全局標誌控制所有內容
# everything and individual settings below act as overrides.
# 以下所述的是單獨設置用作覆蓋

# 以下配置默認是註釋掉的,此處將其打開
#配置列表《開始》
#------------------------------------------
#啓用/restart端點重新啓動應用程序上下文。如果設置爲true,則瀏覽器中輸入網址/cas/restart按回車,就自動重新啓動應用程序上下文
#注:設爲true後,在/cas/status/dashboard頁面會出現Reboot操作按鈕
 endpoints.restart.enabled=false
#啓用/shutdown端點來關閉應用程序。如果設置爲true,則瀏覽器中輸入網址/cas/shutdown按回車,就自動關閉應用的端點
#注:設爲true後,在/cas/status/dashboard頁面會出現shutdown操作按鈕
 endpoints.shutdown.enabled=false
# 啓用端點的自動配置。默認爲true
 endpoints.autoconfig.enabled=true
# 啓用端點的bean加載。默認爲true
 endpoints.beans.enabled=true
# 是否啓用總線
 endpoints.bus.enabled=true
# 是否啓用配置屬性 
 endpoints.configprops.enabled=true
#是否啓用dump。
 endpoints.dump.enabled=true
#是否啓用環境變化事件
 endpoints.env.enabled=true
#是否啓用節點健康檢查 
 endpoints.health.enabled=true
#是否啓用節點功能
 endpoints.features.enabled=true
#是否啓用info
 endpoints.info.enabled=true
#是否啓動節點日誌
 endpoints.loggers.enabled=true
#是否啓用節點日誌文件
 endpoints.logfile.enabled=true
#是否啓用節點追蹤
 endpoints.trace.enabled=true
#是否啓用節點文檔
 endpoints.docs.enabled=false
#是否啓用堆棧導出
 endpoints.heapdump.enabled=true
#配置列表《結束》
#------------------------------------------

# IP address may be enough to protect all endpoints.
#IP地址可能足以保護所有終結點
# It's set to always protect the /status endpoint.
#它設置爲始終保護/狀態終結點

#安全管理頁訪問時要校驗的IP地址。例如設置成127.0.0.1那麼在瀏覽器中只能用127.0.0.1來訪問,即使用localhost也是無權限訪問的。
#這樣做的用意是保護安全管理頁的訪問權限。此項默認是註釋掉的,默認值爲127\.0\.0\.1,這裏需要將其打開,否則是訪問不到的。
 cas.adminPagesSecurity.ip=127.0.0.1
#
# cas.adminPagesSecurity.alternateIpHeaderName=X-Forwarded-For

# If you wish to protect the admin pages via CAS itself, configure the rest.
#如果希望通過CAS本身保護管理頁,請配置其餘的配置項。

# cas登錄頁網址。默認不用開啓。如果開啓則要寫成應用的訪問路徑。
# cas.adminPagesSecurity.loginUrl=https://sso.example.org/cas/login
#cas控制面板網址。默認不用開啓。如果開啓則要寫成應用的訪問路徑。
# cas.adminPagesSecurity.service=https://sso.example.org/cas/status/dashboard
#cas安全管理頁的用戶帳號。這裏可以指向一個配置文件
# 如果不指定帳號文件,則默認會讀取user-details.properties
#cas.adminPagesSecurity.users=file:/etc/cas/config/adminusers.properties
#cas安全管理頁的角色。
# cas.adminPagesSecurity.adminRoles[0]=ROLE_ADMIN
#是否啓用CAS安全管理頁執行者節點。默認爲tree
# cas.adminPagesSecurity.actuatorEndpointsEnabled=true

2.1.2 CAS Endpoints屬性列表

cas.monitor.endpoints
#終結點dashboard對應uri爲/cas/status/dashboard
#這是一個快捷方式頁面,裏面有很多按鈕可以進入到其他節點
cas.monitor.endpoints.dashboard
cas.monitor.endpoints.discovery
cas.monitor.endpoints.auditEvents
#管理身份驗證事件,終結點/cas/status/authnEvents
cas.monitor.endpoints.authenticationEvents
#配置頁,終結點/cas/status/config
cas.monitor.endpoints.configurationState
cas.monitor.endpoints.healthCheck
#查看日誌,終結點/cas/status/logging
cas.monitor.endpoints.loggingConfig
#度量指標,終結點/cas/status/metrics
cas.monitor.endpoints.metrics
#屬性配置列表,終結點/cas/status/attrresolution
cas.monitor.endpoints.attributeResolution
cas.monitor.endpoints.singleSignOnReport
#ticket憑證統計,終結點/cas/status/stats
cas.monitor.endpoints.statistics
cas.monitor.endpoints.trustedDevices
#cas狀態,終結點/cas/status
#注:該終結點不會影響子級終結點。例如
#-------------------------------------------------
#cas.monitor.endpoints.status.enabled=false
#cas.monitor.endpoints.dashboard.enabled=true
#-------------------------------------------------
#如上配置/cas/status不能訪問,但是/cas/status/dashboard仍能訪問
cas.monitor.endpoints.status
#單點登錄,終結點/cas/status/sso
cas.monitor.endpoints.singleSignOnStatus
#springWebflow,終結點/cas/status/swf
#注此配置.enabled只能控制dashboard面板是否顯示模塊入口,即使.enabled=false瀏覽器輸入網址仍能訪問
cas.monitor.endpoints.springWebflowReport
#服務註冊,終結點/cas/status/services
cas.monitor.endpoints.registeredServicesReport
#配置元數據,終結點/cas/status/configmetadata
cas.monitor.endpoints.configurationMetadata

注 :CAS Endpoints的屬性列表只是給出了一個屬性項目,每個項目有兩個參數enabled(是否啓用true或false),sensitive(用於標誌該配置是否敏感信息——即是否需要授權的操作,如果設置爲true,則所有的原生端點都需要授權操作,設置爲false則不需要,默認是false)

因此可以得到一個設置CAS Endpoints的屬性的原則

  1. 所有的enabled屬性應該設置爲true
  2. 所有的sensitive屬性應該設置爲false——需要嚴格授權的情況除外

參考文章:https://www.iteye.com/blog/357029540-2392530

此處引述作者的話
2.endpoints.enabled
該配置屬性用於控制所有的訪問原生端點的可用性,設置爲false的時候所有的原生端點都不可以訪問,設置爲true時所有的原生端點可以訪問。默認爲true。
3.endpoints.{name}.enabled
該配置屬性是相對endpoints.enabled來說的,endpoints.enabled是將所有的原生端點的禁止訪問,而enedpoints.{name}.enabled屬性是針對某個具體的原生端點進行控制,設置爲true時該原生端點可以訪問,設置爲false的時候不可訪問,默認爲true。
4.endpoints.sensitive
該配置屬性用於配置敏感信息,即是否需要授權的操作,如果設置爲true,則所有的原生端點都需要授權操作,設置爲false則不需要,默認是false,這裏需要注意的是如果沒有主動設置該值的話,有些原生端點是需要授權才能訪問的,如/beans,/env等,當與management.security.enabled一起使用時以management.security.enabled爲主。
5.endpoints.{name}.sensitive
該配置屬性是相對endpoints.sensitive來說的,endpoints.sensitive是將所有的原生端點進行授權操作,而endpoints.{name}.sensitive是對某個具體的原生端點進行控制,設置爲true時該原生端點需要授權操作,設置爲false的時候不需要授權訪問,具體的默認值需要看具體的原生端點。

2.2 配置案例演示

在cas-overlay-template工程目錄下創建src\main\resources\文件夾,所有的配置文件放到這裏面去。
默認的配置文件可以從cas.war文件中獲得。如果你沒有cas.war,請看前面的博文:單點登錄CAS-02:如何得到一個cas.war?
請先下載工程執行mvn clean package得到一個默認的cas.war。

2.2.1 案例1:使用全局性配置

本案例使用到文件:application.properties。這個文件的默認版本能從cas.war中獲得。
以下配置加入到application.properties中,如果配置項已存在則覆蓋。

#安全管理頁訪問時要校驗的IP地址。例如設置成127.0.0.1那麼在瀏覽器中只能用127.0.0.1來訪問,即使用localhost也是無權限訪問的。
#這樣做的用意是保護安全管理頁的訪問權限。此項默認是註釋掉的,默認值爲127\.0\.0\.1,這裏需要將其打開,否則是訪問不到的。
 cas.adminPagesSecurity.ip=127.0.0.1
#管理上下文路徑,默認爲/status。
management.contextPath=/status
#是否開啓管理安全,默認爲true
management.security.enabled=true
#管理安全用戶角色,默認爲ACTUATOR,ADMIN
management.security.roles=ACTUATOR,ADMIN
#是否管理安全會話,默認爲if_required
management.security.sessions=if_required

#節點開關配置(全局)
cas.monitor.endpoints.enabled=true
cas.monitor.endpoints.sensitive=false

2.2.2 案例1:驗證

cmd窗口進入cas-overlay-template工程目錄,執行mvn clean package生成cas.war後部署到tomcat\webapps目錄下。
啓動tomcat加載完成後,打開瀏覽器訪問網址http://127.0.0.1:7711/cas/status/dashboard。
在這裏插入圖片描述
以上可以看到即使不登錄用戶,也是可以訪問/status/dashboard頁面的。

2.2.3 案例2:明細配置版本

本案例使用到文件:application.properties。這個文件的默認版本能從cas.war中獲得。
以下配置加入到application.properties中,如果配置項已存在則覆蓋。

#安全管理頁訪問時要校驗的IP地址。例如設置成127.0.0.1那麼在瀏覽器中只能用127.0.0.1來訪問,即使用localhost也是無權限訪問的。
#這樣做的用意是保護安全管理頁的訪問權限。此項默認是註釋掉的,默認值爲127\.0\.0\.1,這裏需要將其打開,否則是訪問不到的。
 cas.adminPagesSecurity.ip=127.0.0.1
#管理上下文路徑,默認爲/status。
management.contextPath=/status
#是否開啓管理安全,默認爲true
management.security.enabled=true
#管理安全用戶角色,默認爲ACTUATOR,ADMIN
management.security.roles=ACTUATOR,ADMIN
#是否管理安全會話,默認爲if_required
management.security.sessions=if_required

#節點開關配置(全局)
#cas.monitor.endpoints.enabled=true
#cas.monitor.endpoints.sensitive=false

#節點開關配置(明細)。每項後面指定enabled和sensitive
cas.monitor.endpoints.dashboard.enabled=true
cas.monitor.endpoints.dashboard.sensitive=false

cas.monitor.endpoints.discovery.enabled=true
cas.monitor.endpoints.discovery.sensitive=false

cas.monitor.endpoints.auditEvents.enabled=true
cas.monitor.endpoints.auditEvents.sensitive=false

cas.monitor.endpoints.authenticationEvents.enabled=true
cas.monitor.endpoints.authenticationEvents.sensitive=false

cas.monitor.endpoints.configurationState.enabled=true
cas.monitor.endpoints.configurationState.sensitive=false

cas.monitor.endpoints.healthCheck.enabled=true
cas.monitor.endpoints.healthCheck.sensitive=false

cas.monitor.endpoints.loggingConfig.enabled=true
cas.monitor.endpoints.loggingConfig.sensitive=false

cas.monitor.endpoints.metrics.enabled=true
cas.monitor.endpoints.metrics.sensitive=false

cas.monitor.endpoints.attributeResolution.enabled=true
cas.monitor.endpoints.attributeResolution.sensitive=false

cas.monitor.endpoints.singleSignOnReport.enabled=true
cas.monitor.endpoints.singleSignOnReport.sensitive=false

cas.monitor.endpoints.statistics.enabled=true
cas.monitor.endpoints.statistics.sensitive=false

cas.monitor.endpoints.trustedDevices.enabled=true
cas.monitor.endpoints.trustedDevices.sensitive=false

cas.monitor.endpoints.status.enabled=true
cas.monitor.endpoints.status.sensitive=false

cas.monitor.endpoints.singleSignOnStatus.enabled=true
cas.monitor.endpoints.singleSignOnStatus.sensitive=false

cas.monitor.endpoints.springWebflowReport.enabled=true
cas.monitor.endpoints.springWebflowReport.sensitive=false

cas.monitor.endpoints.registeredServicesReport.enabled=true
cas.monitor.endpoints.registeredServicesReport.sensitive=false

cas.monitor.endpoints.configurationMetadata.enabled=true
cas.monitor.endpoints.configurationMetadata.sensitive=false

2.2.4 案例2:驗證

cmd窗口進入cas-overlay-template工程目錄,執行mvn clean package生成cas.war後部署到tomcat\webapps目錄下。
啓動tomcat加載完成後,打開瀏覽器訪問網址http://127.0.0.1:7711/cas/status/dashboard。
在這裏插入圖片描述
打開瀏覽器訪問網址http://127.0.0.1:7711/cas/status/dashboard。
在這裏插入圖片描述
以上可以看到即使不登錄用戶,也是可以訪問/status/dashboard和/status/stats頁面的。

2.2.3 案例3:明細配置版本-禁用某節點

本案例使用到文件:application.properties。這個文件的默認版本能從cas.war中獲得。
以下配置加入到application.properties中,如果配置項已存在則覆蓋。

#安全管理頁訪問時要校驗的IP地址。例如設置成127.0.0.1那麼在瀏覽器中只能用127.0.0.1來訪問,即使用localhost也是無權限訪問的。
#這樣做的用意是保護安全管理頁的訪問權限。此項默認是註釋掉的,默認值爲127\.0\.0\.1,這裏需要將其打開,否則是訪問不到的。
 cas.adminPagesSecurity.ip=127.0.0.1
#管理上下文路徑,默認爲/status。
management.contextPath=/status
#是否開啓管理安全,默認爲true
management.security.enabled=true
#管理安全用戶角色,默認爲ACTUATOR,ADMIN
management.security.roles=ACTUATOR,ADMIN
#是否管理安全會話,默認爲if_required
management.security.sessions=if_required

#節點開關配置(全局)
#cas.monitor.endpoints.enabled=true
#cas.monitor.endpoints.sensitive=false

#節點開關配置(明細)。每項後面指定enabled和sensitive
cas.monitor.endpoints.dashboard.enabled=true
cas.monitor.endpoints.dashboard.sensitive=false

cas.monitor.endpoints.discovery.enabled=true
cas.monitor.endpoints.discovery.sensitive=false

cas.monitor.endpoints.auditEvents.enabled=true
cas.monitor.endpoints.auditEvents.sensitive=false

cas.monitor.endpoints.authenticationEvents.enabled=true
cas.monitor.endpoints.authenticationEvents.sensitive=false

cas.monitor.endpoints.configurationState.enabled=true
cas.monitor.endpoints.configurationState.sensitive=false

cas.monitor.endpoints.healthCheck.enabled=true
cas.monitor.endpoints.healthCheck.sensitive=false

cas.monitor.endpoints.loggingConfig.enabled=true
cas.monitor.endpoints.loggingConfig.sensitive=false

cas.monitor.endpoints.metrics.enabled=true
cas.monitor.endpoints.metrics.sensitive=false

cas.monitor.endpoints.attributeResolution.enabled=true
cas.monitor.endpoints.attributeResolution.sensitive=false

cas.monitor.endpoints.singleSignOnReport.enabled=true
cas.monitor.endpoints.singleSignOnReport.sensitive=false

#關閉/status/stats
cas.monitor.endpoints.statistics.enabled=false
cas.monitor.endpoints.statistics.sensitive=false

cas.monitor.endpoints.trustedDevices.enabled=true
cas.monitor.endpoints.trustedDevices.sensitive=false

cas.monitor.endpoints.status.enabled=true
cas.monitor.endpoints.status.sensitive=false

cas.monitor.endpoints.singleSignOnStatus.enabled=true
cas.monitor.endpoints.singleSignOnStatus.sensitive=false

cas.monitor.endpoints.springWebflowReport.enabled=true
cas.monitor.endpoints.springWebflowReport.sensitive=false

cas.monitor.endpoints.registeredServicesReport.enabled=true
cas.monitor.endpoints.registeredServicesReport.sensitive=false

cas.monitor.endpoints.configurationMetadata.enabled=true
cas.monitor.endpoints.configurationMetadata.sensitive=false

2.2.4 案例3:驗證

cmd窗口進入cas-overlay-template工程目錄,執行mvn clean package生成cas.war後部署到tomcat\webapps目錄下。
啓動tomcat加載完成後,打開瀏覽器訪問網址http://127.0.0.1:7711/cas/status/dashboard。
在這裏插入圖片描述
打開瀏覽器訪問網址http://127.0.0.1:7711/cas/status/stats。
在這裏插入圖片描述
以上可以看到當設置cas.monitor.endpoints.statistics.enabled=false時/status/stats模塊無法訪問了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章