refactor(oapi): 提供方强制验签迁 starter——enforce-patterns+trust-registry(审计 P1-6 / L2-8)
build / build-push (push) Successful in 1m25s

- 删自写 svcitem/config/OpenApiAuthEnforceConfiguration(yh-app-auth starter 版
  RequireAppSignFilter 承接,order+11 行为等价;/oapi/site/list 面无签名即 401)
- yh.app-auth.server.enforce-patterns=[/oapi/*] + trust-registry=true(中央密钥链组合:
  trusted-apps 100018 先、Redis sign:app:* 链后,Notice/flow-center 同款)
- data-redis 自 test scope 提升编译期(yh-app-auth 侧 optional 不传递,生产 classpath
  此前并无该依赖);management.health.redis.enabled=false 防 Redis 抖动拉 DOWN 健康
- 测试 yml 同步 enforce-patterns:删自写副本后 SiteOapiIT 的 /oapi/** 401 断言由
  starter 过滤器承接;trust-registry 不进测试配置(IT 密封性,签名用例 100018 走
  trusted-apps 命中)

门禁:mvn test -Dskip.tests=false 413/413 绿(含 SiteOapiIT 6/6,本机 MySQL8+Redis)
This commit is contained in:
chenxing
2026-10-05 22:26:44 +08:00
parent 55d80e21a4
commit ed0c752f4a
4 changed files with 31 additions and 53 deletions
+5 -2
View File
@@ -103,11 +103,14 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 单测专用:验证方案 §12「缓存切 Redis 仅改配置」的演进承诺(生产仍为 Caffeine,零影响) -->
<!-- 入站验签走中央密钥链(注册表模式 yh.app-auth.trust-registry)必须编译期引入 data-redis:
yh-app-auth 的该依赖是 optional、不传递(Notice/flow-center/svc-hall 同款,2026-10-05 自
test scope 提升)。副作用是 RedisHealthIndicator 会被装配,故 yml 里关掉
management.health.redis.enabled,防 Redis 抖动把 /actuator/health 拉成 DOWN(503)。
RedisCacheEvolutionIT(缓存演进验证)继续复用本依赖。 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
@@ -1,49 +0,0 @@
package com.yunhai.cms.svcitem.config;
import com.yunhai.platform.appauth.AppAuthFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 开放接口签名强制(事项库详细设计 §3.4,照 UserBase OpenApiAuthEnforceConfiguration 范式):
* yh-app-auth 的 {@link AppAuthFilter}(order +10,全路由)设计为「无签名头则放行」以兼容浏览器
* CAS 流;本过滤器(order +11)只挂 /oapi/**,校验其写入的请求属性——已验签放行,否则 401。
* CMS 的 /oapi/** 无用户会话语义,一律应用签名(X-App-Key/X-Timestamp/X-Signature 三件套)。
*/
@Configuration
public class OpenApiAuthEnforceConfiguration {
@Bean
public FilterRegistrationBean<RequireAppSignFilter> requireAppSignFilter() {
FilterRegistrationBean<RequireAppSignFilter> bean = new FilterRegistrationBean<>();
bean.setFilter(new RequireAppSignFilter());
bean.addUrlPatterns("/oapi/*");
bean.setOrder(Ordered.HIGHEST_PRECEDENCE + 11);
return bean;
}
public static class RequireAppSignFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (req.getAttribute(AppAuthFilter.APP_AUTH_ATTR) == null) {
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "missing app signature");
return;
}
chain.doFilter(request, response);
}
}
}
+17 -2
View File
@@ -60,8 +60,18 @@ yh:
# UserBase 注册后分配(进白名单),与 yh.open 保持一致;生产由 projman 注入
app-key: 100005
app-secret: 2c7885de594742cc840b8762910b2d2e
# 入站验签白名单:办事大厅 svc-hall(站点目录 /oapi/site/list 消费方,appKey=100018;
# P0-1 修复)。secret 与 svc-hall application.yml yh.app-auth.app-secret 逐字一致(联调态),
# 提供方强制验签(两级模型 §4.1,flow-center/Notice 同款):本地 svcitem/config/
# OpenApiAuthEnforceConfiguration 副本已删(2026-10-05),换此一行——/oapi/**(站点目录
# /oapi/site/list)无签名三件套即 401(starter 版 RequireAppSignFilter,order +11 行为等价)
server:
enforce-patterns: [/oapi/*]
# 中央密钥链(两级模型 §4.2):trusted-apps 先(确定性兜底),未命中走 SignKeyResolver
# (Redis sign:app:* → Caffeine → UserBase 兜底端点)——任何在 UserBase 注册过的 appKey
# 自动可验。需 data-redis 编译期依赖(yh-app-auth 侧 optional 不传递,pom 已提升 scope)
trust-registry: true
# 入站验签白名单(组合链第一层,Redis 停摆时确定性工作):办事大厅 svc-hall
# (站点目录 /oapi/site/list 消费方,appKey=100018;P0-1 修复)。
# secret 与 svc-hall application.yml yh.app-auth.app-secret 逐字一致(联调态),
# 生产两侧由 projman/Nacos 注入同一密钥对
trusted-apps:
"100018": "svc-hall-dev-secret-100018"
@@ -120,6 +130,11 @@ management:
endpoint:
health:
show-details: never
# 密钥链验签依赖 Redis(sign:app:*)。关掉 Redis 健康指标:Redis 抖动不应把 /actuator/health
# 拉成 DOWN(503),否则部署健康检查与探活会误判整机不可用(Notice/flow-center/svc-hall 同口径)
health:
redis:
enabled: false
# 文件上传(同 UserHome 双 key 约定,方案 §7.3)
# FILE_WEB_PATH 只接受相对路径(默认 /cms/upload/,含 context-path)或公网可达绝对地址;
+9
View File
@@ -57,6 +57,12 @@ yh:
enabled: true
app-key: 100XXX
app-secret: xxxxxxxx
# 提供方强制验签(与主配置同款,2026-10-05):自写 OpenApiAuthEnforceConfiguration 副本已删,
# SiteOapiIT 的 /oapi/** 无签名 401 断言由 starter 版 RequireAppSignFilter(本配置驱动)承接;
# trust-registry 不进测试配置(IT 密封性:签名用例 100018 在下方 trusted-apps 命中即可,
# 不引入对 Redis 密钥链/UserBase 兜底端点的依赖)
server:
enforce-patterns: [/oapi/*]
# 入站验签白名单:svc-hall 站点目录调用(与主配置同款联调密钥,SiteOapiIT 咬合用)
trusted-apps:
"100018": "svc-hall-dev-secret-100018"
@@ -90,6 +96,9 @@ management:
endpoint:
health:
show-details: never
health:
redis:
enabled: false
# 本地 Redis(单测 Redis 演进用例连接参数)
cms.test.redis: