Auditing Configuration for Cassandra

要激活审计功能,创建一个配置,如下面的示例所示:

To activate auditing functionality, create a configuration as the following example shows:

Activating auditing through configuration
  • Java

  • XML

@Configuration
@EnableCassandraAuditing
class Config {

  @Bean
  public AuditorAware<AuditableUser> myAuditorProvider() {
      return new AuditorAwareImpl();
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:cassandra="http://www.springframework.org/schema/data/cassandra"
  xsi:schemaLocation="
    http://www.springframework.org/schema/data/cassandra
    https://www.springframework.org/schema/data/cassandra/spring-cassandra.xsd
    http://www.springframework.org/schema/beans
    https://www.springframework.org/schema/beans/spring-beans.xsd">

    <cassandra:auditing mapping-context-ref="customMappingContext" auditor-aware-ref="yourAuditorAwareImpl"/>
</beans>

如果你向 ApplicationContext 公开类型为 AuditorAware 的 Bean,则审计基础设施会自动将其提取出来,并使用它来确定在域类型上设置的当前用户,如果你在 ApplicationContext 中注册了多个实现,那么你可以通过显式设置 @EnableCassandraAuditingauditorAwareRef 属性来选择要使用的实现。

If you expose a bean of type AuditorAware to the ApplicationContext, the auditing infrastructure picks it up automatically and uses it to determine the current user to be set on domain types. If you have multiple implementations registered in the ApplicationContext, you can select the one to be used by explicitly setting the auditorAwareRef attribute of @EnableCassandraAuditing.

要启用审计,利用响应式编程模型,请使用 @EnableReactiveCassandraAuditing 注解,如果你向 ApplicationContext 公开类型为 ReactiveAuditorAware 的 Bean,则审计基础设施会自动将其提取出来,并使用它来确定在域类型上设置的当前用户,如果你在 ApplicationContext 中注册了多个实现,那么你可以通过显式设置 @EnableReactiveCassandraAuditingauditorAwareRef 属性来选择要使用的实现。

To enable auditing, leveraging a reactive programming model, use the @EnableReactiveCassandraAuditing annotation. If you expose a bean of type ReactiveAuditorAware to the ApplicationContext, the auditing infrastructure picks it up automatically and uses it to determine the current user to be set on domain types. If you have multiple implementations registered in the ApplicationContext, you can select the one to be used by explicitly setting the auditorAwareRef attribute of @EnableReactiveCassandraAuditing.

Example 1. Activating reactive auditing using JavaConfig
@Configuration
@EnableReactiveCassandraAuditing
class Config {

  @Bean
  public ReactiveAuditorAware<AuditableUser> myAuditorProvider() {
      return new AuditorAwareImpl();
  }
}