cl
2026-04-17 f7e46d204be81fd2ebb9e5a90728e945700a2c23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.vincent.rsf.httpaudit.props;
 
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
 
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
/**
 * HTTP 审计配置
 */
@Data
@ConfigurationProperties(prefix = "http-audit")
public class HttpAuditProperties {
 
    private boolean enabled = true;
 
    /**
     * true:入站/出站是否落库由 {@code sys_http_audit_rule} 决定(含 record_all=1 全量、方向 IN/OUT/BOTH、截断长度);false:排除路径外入站与全部出站均记录,截断用本配置 + 规则中「全量」行的 request/response_max_chars(若有)
     */
    private boolean whitelistOnly = true;
 
    /** 规则缓存定时刷新间隔(毫秒) */
    private long ruleCacheRefreshMs = 60_000L;
 
    /** 定时清理开关 */
    private boolean cleanupEnabled = true;
    /** 保留天数 */
    private int cleanupRetentionDays = 180;
 
    /** 查询类响应最多保留字符数 */
    private int queryResponseMaxChars = 500;
 
    /** 非查询类响应最多入库字节(超出截断并标记) */
    private int maxResponseStoreChars = 65535;
 
    /**
     * 规则未指定 request_max_chars 时的默认:字符数;-1 表示入库不截断请求体
     */
    private int defaultRequestStoreChars = 65535;
 
    /** 请求体缓存上限(字节) */
    private int maxRequestCacheBytes = 2 * 1024 * 1024;
 
    /** 响应体缓存上限(字节) */
    private int maxResponseCacheBytes = 2 * 1024 * 1024;
 
    /** 不落库的路径前缀 */
    private List<String> excludePathPrefixes = defaultExcludes();
 
    /**
     * true:默认排除中的 /httpAuditLog、/httpAuditRule 仍生效;false:不再排除这两项(便于调试;record_all 也无法绕过 true 时的排除)
     */
    private boolean excludeAuditSelfPaths = true;
 
    /** Filter 实际使用的前缀(受 excludeAuditSelfPaths 影响) */
    public List<String> getEffectiveExcludePrefixes() {
        List<String> list = excludePathPrefixes == null ? new ArrayList<>() : new ArrayList<>(excludePathPrefixes);
        if (!isExcludeAuditSelfPaths()) {
            list.removeIf(p -> "/httpAuditLog".equals(p) || "/httpAuditRule".equals(p));
        }
        return list;
    }
 
    /** 视为外部调用的路径前缀(其余为内部) */
    private List<String> externalPathPrefixes = defaultExternal();
 
    /** 路径 -> 功能描述(按最长路径前缀匹配) */
    private Map<String, String> pathDescriptions = new LinkedHashMap<>();
 
    public boolean isWhitelistOnly() {
        return HttpAuditDbConfigHolder.getBoolean(HttpAuditDbConfigHolder.KEY_WHITELIST_ONLY, whitelistOnly);
    }
 
    public boolean isExcludeAuditSelfPaths() {
        return HttpAuditDbConfigHolder.getBoolean(HttpAuditDbConfigHolder.KEY_EXCLUDE_AUDIT_SELF_PATHS, excludeAuditSelfPaths);
    }
 
    public long getRuleCacheRefreshMs() {
        return HttpAuditDbConfigHolder.getLong(HttpAuditDbConfigHolder.KEY_RULE_CACHE_REFRESH_MS, ruleCacheRefreshMs);
    }
 
    public int getQueryResponseMaxChars() {
        return HttpAuditDbConfigHolder.getInt(HttpAuditDbConfigHolder.KEY_QUERY_RESPONSE_MAX_CHARS, queryResponseMaxChars);
    }
 
    public int getMaxResponseStoreChars() {
        return HttpAuditDbConfigHolder.getInt(HttpAuditDbConfigHolder.KEY_MAX_RESPONSE_STORE_CHARS, maxResponseStoreChars);
    }
 
    public int getDefaultRequestStoreChars() {
        return HttpAuditDbConfigHolder.getInt(HttpAuditDbConfigHolder.KEY_DEFAULT_REQUEST_STORE_CHARS, defaultRequestStoreChars);
    }
 
    public boolean isCleanupEnabled() {
        return HttpAuditDbConfigHolder.getBoolean(HttpAuditDbConfigHolder.KEY_CLEANUP_ENABLED, cleanupEnabled);
    }
 
    public int getCleanupRetentionDays() {
        return HttpAuditDbConfigHolder.getInt(HttpAuditDbConfigHolder.KEY_CLEANUP_RETENTION_DAYS, cleanupRetentionDays);
    }
 
    public Map<String, String> getPathDescriptions() {
        return HttpAuditDbConfigHolder.getPathDescriptions(pathDescriptions);
    }
 
    private static List<String> defaultExcludes() {
        List<String> list = new ArrayList<>();
        list.add("/actuator");
        list.add("/swagger");
        list.add("/webjars");
        list.add("/v2/api-docs");
        list.add("/v3/api-docs");
        list.add("/doc.html");
        list.add("/druid");
        list.add("/error");
        list.add("/favicon.ico");
        list.add("/static/");
        list.add("/httpAuditLog");
        list.add("/httpAuditRule");
        return list;
    }
 
    private static List<String> defaultExternal() {
        List<String> list = new ArrayList<>();
        list.add("/erp");
        list.add("/cloudwms");
        return list;
    }
}