24 lines
1.4 KiB
Java
24 lines
1.4 KiB
Java
package com.baiyue.common.audit;
|
|||
|
|
|
||
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||
|
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||
|
|
import org.springframework.context.annotation.Bean;
|
||
|
|
import org.springframework.web.client.RestClient;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 业务审计自动配置,按配置创建脱敏器、审计输出端和审计切面。
|
||
|
|
*/
|
||
|
|
@AutoConfiguration
|
||
|
|
@EnableConfigurationProperties(AuditProperties.class)
|
||
|
|
@ConditionalOnProperty(prefix = "baiyue.audit", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||
|
|
public class BaiyueAuditAutoConfiguration {
|
||
|
|
@Bean @ConditionalOnMissingBean AuditSink auditSink(RestClient.Builder builder, AuditProperties p) {
|
||
|
|
return p.getEndpoint() == null || p.getEndpoint().isBlank() ? new LoggingAuditSink() : new HttpAuditSink(builder, p.getEndpoint());
|
||
|
|
}
|
||
|
|
@Bean SensitiveDataSanitizer sensitiveDataSanitizer(ObjectMapper mapper, AuditProperties p) { return new SensitiveDataSanitizer(mapper, p.getMaxPayloadLength()); }
|
||
|
|
@Bean BusinessAuditAspect businessAuditAspect(AuditSink sink, SensitiveDataSanitizer sanitizer, AuditProperties p) { return new BusinessAuditAspect(sink, sanitizer, p.getServiceName()); }
|
||
|
|
}
|