From ed0c752f4aec586e652977991eef0dbeaa94e2aa Mon Sep 17 00:00:00 2001 From: chenxing Date: Mon, 5 Oct 2026 22:26:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(oapi):=20=E6=8F=90=E4=BE=9B=E6=96=B9?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E9=AA=8C=E7=AD=BE=E8=BF=81=20starter?= =?UTF-8?q?=E2=80=94=E2=80=94enforce-patterns+trust-registry=EF=BC=88?= =?UTF-8?q?=E5=AE=A1=E8=AE=A1=20P1-6=20/=20L2-8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删自写 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) --- pom.xml | 7 ++- .../OpenApiAuthEnforceConfiguration.java | 49 ------------------- src/main/resources/application.yml | 19 ++++++- src/test/resources/application.yml | 9 ++++ 4 files changed, 31 insertions(+), 53 deletions(-) delete mode 100644 src/main/java/com/yunhai/cms/svcitem/config/OpenApiAuthEnforceConfiguration.java diff --git a/pom.xml b/pom.xml index baf2955..45d9e26 100644 --- a/pom.xml +++ b/pom.xml @@ -103,11 +103,14 @@ spring-boot-starter-test test - + org.springframework.boot spring-boot-starter-data-redis - test diff --git a/src/main/java/com/yunhai/cms/svcitem/config/OpenApiAuthEnforceConfiguration.java b/src/main/java/com/yunhai/cms/svcitem/config/OpenApiAuthEnforceConfiguration.java deleted file mode 100644 index 2db9344..0000000 --- a/src/main/java/com/yunhai/cms/svcitem/config/OpenApiAuthEnforceConfiguration.java +++ /dev/null @@ -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() { - FilterRegistrationBean 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); - } - } -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f072de4..5fa9ce9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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)或公网可达绝对地址; diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 764d167..f595fb5 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -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: