稽核

一旦 Spring Security 啟動,Spring Boot Actuator 會有一個彈性的稽核框架,用於發布事件(預設為「驗證成功」、「失敗」和「拒絕存取」例外)。此功能對於報告和實作基於驗證失敗的鎖定策略非常有用。

您可以透過在應用程式組態中提供 AuditEventRepository 類型的 bean 來啟用稽核。為了方便起見,Spring Boot 提供了 InMemoryAuditEventRepositoryInMemoryAuditEventRepository 的功能有限,我們建議僅在開發環境中使用。對於生產環境,請考慮建立您自己的替代 AuditEventRepository 實作。

自訂稽核

若要自訂發布的安全性事件,您可以提供您自己實作的 AbstractAuthenticationAuditListenerAbstractAuthorizationAuditListener

您也可以將稽核服務用於您自己的業務事件。為此,您可以將 AuditEventRepository bean 注入到您自己的元件中並直接使用,或使用 Spring ApplicationEventPublisher 發布 AuditApplicationEvent(透過實作 ApplicationEventPublisherAware)。