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
package com.vincent.rsf.httpaudit.props;
 
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
 
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
/**
 * 审计配置缓存
 */
public final class HttpAuditDbConfigHolder {
 
    public static final String KEY_WHITELIST_ONLY = "whitelist-only";
    public static final String KEY_EXCLUDE_AUDIT_SELF_PATHS = "exclude-audit-self-paths";
    public static final String KEY_RULE_CACHE_REFRESH_MS = "rule-cache-refresh-ms";
    public static final String KEY_QUERY_RESPONSE_MAX_CHARS = "query-response-max-chars";
    public static final String KEY_MAX_RESPONSE_STORE_CHARS = "max-response-store-chars";
    public static final String KEY_DEFAULT_REQUEST_STORE_CHARS = "default-request-store-chars";
    public static final String KEY_PATH_DESCRIPTIONS = "path-descriptions";
    public static final String KEY_CLEANUP_ENABLED = "cleanup-enabled";
    public static final String KEY_CLEANUP_RETENTION_DAYS = "cleanup-retention-days";
 
    private static final ConcurrentHashMap<String, String> CONFIG = new ConcurrentHashMap<>();
    private static final ObjectMapper MAPPER = new ObjectMapper();
 
    private HttpAuditDbConfigHolder() {
    }
 
    public static void replace(Map<String, String> map) {
        CONFIG.clear();
        if (map != null && !map.isEmpty()) {
            CONFIG.putAll(map);
        }
    }
 
    public static boolean getBoolean(String key, boolean defaultValue) {
        String raw = CONFIG.get(key);
        if (raw == null) {
            return defaultValue;
        }
        return "1".equals(raw) || "true".equalsIgnoreCase(raw.trim());
    }
 
    public static int getInt(String key, int defaultValue) {
        String raw = CONFIG.get(key);
        if (raw == null) {
            return defaultValue;
        }
        try {
            return Integer.parseInt(raw.trim());
        } catch (Exception ignore) {
            return defaultValue;
        }
    }
 
    public static long getLong(String key, long defaultValue) {
        String raw = CONFIG.get(key);
        if (raw == null) {
            return defaultValue;
        }
        try {
            return Long.parseLong(raw.trim());
        } catch (Exception ignore) {
            return defaultValue;
        }
    }
 
    public static Map<String, String> getPathDescriptions(Map<String, String> defaultValue) {
        String raw = CONFIG.get(KEY_PATH_DESCRIPTIONS);
        if (raw == null || raw.trim().isEmpty()) {
            return defaultValue;
        }
        try {
            Map<String, String> parsed = MAPPER.readValue(raw, new TypeReference<Map<String, String>>() {
            });
            return parsed == null ? defaultValue : parsed;
        } catch (Exception ignore) {
            return defaultValue;
        }
    }
 
    public static Map<String, String> snapshot() {
        return Collections.unmodifiableMap(CONFIG);
    }
}