[英]Annotation based Auditing for spring-data-elasticsearch?
I am trying to use the annotation based approach to audit my elasticsearch document using spring-data-elasticsearch.我正在尝试使用基于注释的方法来使用 spring-data-elasticsearch 审计我的 elasticsearch 文档。 I followed the JPA guide while implementing my classes/setup.
我在实现我的类/设置时遵循了 JPA 指南。
My code looks like this:我的代码如下所示:
@Configuration
@EnableJpaAuditing
public class SpringSecurityAuditorAwareConfiguration {
@Bean
public AuditorAware<String> auditorProvider() {
return new SpringSecurityAuditorAware();
}
}
public class SpringSecurityAuditorAware implements AuditorAware<String> {
public Optional<String> getCurrentAuditor() {
return Optional.ofNullable(SecurityContextHolder.getContext())
.map(SecurityContext::getAuthentication)
.filter(Authentication::isAuthenticated)
.map(Authentication::getPrincipal)
.map(User.class::cast)
.map(User::getUsername);
}
}
@Document(indexName = "myEntity", type = "myEntityType")
public class MyEntity {
@Id
private String id;
@CreatedBy
protected String createdBy;
@CreatedDate
protected OffsetDateTime createdDate;
@LastModifiedBy
protected String lastModifiedBy;
@LastModifiedDate
protected OffsetDateTime lastModifiedDate;
public void setDictionaryId(DictionaryId dictionaryId) {
this.dictionaryId = dictionaryId;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public OffsetDateTime getCreatedDate() {
return createdDate;
}
public void setCreatedDate(OffsetDateTime createdDate) {
this.createdDate = createdDate;
}
public String getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public OffsetDateTime getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(OffsetDateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
Unfortunately it when I save a new instance the properties are always set to null.不幸的是,当我保存一个新实例时,属性总是设置为 null。 Does spring-data-elasticsearch support the annotation based approach?
spring-data-elasticsearch 是否支持基于注解的方法?
Edit:编辑:
This is implemented since version 4.0 which has been released in May 2020.这是自 2020 年 5 月发布的 4.0 版以来实施的。
Original answer:原答案:
No, this is currently not supported in Spring Data Elasticsearch.不,Spring Data Elasticsearch 目前不支持此功能。
Please create a ticket to add support for this, this is definitely a feature worth to have.请创建一张票来添加对此的支持,这绝对是一个值得拥有的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.