| | |
| | | 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; |
| | |
| | | |
| | | 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} 决定(含 record_all=1 全量、方向 IN/OUT/BOTH、截断长度);false:排除路径外入站与全部出站均记录,截断用本配置 + 规则中「全量」行的 request/response_max_chars(若有) |
| | | * true:入站/出站是否落库由 {@code sys_http_audit_rule} 匹配决定(record_all 仅影响命中条的截断;方向 IN/OUT/BOTH);false:排除路径外入站与全部出站均记录,截断用本配置默认字段 |
| | | */ |
| | | private boolean whitelistOnly = true; |
| | | |
| | |
| | | private List<String> excludePathPrefixes = defaultExcludes(); |
| | | |
| | | /** |
| | | * true:默认排除中的 /httpAuditLog、/httpAuditRule 仍生效;false:不再排除这两项(便于调试;record_all 也无法绕过 true 时的排除) |
| | | * true:默认排除中的 /httpAuditLog、/httpAuditRule 仍生效;false:不再排除这两项(便于调试;命中规则也无法绕过 true 时的排除) |
| | | */ |
| | | private boolean excludeAuditSelfPaths = true; |
| | | |
| | |
| | | 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)); |
| | | list.removeIf(p -> "/httpAuditLog".equals(p) || "/httpAuditRule".equals(p) || "/httpAuditSysConfig".equals(p)); |
| | | } |
| | | return list; |
| | | } |
| | |
| | | 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<>(); |
| | | list.add("/actuator"); |
| | |
| | | list.add("/static/"); |
| | | list.add("/httpAuditLog"); |
| | | list.add("/httpAuditRule"); |
| | | list.add("/httpAuditSysConfig"); |
| | | list.add("/http-audit/"); |
| | | return list; |
| | | } |
| | | |