審計

一旦 Spring Security 生效,Spring Boot Actuator 就有一個靈活的審計框架,可以釋出事件(預設情況下是“認證成功”、“失敗”和“訪問拒絕”異常)。此功能對於報告和實現基於認證失敗的鎖定策略非常有用。

您可以透過在應用程式配置中提供一個型別為 AuditEventRepository 的 bean 來啟用審計。為了方便起見,Spring Boot 提供了一個 InMemoryAuditEventRepositoryInMemoryAuditEventRepository 功能有限,我們建議僅在開發環境中使用它。對於生產環境,請考慮建立自己的替代 AuditEventRepository 實現。

自定義審計

要自定義釋出的安全性事件,您可以提供自己的 AbstractAuthenticationAuditListenerAbstractAuthorizationAuditListener 實現。

您還可以將審計服務用於自己的業務事件。為此,可以將 AuditEventRepository bean 注入到您自己的元件中並直接使用它,或者透過 Spring ApplicationEventPublisher 釋出一個 AuditApplicationEvent(透過實現 ApplicationEventPublisherAware)。

© . This site is unofficial and not affiliated with VMware.