From 35d8c09fd1ea3f72684c5921939fa20c92bd330b Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期二, 12 五月 2026 13:18:29 +0800
Subject: [PATCH] #

---
 rsf-http-audit/src/main/java/com/vincent/rsf/httpaudit/props/HttpAuditProperties.java |  119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/rsf-http-audit/src/main/java/com/vincent/rsf/httpaudit/props/HttpAuditProperties.java b/rsf-http-audit/src/main/java/com/vincent/rsf/httpaudit/props/HttpAuditProperties.java
index a553c23..b744b41 100644
--- a/rsf-http-audit/src/main/java/com/vincent/rsf/httpaudit/props/HttpAuditProperties.java
+++ b/rsf-http-audit/src/main/java/com/vincent/rsf/httpaudit/props/HttpAuditProperties.java
@@ -3,7 +3,9 @@
 import lombok.Data;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
+import java.time.Duration;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -17,11 +19,47 @@
 
     private boolean enabled = true;
 
+    /** 1 鏁版嵁搴� 2 OpenSearch 3 鍙屽啓锛涙湭濉垨鍏跺畠鍊煎悓 1 */
+    private int logStorageMode = 1;
+
+    /** 浠� 2銆�3 浣跨敤 */
+    private OpenSearch openSearch = new OpenSearch();
+
+    /** 浠� 1銆�3锛涙棤澶氭暟鎹簮鍙渷鐣� */
+    private String datasource = "primary";
+
+    /** 鏄惁娉ㄥ唽 /httpAuditRule銆�/httpAuditLog銆�/httpAuditSysConfig 绛夌鐞嗘帴鍙� */
+    private boolean adminApiEnabled = true;
+
+    /** 鏄惁鎻愪緵闈欐�佹煡璇㈤〉涓� /http-audit/open/log/page锛堥粯璁� true锛涘彲 simple-ui-enabled=false 鍏抽棴锛� */
+    private boolean simpleUiEnabled = true;
+
+    /** 闈炵┖鏃惰姹傝姹傚ご X-Http-Audit-Ui-Token 涓庢湰鍊间竴鑷达紱鐣欑┖鍒欎笉鏍¢獙锛堝叕缃戝缓璁厤缃級 */
+    private String simpleUiToken = "";
+
+    /**
+     * true锛氬叆绔�/鍑虹珯鏄惁钀藉簱鐢� {@code sys_http_audit_rule} 鍖归厤鍐冲畾锛坮ecord_all 浠呭奖鍝嶅懡涓潯鐨勬埅鏂紱鏂瑰悜 IN/OUT/BOTH锛夛紱false锛氭帓闄よ矾寰勫鍏ョ珯涓庡叏閮ㄥ嚭绔欏潎璁板綍锛屾埅鏂敤鏈厤缃粯璁ゅ瓧娈�
+     */
+    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;
@@ -32,11 +70,89 @@
     /** 涓嶈惤搴撶殑璺緞鍓嶇紑 */
     private List<String> excludePathPrefixes = defaultExcludes();
 
+    /**
+     * true锛氶粯璁ゆ帓闄や腑鐨� /httpAuditLog銆�/httpAuditRule 浠嶇敓鏁堬紱false锛氫笉鍐嶆帓闄よ繖涓ら」锛堜究浜庤皟璇曪紱鍛戒腑瑙勫垯涔熸棤娉曠粫杩� 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) || "/httpAuditSysConfig".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);
+    }
+
+    public int resolveLogStorageMode() {
+        if (logStorageMode == 2 || logStorageMode == 3) {
+            return logStorageMode;
+        }
+        return 1;
+    }
+
+    public boolean usesMysqlLogStorage() {
+        int m = resolveLogStorageMode();
+        return m == 1 || m == 3;
+    }
+
+    public boolean usesOpenSearchLogStorage() {
+        int m = resolveLogStorageMode();
+        return m == 2 || m == 3;
+    }
+
+    @Data
+    public static class OpenSearch {
+        private List<String> uris = new ArrayList<>(Collections.singletonList("localhost:9200"));
+        private String scheme = "http";
+        private String username = "";
+        private String password = "";
+        private String indexName = "http_audit_log";
+        private Duration connectTimeout = Duration.ofSeconds(5);
+        private Duration socketTimeout = Duration.ofSeconds(30);
+    }
 
     private static List<String> defaultExcludes() {
         List<String> list = new ArrayList<>();
@@ -51,6 +167,9 @@
         list.add("/favicon.ico");
         list.add("/static/");
         list.add("/httpAuditLog");
+        list.add("/httpAuditRule");
+        list.add("/httpAuditSysConfig");
+        list.add("/http-audit/");
         return list;
     }
 

--
Gitblit v1.9.1