cl
3 小时以前 880621206ae152e69104cabc30200ff3a098eabb
rsf-http-audit/src/main/java/com/vincent/rsf/httpaudit/config/HttpAuditAutoConfiguration.java
@@ -1,8 +1,14 @@
package com.vincent.rsf.httpaudit.config;
import com.vincent.rsf.httpaudit.mapper.HttpAuditLogMapper;
import com.vincent.rsf.httpaudit.mapper.HttpAuditRuleMapper;
import com.vincent.rsf.httpaudit.props.HttpAuditProperties;
import com.vincent.rsf.httpaudit.service.HttpAuditAsyncRecorder;
import com.vincent.rsf.httpaudit.service.HttpAuditOutboundRecorder;
import com.vincent.rsf.httpaudit.service.HttpAuditRuleService;
import com.vincent.rsf.httpaudit.service.HttpAuditRuleServiceImpl;
import com.vincent.rsf.httpaudit.web.HttpAuditFilter;
import com.vincent.rsf.httpaudit.web.OutboundHttpAuditInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -12,6 +18,7 @@
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@@ -21,10 +28,41 @@
 */
@Configuration
@EnableAsync
@EnableScheduling
@EnableConfigurationProperties(HttpAuditProperties.class)
@ConditionalOnProperty(prefix = "http-audit", name = "enabled", havingValue = "true", matchIfMissing = true)
@MapperScan("com.vincent.rsf.httpaudit.mapper")
public class HttpAuditAutoConfiguration {
    @Bean
    public HttpAuditRuleService httpAuditRuleService(HttpAuditRuleMapper mapper, HttpAuditProperties props) {
        return new HttpAuditRuleServiceImpl(mapper, props);
    }
    @Bean
    public HttpAuditAsyncRecorder httpAuditAsyncRecorder(HttpAuditLogMapper httpAuditLogMapper) {
        return new HttpAuditAsyncRecorder(httpAuditLogMapper);
    }
    @Bean
    public HttpAuditOutboundRecorder httpAuditOutboundRecorder(
            HttpAuditAsyncRecorder recorder,
            HttpAuditProperties props,
            Environment env,
            HttpAuditRuleService httpAuditRuleService) {
        return new HttpAuditOutboundRecorder(recorder, props, env, httpAuditRuleService);
    }
    @Bean
    public OutboundHttpAuditInterceptor outboundHttpAuditInterceptor(HttpAuditOutboundRecorder httpAuditOutboundRecorder) {
        return new OutboundHttpAuditInterceptor(httpAuditOutboundRecorder);
    }
    @Bean
    public HttpAuditRestTemplateBeanPostProcessor httpAuditRestTemplateBeanPostProcessor(
            OutboundHttpAuditInterceptor outboundHttpAuditInterceptor) {
        return new HttpAuditRestTemplateBeanPostProcessor(outboundHttpAuditInterceptor);
    }
    @Bean(name = "httpAuditExecutor")
    public Executor httpAuditExecutor() {
@@ -39,8 +77,9 @@
    @Bean
    public FilterRegistrationBean<HttpAuditFilter> httpAuditFilterRegistration(
            HttpAuditAsyncRecorder recorder, HttpAuditProperties props, Environment env) {
        HttpAuditFilter filter = new HttpAuditFilter(recorder, props, env);
            HttpAuditAsyncRecorder recorder, HttpAuditProperties props, Environment env,
            HttpAuditRuleService httpAuditRuleService) {
        HttpAuditFilter filter = new HttpAuditFilter(recorder, props, env, httpAuditRuleService);
        FilterRegistrationBean<HttpAuditFilter> reg = new FilterRegistrationBean<>();
        reg.setFilter(filter);
        reg.addUrlPatterns("/*");