2026-07-30 18:01:36 +08:00
|
|
|
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()); }
|
2026-08-05 10:35:07 +08:00
|
|
|
@Bean BusinessAuditAspect businessAuditAspect() { return new BusinessAuditAspect(); }
|
2026-07-30 18:01:36 +08:00
|
|
|
}
|