方法安全性
<method-security>
此元素是用於新增 Spring Security Bean 的方法安全支援的主要方式。方法可以透過使用註解(在介面或類別層級定義)或透過定義一組切入點來保護。
<method-security> 屬性
-
pre-post-enabled 啟用此應用程式內容的 Spring Security 前置和後置調用註解 (@PreFilter、@PreAuthorize、@PostFilter、@PostAuthorize)。預設為 "true"。
-
secured-enabled 啟用此應用程式內容的 Spring Security @Secured 註解。預設為 "false"。
-
jsr250-enabled 啟用此應用程式內容的 JSR-250 授權註解 (@RolesAllowed、@PermitAll、@DenyAll)。預設為 "false"。
-
mode 若設定為 "aspectj",則使用 AspectJ 來攔截方法調用。
-
proxy-target-class 若為 true,將使用基於類別的代理,而非基於介面的代理。預設為 "false"。
-
security-context-holder-strategy-ref 指定在檢索 SecurityContext 時要使用的 SecurityContextHolderStrategy。預設為 SecurityContextHolder.getContextHolderStrategy() 傳回的值。
-
observation-registry-ref 用於
FilterChain
和相關元件的ObservationRegistry
參考
<global-method-security>
此元素是用於新增 Spring Security Bean 的方法安全支援的主要方式。方法可以透過使用註解(在介面或類別層級定義)或透過定義一組切入點作為子元素,使用 AspectJ 語法來保護。
<global-method-security> 屬性
-
access-decision-manager-ref 方法安全性使用與網路安全性相同的
AccessDecisionManager
組態,但可以使用此屬性覆寫。預設情況下,AffirmativeBased 實作會與 RoleVoter 和 AuthenticatedVoter 一起使用。
-
authentication-manager-ref 應使用於方法安全性的
AuthenticationManager
參考。
-
jsr250-annotations 指定是否要使用 JSR-250 樣式屬性(例如 "RolesAllowed")。這會要求 classpath 上有 javax.annotation.security 類別。將此設定為 true 也會將
Jsr250Voter
新增至AccessDecisionManager
,因此如果您正在使用自訂實作並想要使用這些註解,則需要確保執行此操作。
-
metadata-source-ref 可以提供外部
MethodSecurityMetadataSource
實例,其優先順序高於其他來源(例如預設註解)。
-
mode 此屬性可以設定為 "aspectj",以指定應使用 AspectJ 而非預設 Spring AOP。受保護的方法必須與來自
spring-security-aspects
模組的AnnotationSecurityAspect
編織在一起。
重要的是要注意,AspectJ 遵循 Java 的規則,即介面上的註解不會被繼承。這表示在介面上定義安全性註解的方法將不會受到保護。相反地,在使用 AspectJ 時,您必須將安全性註解放在類別上。
-
order 允許為方法安全性攔截器設定建議 "order"。
-
pre-post-annotations 指定是否應為此應用程式內容啟用 Spring Security 的前置和後置調用註解 (@PreFilter、@PreAuthorize、@PostFilter、@PostAuthorize)。預設為 "disabled"。
-
proxy-target-class 若為 true,將使用基於類別的代理,而非基於介面的代理。
-
run-as-manager-ref
RunAsManager
實作的可選參考,將由已組態的MethodSecurityInterceptor
使用
-
secured-annotations 指定是否應為此應用程式內容啟用 Spring Security 的 @Secured 註解。預設為 "disabled"。
<after-invocation-provider>
<pre-post-annotation-handling>
<invocation-attribute-factory>
<post-invocation-advice>
<pre-invocation-advice>
使用 <protect-pointcut>
保護方法
您可以使用 <protect-pointcut>
元素,跨服務層中的整組方法和介面定義跨領域的安全性限制,而不是使用 @Secured
註解在個別方法或類別基礎上定義安全性屬性。您可以在命名空間簡介中找到範例。