feat: 捕获链路打通(里程碑 3)
- CaptureRule:/apis/** 写操作 + /login、/logout(纯函数) - ResourceResolver:路径 → 资源类型/名称(纯函数,深层子资源取前两段) - RequestSnapshot:请求期一次性解析不可变快照(D2) - OperationAuditWebFilter:AfterSecurityWebFilter 扩展点注册;操作者经 transformDeferredContextual 从订阅上下文(SecurityContext.class -> Mono)解析, 匿名判断在记录时做(D1);WebFlux 无 ThreadLocal - AuditRecorder:响应式直写 fire-and-forget,失败静默降级 warn(D2) - 28 个单测覆盖规则/解析/快照/降级/过滤器行为
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package run.halo.operationaudit.audit;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 捕获规则(纯函数,技术方案 D1):
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@code POST/PUT/DELETE/PATCH} + 路径前缀 {@code /apis/}</li>
|
||||
* <li>或路径精确匹配 {@code /login}、{@code /logout}(登录端点不在 /apis/** 下,
|
||||
* 是“一条通用规则覆盖全部管理面操作”的唯一必要例外,需在产品文档同步注明)</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>匿名判断不在请求期做,而在记录时做(技术方案 D1)。
|
||||
*/
|
||||
public final class CaptureRule {
|
||||
|
||||
public static final Set<String> WRITE_METHODS = Set.of("POST", "PUT", "DELETE", "PATCH");
|
||||
public static final Set<String> AUTH_ENDPOINTS = Set.of("/login", "/logout");
|
||||
public static final String APIS_PREFIX = "/apis/";
|
||||
|
||||
private CaptureRule() {
|
||||
}
|
||||
|
||||
/** 是否命中捕获规则。path 为不含查询串的请求路径。 */
|
||||
public static boolean shouldCapture(String path, String method) {
|
||||
if (isAuthEndpoint(path)) {
|
||||
return true;
|
||||
}
|
||||
if (path == null || !path.startsWith(APIS_PREFIX)) {
|
||||
return false;
|
||||
}
|
||||
return method != null && WRITE_METHODS.contains(method);
|
||||
}
|
||||
|
||||
/** 是否为登录/登出端点。 */
|
||||
public static boolean isAuthEndpoint(String path) {
|
||||
return path != null && AUTH_ENDPOINTS.contains(path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user