審計
一旦引入 Spring Security,Spring Boot Actuator 就會有一個靈活的審計框架,用於釋出事件(預設情況下,包括“認證成功”、“認證失敗”和“訪問拒絕”異常)。此功能對於報告以及基於認證失敗實現鎖定策略非常有用。
你可以透過在應用程式配置中提供一個型別為 AuditEventRepository
的 bean 來啟用審計功能。為了方便起見,Spring Boot 提供了一個 InMemoryAuditEventRepository
。 InMemoryAuditEventRepository
的能力有限,我們建議僅在開發環境中使用它。對於生產環境,請考慮建立你自己的替代 AuditEventRepository
實現。
自定義審計
為了自定義釋出的安全性事件,你可以提供自己的 AbstractAuthenticationAuditListener
和 AbstractAuthorizationAuditListener
實現。
你也可以將審計服務用於你自己的業務事件。為此,可以將 AuditEventRepository
bean 注入到你自己的元件中直接使用,或者透過 Spring 的 ApplicationEventPublisher
(透過實現 ApplicationEventPublisherAware
)釋出 AuditApplicationEvent
。