Merge feat/p0-security-hardening: P0 安全洞收口(2026-06-24 架构评审)
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
①permitAll fail-open→fail-safe profile+prod配置+JWT弱密钥守卫 ②asUser/roles 越权 JWT 身份权威(EntityController+PickerController) ③脚本RCE/任意DROP拆控制器隔离+路径穿越守卫+Poc门禁+TodoController advanced-script 守卫 ④CI孤儿迁Gitea+JDK21。含独立 security-reviewer 对抗评审揪出的 2 个孪生漏洞(TodoController RCE/PickerController IDOR)。全 reactor mvn clean install 绿。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
# eip4-platform CI:编译+单测+ArchUnit+对拍冒烟(公司自建 Git 服务可换 Jenkins,步骤同 scripts/ci.sh)
|
# eip4-platform CI(Gitea Actions)。
|
||||||
|
#
|
||||||
|
# P0 修复(2026-06-24 架构评审):原 .github/workflows/ci.yml 在 Gitea(git.latent.chat)上是孤儿
|
||||||
|
# (GitHub Actions 不会跑),且 java-version 写死 17(项目 JDK21)。本文件迁到 Gitea 规范位置
|
||||||
|
# .gitea/workflows/,JDK 升 21。
|
||||||
|
#
|
||||||
|
# 前置条件:Gitea 实例需已启用 Actions 且注册了带 `ubuntu-latest` 标签的 act_runner;
|
||||||
|
# 否则本工作流不会被调度(纯文件存在不等于会跑)。详见仓库 Actions 设置。
|
||||||
name: ci
|
name: ci
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -23,9 +30,9 @@ jobs:
|
|||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: temurin
|
||||||
java-version: "17"
|
java-version: "21"
|
||||||
cache: maven
|
cache: maven
|
||||||
- name: 编译+单测+对拍冒烟
|
- name: 编译+单测(含 ArchUnit)+对拍冒烟
|
||||||
env:
|
env:
|
||||||
CI_PG_HOST: localhost
|
CI_PG_HOST: localhost
|
||||||
CI_PG_PORT: "5433"
|
CI_PG_PORT: "5433"
|
||||||
54
platform-app/src/main/resources/application-prod.yml
Normal file
54
platform-app/src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# ============================================================================
|
||||||
|
# 生产 profile(P0 修复,2026-06-24 架构评审:补齐缺失的 prod 配置)。
|
||||||
|
#
|
||||||
|
# 启用方式:-Dspring.profiles.active=prod(或 SPRING_PROFILES_ACTIVE=prod)。
|
||||||
|
# 设计原则 fail-safe:所有敏感项<strong>无内置默认</strong>,必须经环境变量显式提供,
|
||||||
|
# 缺失即启动失败——杜绝继承 application.yml 的开发默认值(共享测试库 / 弱 JWT 密钥)裸奔进生产。
|
||||||
|
#
|
||||||
|
# 安全链:prod 不在 SecurityProfiles 旁路名单内 → 自动走严格链(其余 /api/** 强制认证),
|
||||||
|
# 且 JwtSecretSafetyCheck 在此 profile 下拒绝开发默认 JWT 密钥。
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
# 生产库连接必须经环境变量提供,无默认值(缺失 → 占位符解析失败 → 启动拒绝)。
|
||||||
|
url: ${EIP4_DB_URL}
|
||||||
|
username: ${EIP4_DB_USERNAME}
|
||||||
|
password: ${EIP4_DB_PASSWORD}
|
||||||
|
hikari:
|
||||||
|
maximum-pool-size: ${EIP4_DB_POOL_MAX:20}
|
||||||
|
read-only: false
|
||||||
|
connection-init-sql: "SET statement_timeout = '${EIP4_DB_STATEMENT_TIMEOUT:120s}'"
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: ${SERVER_PORT:8084}
|
||||||
|
|
||||||
|
eip4:
|
||||||
|
auth:
|
||||||
|
jwt:
|
||||||
|
# 生产 JWT 密钥必须经环境变量提供,无默认值(故意去掉 application.yml 的 dev 默认回退)。
|
||||||
|
# 缺失 → 占位符解析失败启动拒绝;若误填为开发默认值 → JwtSecretSafetyCheck 拒绝启动。
|
||||||
|
secret: ${EIP4_AUTH_JWT_SECRET}
|
||||||
|
expire-seconds: ${EIP4_AUTH_JWT_EXPIRE_SECONDS:28800}
|
||||||
|
issuer: eip4-platform
|
||||||
|
file:
|
||||||
|
# 生产附件根必须为绝对路径,经环境变量提供。
|
||||||
|
root: ${EIP4_FILE_ROOT}
|
||||||
|
|
||||||
|
# 可观测性:生产仅暴露健康探针,详情仅对已认证者可见(匿名只见 UP/DOWN)。
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: health
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
probes:
|
||||||
|
enabled: true
|
||||||
|
show-details: when-authorized
|
||||||
|
show-components: when-authorized
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.dsasp: INFO
|
||||||
|
org.springframework.jdbc.core: INFO
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.eip4.platform.auth.security;
|
||||||
|
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT 弱密钥启动守卫(P0,2026-06-24 架构评审)。
|
||||||
|
*
|
||||||
|
* <p>{@code application.yml} 给出「非生产默认密钥」
|
||||||
|
* ({@value #DEV_DEFAULT_SECRET})供 dev/local/ci 开箱即用。风险:若生产(或任何
|
||||||
|
* 非旁路 profile)忘记经 {@code EIP4_AUTH_JWT_SECRET} 覆盖,该默认密钥会静默签发可伪造令牌。
|
||||||
|
*
|
||||||
|
* <p>本守卫在启动期判定:激活的是<strong>严格 profile</strong>
|
||||||
|
* ({@link SecurityProfiles#isBypassActive(Environment)} 为 false,含 prod 与未设 profile)
|
||||||
|
* 却仍使用开发默认密钥 → <strong>启动即失败</strong>,杜绝弱密钥裸奔进生产。
|
||||||
|
*
|
||||||
|
* <p>旁路 profile(dev/local/ci/parity)下跳过本检查,保留默认密钥开箱即用。
|
||||||
|
* {@link JwtService} 仍独立校验密钥存在且 ≥256bit;本守卫只补「默认值不得进严格环境」一条。
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class JwtSecretSafetyCheck {
|
||||||
|
|
||||||
|
/** application.yml 内置的非生产默认密钥;严格 profile 下出现即拒启动。 */
|
||||||
|
static final String DEV_DEFAULT_SECRET =
|
||||||
|
"dev-only-eip4-jwt-secret-change-me-in-production-0123456789";
|
||||||
|
|
||||||
|
public JwtSecretSafetyCheck(JwtProperties props, Environment env) {
|
||||||
|
if (!SecurityProfiles.isBypassActive(env)
|
||||||
|
&& DEV_DEFAULT_SECRET.equals(props.getSecret())) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"严格安全 profile(prod 或未设旁路 profile)下仍使用 application.yml 的开发默认 JWT 密钥;"
|
||||||
|
+ "生产部署必须经环境变量 EIP4_AUTH_JWT_SECRET 设置强随机密钥(≥32 字节),"
|
||||||
|
+ "或仅在 dev/local/ci/parity profile 下使用默认密钥。");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,15 +15,20 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|||||||
/**
|
/**
|
||||||
* Spring Security 配置(无状态,STATELESS:不建 HttpSession,免 session 共享)。
|
* Spring Security 配置(无状态,STATELESS:不建 HttpSession,免 session 共享)。
|
||||||
*
|
*
|
||||||
* <p><strong>双链按 profile 装配</strong>:
|
* <p><strong>双链按 profile 装配(fail-safe 默认)</strong>:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><b>prod</b>(生产):严格链——{@code /api/auth/**}、swagger/openapi 放行,
|
* <li><b>严格链(默认)</b>:旁路 profile({@link SecurityProfiles#BYPASS_NAMES})<em>全不激活</em>时
|
||||||
* 其余 {@code /api/**} 必须认证;<em>无任何测试旁路</em>。</li>
|
* 装配——含生产 {@code prod} <strong>以及未设任何 profile 的裸启动</strong>。
|
||||||
* <li><b>非 prod</b>(default/local/ci 等):宽松链——保留 {@code permitAll} 测试通道,
|
* {@code /api/auth/**}、swagger/openapi、健康探针放行,其余 {@code /api/**} 必须认证;
|
||||||
* 使对拍框架的免令牌 + {@code asUser/roles} 旁路可用(CI 依赖)。JWT 过滤器仍挂载,
|
* <em>无任何测试旁路</em>。</li>
|
||||||
* 带令牌照常填充引擎上下文。</li>
|
* <li><b>宽松链(显式 opt-in)</b>:仅 {@code dev/local/ci/parity} 之一激活时装配——保留
|
||||||
|
* {@code permitAll} 测试通道,使对拍框架的免令牌 + {@code asUser/roles} 旁路可用(CI 依赖)。
|
||||||
|
* JWT 过滤器仍挂载,带令牌照常填充引擎上下文。</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* 「生产绝不放行」由 {@code @Profile} 条件装配硬保证,并由 {@code SecurityProfileTest} 断言。
|
* P0 修复(2026-06-24 架构评审):旧实现宽松链为 {@code @Profile("!prod")},未设 profile 即 fail-open
|
||||||
|
* 全放行。现改为旁路<strong>显式 opt-in</strong>,默认 fail-safe(忘设 profile = 强制认证)。
|
||||||
|
* 旁路 profile 名单集中在 {@link SecurityProfiles},「生产/默认绝不放行」由 {@code @Profile} 条件装配
|
||||||
|
* 硬保证,并由 {@code SecurityProfileTest} 断言。
|
||||||
*
|
*
|
||||||
* <p>两链共享的放行清单与无状态/无表单/无 CSRF 设定抽到 {@link #applyCommon}。
|
* <p>两链共享的放行清单与无状态/无表单/无 CSRF 设定抽到 {@link #applyCommon}。
|
||||||
*/
|
*/
|
||||||
@@ -46,9 +51,9 @@ public class SecurityConfig {
|
|||||||
this.roleResolver = roleResolver;
|
this.roleResolver = roleResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 生产链:其余 /api/** 一律需认证,无测试旁路。 */
|
/** 严格链(默认 + prod):旁路 profile 全不激活时装配,其余 /api/** 一律需认证,无测试旁路。 */
|
||||||
@Bean
|
@Bean
|
||||||
@Profile("prod")
|
@Profile(SecurityProfiles.STRICT)
|
||||||
SecurityFilterChain prodFilterChain(HttpSecurity http) throws Exception {
|
SecurityFilterChain prodFilterChain(HttpSecurity http) throws Exception {
|
||||||
applyCommon(http);
|
applyCommon(http);
|
||||||
http.authorizeHttpRequests(reg -> reg
|
http.authorizeHttpRequests(reg -> reg
|
||||||
@@ -62,11 +67,11 @@ public class SecurityConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 非生产链(default/local/ci):保留 permitAll 测试通道。
|
* 宽松链(显式 opt-in:dev/local/ci/parity):保留 permitAll 测试通道。
|
||||||
* JWT 过滤器照常挂载——带令牌走 JWT 上下文,不带令牌走 asUser/roles 旁路(对拍 CI 依赖)。
|
* JWT 过滤器照常挂载——带令牌走 JWT 上下文,不带令牌走 asUser/roles 旁路(对拍 CI 依赖)。
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@Profile("!prod")
|
@Profile(SecurityProfiles.BYPASS)
|
||||||
SecurityFilterChain devFilterChain(HttpSecurity http) throws Exception {
|
SecurityFilterChain devFilterChain(HttpSecurity http) throws Exception {
|
||||||
applyCommon(http);
|
applyCommon(http);
|
||||||
http.authorizeHttpRequests(reg -> reg.anyRequest().permitAll());
|
http.authorizeHttpRequests(reg -> reg.anyRequest().permitAll());
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.eip4.platform.auth.security;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全旁路 profile 的<strong>唯一真相</strong>。
|
||||||
|
*
|
||||||
|
* <p>历史问题(P0,2026-06-24 架构评审):宽松安全链曾用 {@code @Profile("!prod")},即
|
||||||
|
* <em>未显式设 prod 的一切场景</em>(含「裸 {@code java -jar} 未设任何 profile」)都开
|
||||||
|
* {@code permitAll} + {@code asUser/roles} 旁路 → fail-open 默认。忘记设 profile = 全放行。
|
||||||
|
*
|
||||||
|
* <p>修复:把旁路改为<strong>显式 opt-in</strong>。仅 {@link #BYPASS_NAMES} 里的 profile
|
||||||
|
* (开发/对拍/CI)开启免令牌旁路;其余一切(prod、<em>以及未设任何 profile</em>)走严格链。
|
||||||
|
* 即默认 fail-safe——忘记设 profile = 强制认证,而非全放行。
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>{@code dev} —— 本机开发(run-dev.sh 默认)</li>
|
||||||
|
* <li>{@code local} —— 本机集成测试(@ActiveProfiles("local"))</li>
|
||||||
|
* <li>{@code ci} —— CI 流水线对拍</li>
|
||||||
|
* <li>{@code parity}—— 对拍框架免令牌重放</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>{@link SecurityConfig} 的 {@code @Profile} 表达式与本类的名单<strong>必须一致</strong>,
|
||||||
|
* 故 {@link #BYPASS} / {@link #STRICT} 提供编译期常量给注解复用,
|
||||||
|
* {@link #isBypassActive(Environment)} 给运行期判定(JWT 弱密钥守卫等)复用。
|
||||||
|
*/
|
||||||
|
public final class SecurityProfiles {
|
||||||
|
|
||||||
|
private SecurityProfiles() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 开启免令牌旁路的 profile 名(运行期判定用)。 */
|
||||||
|
static final Set<String> BYPASS_NAMES = Set.of("dev", "local", "ci", "parity");
|
||||||
|
|
||||||
|
/** 宽松(旁路)链的 {@code @Profile} 表达式——与 {@link #BYPASS_NAMES} 一致。 */
|
||||||
|
public static final String BYPASS = "dev | local | ci | parity";
|
||||||
|
|
||||||
|
/** 严格链的 {@code @Profile} 表达式:旁路 profile 全不激活(含 prod 与未设 profile)。 */
|
||||||
|
public static final String STRICT = "!dev & !local & !ci & !parity";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前是否激活了任一旁路 profile。
|
||||||
|
* 用于运行期 fail-safe 判定(如 prod/严格场景下拒绝弱 JWT 密钥)。
|
||||||
|
*/
|
||||||
|
public static boolean isBypassActive(Environment env) {
|
||||||
|
if (env == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String p : env.getActiveProfiles()) {
|
||||||
|
if (BYPASS_NAMES.contains(p)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.eip4.platform.auth.security;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT 弱密钥启动守卫断言:严格 profile 下用开发默认密钥必须拒启动;旁路 profile 或强密钥放行。
|
||||||
|
*/
|
||||||
|
class JwtSecretSafetyCheckTest {
|
||||||
|
|
||||||
|
private JwtProperties props(String secret) {
|
||||||
|
JwtProperties p = new JwtProperties();
|
||||||
|
p.setSecret(secret);
|
||||||
|
p.setIssuer("eip4-platform");
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 严格profile下开发默认密钥_拒启动() {
|
||||||
|
MockEnvironment env = new MockEnvironment().withProperty("x", "y"); // 无旁路 profile = 严格
|
||||||
|
assertThatThrownBy(() -> new JwtSecretSafetyCheck(
|
||||||
|
props(JwtSecretSafetyCheck.DEV_DEFAULT_SECRET), env))
|
||||||
|
.isInstanceOf(IllegalStateException.class)
|
||||||
|
.hasMessageContaining("EIP4_AUTH_JWT_SECRET");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void prod_profile下开发默认密钥_拒启动() {
|
||||||
|
MockEnvironment env = new MockEnvironment();
|
||||||
|
env.setActiveProfiles("prod");
|
||||||
|
assertThatThrownBy(() -> new JwtSecretSafetyCheck(
|
||||||
|
props(JwtSecretSafetyCheck.DEV_DEFAULT_SECRET), env))
|
||||||
|
.isInstanceOf(IllegalStateException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 旁路profile下开发默认密钥_放行() {
|
||||||
|
for (String profile : new String[] {"dev", "local", "ci", "parity"}) {
|
||||||
|
MockEnvironment env = new MockEnvironment();
|
||||||
|
env.setActiveProfiles(profile);
|
||||||
|
assertThatCode(() -> new JwtSecretSafetyCheck(
|
||||||
|
props(JwtSecretSafetyCheck.DEV_DEFAULT_SECRET), env))
|
||||||
|
.as("旁路 profile " + profile + " 下默认密钥应放行")
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 严格profile下强密钥_放行() {
|
||||||
|
MockEnvironment env = new MockEnvironment();
|
||||||
|
env.setActiveProfiles("prod");
|
||||||
|
assertThatCode(() -> new JwtSecretSafetyCheck(
|
||||||
|
props("a-strong-random-production-secret-key-0123456789-abcdef"), env))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,11 +18,13 @@ import org.springframework.security.web.FilterChainProxy;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安全链按 profile 装配的断言:
|
* 安全链按 profile 装配的断言(P0 fail-safe 修复后):
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><b>生产链(prod)</b>:测试旁路<strong>关闭</strong>——无令牌访问 /api/entity/** 被拒(401/403,非 2xx);
|
* <li><b>严格链(prod)</b>:测试旁路<strong>关闭</strong>——无令牌访问 /api/entity/** 被拒(401);
|
||||||
* 放行清单(/api/auth/**、/v3/api-docs/**)仍开。</li>
|
* 放行清单(/api/auth/**、/v3/api-docs/**)仍开。</li>
|
||||||
* <li><b>非生产链(无 profile)</b>:permitAll 测试通道开启——无令牌访问 /api/entity/** 放行(对拍 CI 依赖)。</li>
|
* <li><b>严格链(未设任何 profile)</b>:fail-safe 默认——无令牌访问受保护路径同样被拒(401)。
|
||||||
|
* 这是修复点:旧实现未设 profile 即 permitAll 全放行(fail-open),现默认强制认证。</li>
|
||||||
|
* <li><b>宽松链(显式 dev/local/ci/parity)</b>:permitAll 测试通道开启——无令牌访问放行(对拍 CI 依赖)。</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* 用 WebApplicationContextRunner 直接装载 SecurityConfig + 真实 Security 自动配置,
|
* 用 WebApplicationContextRunner 直接装载 SecurityConfig + 真实 Security 自动配置,
|
||||||
* 取出 springSecurityFilterChain 跑 Mock 请求观察拦截结果,不需起整 Boot 应用。
|
* 取出 springSecurityFilterChain 跑 Mock 请求观察拦截结果,不需起整 Boot 应用。
|
||||||
@@ -83,13 +85,29 @@ class SecurityProfileTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void 非生产链开启测试旁路_无令牌放行() {
|
void 未设profile_fail_safe默认严格_受保护路径无令牌被拒() {
|
||||||
// 无 active profile → devFilterChain(@Profile("!prod"))
|
// P0 修复:无 active profile → 严格链(@Profile(SecurityProfiles.STRICT)),不再 fail-open 全放行
|
||||||
runner().run(ctx -> {
|
runner().run(ctx -> {
|
||||||
assertThat(ctx).hasNotFailed();
|
assertThat(ctx).hasNotFailed();
|
||||||
assertThat(statusThroughChain(ctx, "GET", "/api/entity/EIP4PT_TASK/list"))
|
assertThat(statusThroughChain(ctx, "GET", "/api/entity/EIP4PT_TASK/list"))
|
||||||
.as("非生产 profile:permitAll 测试通道开启,无令牌应放行(对拍 CI 依赖)")
|
.as("未设 profile:fail-safe 默认必须强制认证,无令牌被拒为 401(旧实现此处 fail-open 放行)")
|
||||||
|
.isEqualTo(401);
|
||||||
|
// 放行清单在严格默认链下仍开
|
||||||
|
assertThat(statusThroughChain(ctx, "POST", "/api/auth/login"))
|
||||||
|
.as("登录端点须放行").isEqualTo(200);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void 显式旁路profile开启测试通道_无令牌放行() {
|
||||||
|
// dev/local/ci/parity 任一激活 → devFilterChain(@Profile(SecurityProfiles.BYPASS))
|
||||||
|
for (String profile : new String[] {"dev", "local", "ci", "parity"}) {
|
||||||
|
runner().withPropertyValues("spring.profiles.active=" + profile).run(ctx -> {
|
||||||
|
assertThat(ctx).hasNotFailed();
|
||||||
|
assertThat(statusThroughChain(ctx, "GET", "/api/entity/EIP4PT_TASK/list"))
|
||||||
|
.as("旁路 profile(" + profile + "):permitAll 测试通道开启,无令牌应放行(对拍 CI 依赖)")
|
||||||
.isEqualTo(200);
|
.isEqualTo(200);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,10 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||||
|
import com.eip4.platform.auth.security.SecurityProfiles;
|
||||||
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
|
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService;
|
||||||
import com.eip4.platform.flowgateway.aggregate.TodoAggregator;
|
import com.eip4.platform.flowgateway.aggregate.TodoAggregator;
|
||||||
import com.eip4.platform.flowgateway.aggregate.TodoItem;
|
import com.eip4.platform.flowgateway.aggregate.TodoItem;
|
||||||
@@ -77,15 +80,18 @@ public class TodoController {
|
|||||||
private final StatusWriteback statusWriteback;
|
private final StatusWriteback statusWriteback;
|
||||||
private final BusinessSummaryService businessSummaryService;
|
private final BusinessSummaryService businessSummaryService;
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
/** P0:判定是否处于非生产旁路 profile,用于关闭生产环境的任意脚本执行端点。 */
|
||||||
|
private final Environment environment;
|
||||||
|
|
||||||
public TodoController(TodoAggregator todoAggregator, FlowableClient flowableClient,
|
public TodoController(TodoAggregator todoAggregator, FlowableClient flowableClient,
|
||||||
StatusWriteback statusWriteback, BusinessSummaryService businessSummaryService,
|
StatusWriteback statusWriteback, BusinessSummaryService businessSummaryService,
|
||||||
JdbcTemplate jdbcTemplate) {
|
JdbcTemplate jdbcTemplate, Environment environment) {
|
||||||
this.todoAggregator = todoAggregator;
|
this.todoAggregator = todoAggregator;
|
||||||
this.flowableClient = flowableClient;
|
this.flowableClient = flowableClient;
|
||||||
this.statusWriteback = statusWriteback;
|
this.statusWriteback = statusWriteback;
|
||||||
this.businessSummaryService = businessSummaryService;
|
this.businessSummaryService = businessSummaryService;
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "当前用户待办(含候选组待办)",
|
@Operation(summary = "当前用户待办(含候选组待办)",
|
||||||
@@ -276,12 +282,20 @@ public class TodoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "流程监控高级处理脚本",
|
@Operation(summary = "流程监控高级处理脚本",
|
||||||
description = "流程监控页专用:按老系统语义给 Groovy 绑定 processid/businessKey 后执行;失败返回 AMIS status=1。")
|
description = "流程监控页专用:按老系统语义给 Groovy 绑定 processid/businessKey 后执行;失败返回 AMIS status=1。"
|
||||||
|
+ "【仅非生产旁路 profile 可用:本端点执行请求体里的任意 Groovy(RCE),生产已禁用。】")
|
||||||
@PostMapping("/api/workflow/process/{processInstanceId}/advanced-script")
|
@PostMapping("/api/workflow/process/{processInstanceId}/advanced-script")
|
||||||
public ResponseEntity<Map<String, Object>> runProcessAdvancedScript(
|
public ResponseEntity<Map<String, Object>> runProcessAdvancedScript(
|
||||||
@AuthenticationPrincipal AuthPrincipal principal,
|
@AuthenticationPrincipal AuthPrincipal principal,
|
||||||
@PathVariable String processInstanceId,
|
@PathVariable String processInstanceId,
|
||||||
@RequestBody(required = false) GatewayRequests.AdvancedScriptRequest req) {
|
@RequestBody(required = false) GatewayRequests.AdvancedScriptRequest req) {
|
||||||
|
// P0 安全(2026-06-24 架构评审 followup,安全评审揪出的 ScriptExecuteController 孪生实例):
|
||||||
|
// 本端点执行请求体携带的任意 Groovy(= 远程代码执行 RCE),严禁在生产可达。
|
||||||
|
// 仅 dev/local/ci/parity 旁路 profile 放行;严格(prod/默认)profile 直接拒绝,绝不执行脚本。
|
||||||
|
if (!SecurityProfiles.isBypassActive(environment)) {
|
||||||
|
return ResponseEntity.ok(amisFail(
|
||||||
|
"流程高级处理脚本仅在非生产环境可用(生产已禁用任意脚本执行)"));
|
||||||
|
}
|
||||||
String script = req == null ? null : trim(req.script);
|
String script = req == null ? null : trim(req.script);
|
||||||
if (script == null || script.isBlank()) {
|
if (script == null || script.isBlank()) {
|
||||||
return ResponseEntity.ok(amisFail("请输入高级处理脚本"));
|
return ResponseEntity.ok(amisFail("请输入高级处理脚本"));
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ import java.util.Map;
|
|||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import com.dsasp.server.common.workflow.service.ProcessCoreService;
|
import com.dsasp.server.common.workflow.service.ProcessCoreService;
|
||||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||||
@@ -35,8 +37,18 @@ class TodoControllerAmisTest {
|
|||||||
private final StatusWriteback statusWriteback = mock(StatusWriteback.class);
|
private final StatusWriteback statusWriteback = mock(StatusWriteback.class);
|
||||||
private final BusinessSummaryService businessSummaryService = mock(BusinessSummaryService.class);
|
private final BusinessSummaryService businessSummaryService = mock(BusinessSummaryService.class);
|
||||||
private final JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
private final JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||||
|
// 共享控制器走旁路 profile(ci),其余 amis 端点测试不受 P0 脚本守卫影响。
|
||||||
private final TodoController controller = new TodoController(
|
private final TodoController controller = new TodoController(
|
||||||
aggregator, flowableClient, statusWriteback, businessSummaryService, jdbcTemplate);
|
aggregator, flowableClient, statusWriteback, businessSummaryService, jdbcTemplate,
|
||||||
|
new MockEnvironment().withProperty("spring.profiles.active", "ci"));
|
||||||
|
|
||||||
|
/** 构造指定 active profile 的控制器(用于高级脚本端点的 profile 守卫测试)。 */
|
||||||
|
private TodoController controllerWithProfiles(String... profiles) {
|
||||||
|
MockEnvironment env = new MockEnvironment();
|
||||||
|
env.setActiveProfiles(profiles);
|
||||||
|
return new TodoController(aggregator, flowableClient, statusWriteback,
|
||||||
|
businessSummaryService, jdbcTemplate, env);
|
||||||
|
}
|
||||||
|
|
||||||
private static AuthPrincipal principal() {
|
private static AuthPrincipal principal() {
|
||||||
return new AuthPrincipal("U1", "u1", "张三", "D1", "O1", List.of("R1"));
|
return new AuthPrincipal("U1", "u1", "张三", "D1", "O1", List.of("R1"));
|
||||||
@@ -302,4 +314,33 @@ class TodoControllerAmisTest {
|
|||||||
dto.ended = ended;
|
dto.ended = ended;
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ───────────────────── P0:高级处理脚本端点 profile 守卫(RCE 防护) ─────────────────────
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void advancedScript_严格profile_拒绝执行且不触达引擎() {
|
||||||
|
TodoController prod = controllerWithProfiles(); // 无 active profile = 严格(prod 同)
|
||||||
|
GatewayRequests.AdvancedScriptRequest req = new GatewayRequests.AdvancedScriptRequest();
|
||||||
|
req.script = "Runtime.getRuntime().exec('id')"; // 攻击载荷
|
||||||
|
|
||||||
|
Map<String, Object> body = prod.runProcessAdvancedScript(principal(), "PI-1", req).getBody();
|
||||||
|
|
||||||
|
assertThat(body.get("status")).as("严格 profile 必须拒绝(amis status=1)").isEqualTo(1);
|
||||||
|
assertThat(String.valueOf(body.get("msg"))).contains("生产");
|
||||||
|
// 关键:守卫在执行/取流程实例之前短路,脚本绝不进引擎
|
||||||
|
verify(flowableClient, never()).processInstance(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void advancedScript_旁路profile_放行通过守卫到脚本校验() {
|
||||||
|
TodoController dev = controllerWithProfiles("dev");
|
||||||
|
GatewayRequests.AdvancedScriptRequest req = new GatewayRequests.AdvancedScriptRequest();
|
||||||
|
req.script = " "; // 空脚本:证明已越过 profile 守卫,落到下一道 script 非空校验
|
||||||
|
|
||||||
|
Map<String, Object> body = dev.runProcessAdvancedScript(principal(), "PI-1", req).getBody();
|
||||||
|
|
||||||
|
assertThat(body.get("status")).isEqualTo(1);
|
||||||
|
assertThat(String.valueOf(body.get("msg")))
|
||||||
|
.as("旁路 profile 不被守卫拦截,落到脚本非空校验").contains("请输入高级处理脚本");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ public class RewrittenScriptStore {
|
|||||||
|
|
||||||
public RewrittenScriptStore(
|
public RewrittenScriptStore(
|
||||||
@Value("${eip4.script.rewritten-root:tools/s3_rewriter/output/rewritten}") String rewrittenRoot) {
|
@Value("${eip4.script.rewritten-root:tools/s3_rewriter/output/rewritten}") String rewrittenRoot) {
|
||||||
this.root = Path.of(rewrittenRoot);
|
// normalize 一次,后续 load 用 startsWith(root) 做路径包含校验防 ../ 穿越。
|
||||||
|
this.root = Path.of(rewrittenRoot).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,8 +48,16 @@ public class RewrittenScriptStore {
|
|||||||
if (templateId == null || templateId.isBlank()) {
|
if (templateId == null || templateId.isBlank()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Path dir = root.resolve(templateId);
|
// P0 安全(2026-06-24 架构评审):templateId 来自请求体,resolve 后 normalize 并校验仍在
|
||||||
if (!Files.isDirectory(dir)) {
|
// root 之内,防 `../../` 穿越读取脚本库外任意 .groovy 文件并交保真层执行(路径穿越→RCE)。
|
||||||
|
Path dir;
|
||||||
|
try {
|
||||||
|
dir = root.resolve(templateId).normalize();
|
||||||
|
} catch (java.nio.file.InvalidPathException e) {
|
||||||
|
// 非法路径字符(如 NUL 字节)→ 当作未找到,优雅降级而非 500。
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!dir.startsWith(root) || !Files.isDirectory(dir)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String prefix = seq + ".";
|
String prefix = seq + ".";
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.eip4.platform.metadata.script;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.script.Bindings;
|
||||||
|
|
||||||
|
import com.dsasp.server.dataDic.binding.ScriptingEnginesManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 脚本 facade 执行的共享原语:把脚本经保真层 {@link ScriptingEnginesManager} 执行,
|
||||||
|
* 行数据上下文 + facade 动词注入 {@link Bindings},返回捕获的 amis 事件动作指令。
|
||||||
|
*
|
||||||
|
* <p>P0 拆分(2026-06-24 架构评审)后,「生产改写脚本重放」({@code ScriptReplayController})与
|
||||||
|
* 「开发任意脚本执行」({@code ScriptExecuteController},@Profile 旁路限定)共用本原语,避免重复。
|
||||||
|
*/
|
||||||
|
public final class ScriptFacadeRunner {
|
||||||
|
|
||||||
|
private ScriptFacadeRunner() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用 facade 动词表执行脚本,返回捕获的 amis 指令。
|
||||||
|
*
|
||||||
|
* @param key 缓存/诊断键(模板/序号派生),允许 null
|
||||||
|
* @param script 脚本正文
|
||||||
|
* @param item 当前行数据域(facade 动词读写)
|
||||||
|
*/
|
||||||
|
public static List<Map<String, Object>> run(String key, String script, Map<String, Object> item) {
|
||||||
|
ScriptFacade facade = new ScriptFacade(item);
|
||||||
|
Bindings bindings = facade.buildBindings(item);
|
||||||
|
ScriptingEnginesManager.getScriptingEnginesManager()
|
||||||
|
.evaluateGroovy(key, script, bindings);
|
||||||
|
return facade.getCommands();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -218,7 +218,21 @@ public class EntityController {
|
|||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
private Properties buildCtx(String asUser, String roles, String asDepart, String asOrg) {
|
private Properties buildCtx(String asUser, String roles, String asDepart, String asOrg) {
|
||||||
// 1) 显式 asUser 测试通道优先(保持 C2 既有行为不变)
|
// P0 修复(2026-06-24 架构评审):JWT 已绑定的认证身份【权威】,一律优先于客户端传入的
|
||||||
|
// asUser/roles —— 杜绝「已认证用户传 asUser=他人 / roles=ADMIN 冒充提权」(IDOR + 越权)。
|
||||||
|
//
|
||||||
|
// 1) JWT 过滤器已绑定的请求级身份(任何非空 CURRENTUSER,含 ADMIN)→ 直接复用,忽略 asUser/roles。
|
||||||
|
// 含 ADMIN:认证为 ADMIN 即用 ADMIN 自身视角(引擎对 ADMIN 不做行级过滤),asUser 同样不生效。
|
||||||
|
Properties bound = UserSession.get();
|
||||||
|
if (bound != null) {
|
||||||
|
String cu = bound.getProperty(LoggedInUser.CURRENTUSER);
|
||||||
|
if (cu != null && !cu.isBlank()) {
|
||||||
|
return bound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2) 无 JWT 身份时的 asUser/roles 测试通道。【仅非生产 permitAll 旁路可达】:严格链要求认证,
|
||||||
|
// 带令牌必经上面第 1 步;故在 prod / 默认严格链下,匿名请求根本进不来,本分支结构上不可达。
|
||||||
|
// 供对拍框架免令牌按指定用户/角色重放(驱动 POJOCRUDServiceImpl 行级过滤)。
|
||||||
if (asUser != null && !asUser.isBlank()) {
|
if (asUser != null && !asUser.isBlank()) {
|
||||||
Properties ctx = new Properties();
|
Properties ctx = new Properties();
|
||||||
ctx.setProperty(LoggedInUser.CURRENTUSER, asUser);
|
ctx.setProperty(LoggedInUser.CURRENTUSER, asUser);
|
||||||
@@ -241,14 +255,6 @@ public class EntityController {
|
|||||||
ctx.put(LoggedInUser.ROLES, roleList);
|
ctx.put(LoggedInUser.ROLES, roleList);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
// 2) JWT 过滤器已绑定的请求级上下文(非 ADMIN 真实用户)→ 复用,驱动行级过滤
|
|
||||||
Properties bound = UserSession.get();
|
|
||||||
if (bound != null) {
|
|
||||||
String cu = bound.getProperty(LoggedInUser.CURRENTUSER);
|
|
||||||
if (cu != null && !cu.isBlank() && !LoggedInUser.ADMIN.trim().equals(cu.trim())) {
|
|
||||||
return bound;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 3) 默认 ADMIN 视角(无令牌、无 asUser)
|
// 3) 默认 ADMIN 视角(无令牌、无 asUser)
|
||||||
return UserSession.getAdmin();
|
return UserSession.getAdmin();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -859,14 +859,27 @@ public class PickerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行级权限上下文构造,与 {@link EntityController#buildCtx} 同口径(三级优先):
|
* 行级权限上下文构造,与 {@link EntityController#buildCtx} 同口径(JWT 身份权威):
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>显式 {@code asUser}(对拍测试通道)→ 非 ADMIN 视角,触发行级过滤;</li>
|
* <li>JWT 过滤器已绑定的请求级身份(任何非空 CURRENTUSER,含 ADMIN)→ 直接复用,忽略 asUser/roles;</li>
|
||||||
* <li>JWT 过滤器已绑定的请求级上下文(真实用户,非 ADMIN)→ 复用;</li>
|
* <li>无 JWT 身份时的 asUser/roles 测试通道(仅非生产 permitAll 旁路可达,供对拍免令牌重放);</li>
|
||||||
* <li>都没有 → ADMIN 视角(不过滤)。</li>
|
* <li>都没有 → ADMIN 视角(不过滤)。</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
|
*
|
||||||
|
* <p>P0 修复(2026-06-24 架构评审 followup,安全评审揪出的 EntityController 孪生实例):
|
||||||
|
* JWT 已绑定的认证身份【权威】,一律优先于客户端传入的 asUser/roles——杜绝「已认证用户传
|
||||||
|
* asUser=他人 / roles=ADMIN 经 picker list/resolve 冒充提权读取越权数据」(IDOR + 越权)。
|
||||||
*/
|
*/
|
||||||
private Properties buildCtx(String asUser, String roles, String asDepart, String asOrg) {
|
private Properties buildCtx(String asUser, String roles, String asDepart, String asOrg) {
|
||||||
|
// 1) JWT 绑定身份恒优先(含 ADMIN),忽略客户端 asUser/roles
|
||||||
|
Properties bound = UserSession.get();
|
||||||
|
if (bound != null) {
|
||||||
|
String cu = bound.getProperty(LoggedInUser.CURRENTUSER);
|
||||||
|
if (cu != null && !cu.isBlank()) {
|
||||||
|
return bound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2) 无 JWT 身份时的 asUser/roles 测试通道(仅非生产旁路可达;prod 严格链要求认证,结构上不可达)
|
||||||
if (asUser != null && !asUser.isBlank()) {
|
if (asUser != null && !asUser.isBlank()) {
|
||||||
Properties ctx = new Properties();
|
Properties ctx = new Properties();
|
||||||
ctx.setProperty(LoggedInUser.CURRENTUSER, asUser);
|
ctx.setProperty(LoggedInUser.CURRENTUSER, asUser);
|
||||||
@@ -887,13 +900,7 @@ public class PickerController {
|
|||||||
ctx.put(LoggedInUser.ROLES, roleList);
|
ctx.put(LoggedInUser.ROLES, roleList);
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
Properties bound = UserSession.get();
|
// 3) 默认 ADMIN 视角
|
||||||
if (bound != null) {
|
|
||||||
String cu = bound.getProperty(LoggedInUser.CURRENTUSER);
|
|
||||||
if (cu != null && !cu.isBlank() && !LoggedInUser.ADMIN.trim().equals(cu.trim())) {
|
|
||||||
return bound;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return UserSession.getAdmin();
|
return UserSession.getAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||||
import com.dsasp.server.common.util.UserSession;
|
import com.dsasp.server.common.util.UserSession;
|
||||||
|
import com.eip4.platform.auth.security.SecurityProfiles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WS1 主子表级联验证:SYS_DATA_LOG(主) → DETAILLIST → SYS_DATA_LOGITEM(子)。
|
* WS1 主子表级联验证:SYS_DATA_LOG(主) → DETAILLIST → SYS_DATA_LOGITEM(子)。
|
||||||
@@ -23,6 +25,7 @@ import com.dsasp.server.common.util.UserSession;
|
|||||||
* 测试行以 COLUMNNAME=EIP4POC_* 标记,结束后行数断言复原,残留兜底清理。
|
* 测试行以 COLUMNNAME=EIP4POC_* 标记,结束后行数断言复原,残留兜底清理。
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@Profile(SecurityProfiles.BYPASS)
|
||||||
public class PocMasterSubController {
|
public class PocMasterSubController {
|
||||||
|
|
||||||
// 首选 SYS_DATA_LOG 对在 diff 更新时暴露了选表不当:其子表为 insert-only 设计
|
// 首选 SYS_DATA_LOG 对在 diff 更新时暴露了选表不当:其子表为 insert-only 设计
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import javax.script.SimpleBindings;
|
|||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.dsasp.server.dataDic.binding.ScriptingEnginesManager;
|
import com.dsasp.server.dataDic.binding.ScriptingEnginesManager;
|
||||||
|
import com.eip4.platform.auth.security.SecurityProfiles;
|
||||||
|
|
||||||
import groovy.lang.Closure;
|
import groovy.lang.Closure;
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ import groovy.lang.Closure;
|
|||||||
* 指令列表——即「脚本文本零修改,换 facade 实现」方案的最小实证。
|
* 指令列表——即「脚本文本零修改,换 facade 实现」方案的最小实证。
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@Profile(SecurityProfiles.BYPASS)
|
||||||
public class PocScriptTestController {
|
public class PocScriptTestController {
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.eip4.platform.auth.security.SecurityProfiles;
|
||||||
|
|
||||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||||
@@ -22,8 +25,13 @@ import com.dsasp.server.dataDic.bean.Entity;
|
|||||||
* WS1 写路径一键验证(PoC 方案 3.1 步骤 7):
|
* WS1 写路径一键验证(PoC 方案 3.1 步骤 7):
|
||||||
* 克隆既有小实体的元数据 → 动态生成并执行 CREATE TABLE → CRUD 往返 → 全量清理。
|
* 克隆既有小实体的元数据 → 动态生成并执行 CREATE TABLE → CRUD 往返 → 全量清理。
|
||||||
* 所有产物以 target 表名隔离(默认 EIP4POCTEST),结束后物理表与元数据一并删除。
|
* 所有产物以 target 表名隔离(默认 EIP4POCTEST),结束后物理表与元数据一并删除。
|
||||||
|
*
|
||||||
|
* <p><strong>P0 安全(2026-06-24 架构评审)</strong>:本 PoC 控制器 {@code cleanup} 以
|
||||||
|
* {@code DROP TABLE IF EXISTS <target>} 裸拼请求参数(可传 {@code target=SYS_USER} 任意删表),
|
||||||
|
* 严禁随生产 jar 装配。故 {@code @Profile(SecurityProfiles.BYPASS)}——仅 dev/local/ci/parity 装配。
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@Profile(SecurityProfiles.BYPASS)
|
||||||
public class PocWriteTestController {
|
public class PocWriteTestController {
|
||||||
|
|
||||||
private final DataDicService dataDicService;
|
private final DataDicService dataDicService;
|
||||||
|
|||||||
@@ -4,56 +4,40 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.script.Bindings;
|
|
||||||
|
|
||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.dsasp.server.dataDic.binding.ScriptingEnginesManager;
|
import com.eip4.platform.auth.security.SecurityProfiles;
|
||||||
import com.eip4.platform.metadata.flow.EnumDisplayResolver;
|
import com.eip4.platform.metadata.script.ScriptFacadeRunner;
|
||||||
import com.eip4.platform.metadata.script.RewrittenScriptStore;
|
|
||||||
import com.eip4.platform.metadata.script.ScriptFacade;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 脚本执行端点(P4 脚本迁移线 任务2 集成)。
|
* 脚本<strong>开发/调试</strong>执行端点——执行<em>请求体里的任意脚本</em>,仅供改写验证用。
|
||||||
*
|
*
|
||||||
* <p>把(改写后的)Groovy 脚本经保真层 {@link ScriptingEnginesManager} 执行,行数据上下文 +
|
* <p><strong>P0 安全(2026-06-24 架构评审)</strong>:本控制器的 {@code /api/script/execute}
|
||||||
* 31 个 facade 动词由 {@link ScriptFacade} 注入 {@link Bindings}:
|
* 直接执行请求体携带的任意 Groovy(= 远程代码执行 RCE),严禁随生产 jar 装配。故全类
|
||||||
* <ul>
|
* {@code @Profile(SecurityProfiles.BYPASS)}——<strong>仅 dev/local/ci/parity 装配,生产不可达</strong>。
|
||||||
* <li>服务端语义动词(getFieldValue 等)在服务端求值;</li>
|
|
||||||
* <li>UI 语义动词(setFieldVisible/showToast/addSubTableButton…)捕获为 amis 事件动作
|
|
||||||
* 指令 JSON 数组(actionType/componentId/args)返回前端。</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
*
|
||||||
* <p>架构:本控制器与 {@link ScriptFacade} 均在现代层 {@code com.eip4.*},仅向保真层注入闭包,
|
* <p>生产运行时的「改写后脚本重放」(脚本来源 = 脚本库内已审产物,非请求体)已隔离到
|
||||||
|
* {@code ScriptReplayController}(/api/script/execute-template,无 @Profile,随生产装配)。
|
||||||
|
*
|
||||||
|
* <p>架构:本控制器在现代层 {@code com.eip4.*},仅经 {@link ScriptFacadeRunner} 向保真层注入闭包,
|
||||||
* 不改 {@code com.dsasp} 源码。
|
* 不改 {@code com.dsasp} 源码。
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
|
@Profile(SecurityProfiles.BYPASS)
|
||||||
public class ScriptExecuteController {
|
public class ScriptExecuteController {
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final RewrittenScriptStore rewrittenScriptStore;
|
|
||||||
/** 小修#2:脚本执行前给 item 注入枚举列显示串(复刻老系统 grid 行 item 语义),修 {@code item['ISPLACE']=="未归档"} 类脚本。 */
|
|
||||||
private final EnumDisplayResolver enumDisplayResolver;
|
|
||||||
|
|
||||||
@Autowired
|
public ScriptExecuteController(JdbcTemplate jdbcTemplate) {
|
||||||
public ScriptExecuteController(JdbcTemplate jdbcTemplate, RewrittenScriptStore rewrittenScriptStore,
|
|
||||||
EnumDisplayResolver enumDisplayResolver) {
|
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
this.rewrittenScriptStore = rewrittenScriptStore;
|
|
||||||
this.enumDisplayResolver = enumDisplayResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 兼容旧 2 参构造(单测/旧接线):从 jdbcTemplate 自建枚举显示值解析器。 */
|
|
||||||
public ScriptExecuteController(JdbcTemplate jdbcTemplate, RewrittenScriptStore rewrittenScriptStore) {
|
|
||||||
this(jdbcTemplate, rewrittenScriptStore, new EnumDisplayResolver(jdbcTemplate));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +60,7 @@ public class ScriptExecuteController {
|
|||||||
? (Map<String, Object>) body.get("item") : new LinkedHashMap<>();
|
? (Map<String, Object>) body.get("item") : new LinkedHashMap<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Map<String, Object>> commands = runWithFacade(null, script, item);
|
List<Map<String, Object>> commands = ScriptFacadeRunner.run(null, script, item);
|
||||||
resp.put("passed", true);
|
resp.put("passed", true);
|
||||||
resp.put("item", item);
|
resp.put("item", item);
|
||||||
resp.put("commands", commands);
|
resp.put("commands", commands);
|
||||||
@@ -92,9 +76,6 @@ public class ScriptExecuteController {
|
|||||||
/**
|
/**
|
||||||
* 按模板名从客户库取「库内原始脚本」执行(P4-2 端到端验证端点,保留兼容)。
|
* 按模板名从客户库取「库内原始脚本」执行(P4-2 端到端验证端点,保留兼容)。
|
||||||
*
|
*
|
||||||
* <p>注:P4-5 改写后脚本挂回链路走 {@link #executeTemplateRewritten}(按 templateId/seq 取
|
|
||||||
* 改写产物);本端点按模板名取库内 XML 原始脚本,端点路径区隔为 {@code -by-name}。
|
|
||||||
*
|
|
||||||
* @param template 模板名(VIEW_TEMPLATE.NAME)
|
* @param template 模板名(VIEW_TEMPLATE.NAME)
|
||||||
* @param state 注入 item.ISPLACE 的取值,便于驱动分支
|
* @param state 注入 item.ISPLACE 的取值,便于驱动分支
|
||||||
*/
|
*/
|
||||||
@@ -115,89 +96,13 @@ public class ScriptExecuteController {
|
|||||||
}
|
}
|
||||||
resp.put("template", template);
|
resp.put("template", template);
|
||||||
resp.put("scriptSource", script);
|
resp.put("scriptSource", script);
|
||||||
List<Map<String, Object>> commands = runWithFacade("tpl:" + template, script, item);
|
List<Map<String, Object>> commands = ScriptFacadeRunner.run("tpl:" + template, script, item);
|
||||||
resp.put("commands", commands);
|
resp.put("commands", commands);
|
||||||
resp.put("commandCount", commands.size());
|
resp.put("commandCount", commands.size());
|
||||||
resp.put("passed", true);
|
resp.put("passed", true);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 改写后脚本挂回 onEvent 重放链路的执行端点(P4-5)。
|
|
||||||
*
|
|
||||||
* <p>转换器在 amis 页面 onEvent 里配置「调本端点,传 templateId/seq/item」;本端点按
|
|
||||||
* {@code (templateId, seq)} 从改写后脚本库({@link RewrittenScriptStore})取脚本正文,
|
|
||||||
* 经 facade 执行,返回 amis 事件动作指令数组供前端逐条重放(show/hidden/setValue/setOptions/toast 等)。
|
|
||||||
*
|
|
||||||
* <p>请求体:{@code {"templateId":"021e...","seq":2,"item":{"STORE_ID":"X",...}}}<br>
|
|
||||||
* 返回 :{@code {"commands":[{actionType,componentId,args},...], "passed":true, "item":{...}}}
|
|
||||||
*
|
|
||||||
* @param body templateId(落盘目录名)+ seq(脚本序号)+ item(amis 表单当前数据域)
|
|
||||||
*/
|
|
||||||
@PostMapping("/api/script/execute-template")
|
|
||||||
public Map<String, Object> executeTemplateRewritten(@RequestBody Map<String, Object> body) {
|
|
||||||
Map<String, Object> resp = new LinkedHashMap<>();
|
|
||||||
String templateId = body.get("templateId") == null ? null : String.valueOf(body.get("templateId"));
|
|
||||||
if (templateId == null || templateId.isBlank()) {
|
|
||||||
resp.put("passed", false);
|
|
||||||
resp.put("error", "缺少 templateId");
|
|
||||||
return resp;
|
|
||||||
}
|
|
||||||
int seq = body.get("seq") instanceof Number n ? n.intValue() : parseSeq(body.get("seq"));
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> item = body.get("item") instanceof Map
|
|
||||||
? (Map<String, Object>) body.get("item") : new LinkedHashMap<>();
|
|
||||||
|
|
||||||
String script = rewrittenScriptStore.load(templateId, seq);
|
|
||||||
if (script == null || script.isBlank()) {
|
|
||||||
// WS-B C1-b:脚本未找到(残余缺脚本/seq 偏差)退化为「无联动」no-op,而非用户可见 ajax 报错。
|
|
||||||
// 转换期 fail-closed 已尽量不挂缺文件的绑定;此处兜底任何残余,返空 commands → 前端无动作可重放。
|
|
||||||
resp.put("templateId", templateId);
|
|
||||||
resp.put("seq", seq);
|
|
||||||
resp.put("passed", true);
|
|
||||||
resp.put("commands", List.of());
|
|
||||||
resp.put("commandCount", 0);
|
|
||||||
resp.put("note", "改写后脚本未找到,按无联动处理(no-op): templateId=" + templateId + " seq=" + seq);
|
|
||||||
return resp;
|
|
||||||
}
|
|
||||||
// 小修#2:脚本执行前把 item 里枚举列的裸码换成显示串(复刻老系统 grid 行 item 语义),使
|
|
||||||
// onselectedscript 里 `item['ISPLACE'] == "未归档"` 类显示串比较成立(否则裸码 0 != "未归档"
|
|
||||||
// → 文件归档等按钮永不点亮)。表名从 item 的 <TABLE>_ID 主键反推;失败静默跳过不影响主路径。
|
|
||||||
if (enumDisplayResolver != null) {
|
|
||||||
enumDisplayResolver.enrichItem(null, item);
|
|
||||||
}
|
|
||||||
resp.put("templateId", templateId);
|
|
||||||
resp.put("seq", seq);
|
|
||||||
try {
|
|
||||||
List<Map<String, Object>> commands = runWithFacade("rw:" + templateId + ":" + seq, script, item);
|
|
||||||
resp.put("passed", true);
|
|
||||||
resp.put("item", item);
|
|
||||||
resp.put("commands", commands);
|
|
||||||
resp.put("commandCount", commands.size());
|
|
||||||
} catch (Exception e) {
|
|
||||||
resp.put("passed", false);
|
|
||||||
resp.put("error", e.getMessage());
|
|
||||||
}
|
|
||||||
return resp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int parseSeq(Object raw) {
|
|
||||||
try {
|
|
||||||
return raw == null ? 1 : Integer.parseInt(String.valueOf(raw).trim());
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 用 facade 动词表执行脚本,返回捕获的 amis 指令。 */
|
|
||||||
private List<Map<String, Object>> runWithFacade(String key, String script, Map<String, Object> item) {
|
|
||||||
ScriptFacade facade = new ScriptFacade(item);
|
|
||||||
Bindings bindings = facade.buildBindings(item);
|
|
||||||
ScriptingEnginesManager.getScriptingEnginesManager()
|
|
||||||
.evaluateGroovy(key, script, bindings);
|
|
||||||
return facade.getCommands();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 从 VIEW_TEMPLATE 取模板第一段实质脚本(getText 保留换行,见迁移手册 5.3)。 */
|
/** 从 VIEW_TEMPLATE 取模板第一段实质脚本(getText 保留换行,见迁移手册 5.3)。 */
|
||||||
private String extractScript(String template) throws Exception {
|
private String extractScript(String template) throws Exception {
|
||||||
List<String> xmls = jdbcTemplate.queryForList(
|
List<String> xmls = jdbcTemplate.queryForList(
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package com.eip4.platform.metadata.web;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.eip4.platform.metadata.flow.EnumDisplayResolver;
|
||||||
|
import com.eip4.platform.metadata.script.RewrittenScriptStore;
|
||||||
|
import com.eip4.platform.metadata.script.ScriptFacadeRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 改写后脚本挂回 onEvent 重放执行端点(P4-5)——<strong>生产运行时依赖</strong>。
|
||||||
|
*
|
||||||
|
* <p>转换器在 amis 页面 onEvent 里配置「调本端点,传 templateId/seq/item」;本端点按
|
||||||
|
* {@code (templateId, seq)} 从改写后脚本库({@link RewrittenScriptStore})取<em>已落盘、已审</em>
|
||||||
|
* 的脚本正文,经 facade 执行,返回 amis 事件动作指令数组供前端逐条重放。
|
||||||
|
*
|
||||||
|
* <p><strong>P0 安全拆分(2026-06-24 架构评审)</strong>:本控制器只重放<em>脚本库内</em>脚本
|
||||||
|
* (脚本来源 = S3 改写器落盘产物,非请求体),不接受请求体里的任意脚本,故可随生产 jar 装配。
|
||||||
|
* 「执行请求体任意 Groovy(RCE)」的开发端点已隔离到 {@code ScriptExecuteController}
|
||||||
|
* (@Profile 旁路限定,生产不装配)。{@link RewrittenScriptStore} 另对 {@code templateId} 做
|
||||||
|
* 路径包含校验,防 {@code ../} 穿越读任意 {@code .groovy} 文件。
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class ScriptReplayController {
|
||||||
|
|
||||||
|
private final RewrittenScriptStore rewrittenScriptStore;
|
||||||
|
/** 脚本执行前给 item 注入枚举列显示串(复刻老系统 grid 行 item 语义),修 {@code item['ISPLACE']=="未归档"} 类脚本。 */
|
||||||
|
private final EnumDisplayResolver enumDisplayResolver;
|
||||||
|
|
||||||
|
public ScriptReplayController(RewrittenScriptStore rewrittenScriptStore,
|
||||||
|
EnumDisplayResolver enumDisplayResolver) {
|
||||||
|
this.rewrittenScriptStore = rewrittenScriptStore;
|
||||||
|
this.enumDisplayResolver = enumDisplayResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 改写后脚本挂回 onEvent 重放链路的执行端点(P4-5)。
|
||||||
|
*
|
||||||
|
* <p>请求体:{@code {"templateId":"021e...","seq":2,"item":{"STORE_ID":"X",...}}}<br>
|
||||||
|
* 返回 :{@code {"commands":[{actionType,componentId,args},...], "passed":true, "item":{...}}}
|
||||||
|
*/
|
||||||
|
@PostMapping("/api/script/execute-template")
|
||||||
|
public Map<String, Object> executeTemplateRewritten(@RequestBody Map<String, Object> body) {
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
String templateId = body.get("templateId") == null ? null : String.valueOf(body.get("templateId"));
|
||||||
|
if (templateId == null || templateId.isBlank()) {
|
||||||
|
resp.put("passed", false);
|
||||||
|
resp.put("error", "缺少 templateId");
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
int seq = body.get("seq") instanceof Number n ? n.intValue() : parseSeq(body.get("seq"));
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> item = body.get("item") instanceof Map
|
||||||
|
? (Map<String, Object>) body.get("item") : new LinkedHashMap<>();
|
||||||
|
|
||||||
|
String script = rewrittenScriptStore.load(templateId, seq);
|
||||||
|
if (script == null || script.isBlank()) {
|
||||||
|
// WS-B C1-b:脚本未找到(残余缺脚本/seq 偏差)退化为「无联动」no-op,而非用户可见 ajax 报错。
|
||||||
|
resp.put("templateId", templateId);
|
||||||
|
resp.put("seq", seq);
|
||||||
|
resp.put("passed", true);
|
||||||
|
resp.put("commands", List.of());
|
||||||
|
resp.put("commandCount", 0);
|
||||||
|
resp.put("note", "改写后脚本未找到,按无联动处理(no-op): templateId=" + templateId + " seq=" + seq);
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
// 执行前把 item 里枚举列的裸码换成显示串(复刻老系统 grid 行 item 语义),使
|
||||||
|
// onselectedscript 里 `item['ISPLACE'] == "未归档"` 类显示串比较成立。失败静默跳过不影响主路径。
|
||||||
|
if (enumDisplayResolver != null) {
|
||||||
|
enumDisplayResolver.enrichItem(null, item);
|
||||||
|
}
|
||||||
|
resp.put("templateId", templateId);
|
||||||
|
resp.put("seq", seq);
|
||||||
|
try {
|
||||||
|
List<Map<String, Object>> commands =
|
||||||
|
ScriptFacadeRunner.run("rw:" + templateId + ":" + seq, script, item);
|
||||||
|
resp.put("passed", true);
|
||||||
|
resp.put("item", item);
|
||||||
|
resp.put("commands", commands);
|
||||||
|
resp.put("commandCount", commands.size());
|
||||||
|
} catch (Exception e) {
|
||||||
|
resp.put("passed", false);
|
||||||
|
resp.put("error", e.getMessage());
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int parseSeq(Object raw) {
|
||||||
|
try {
|
||||||
|
return raw == null ? 1 : Integer.parseInt(String.valueOf(raw).trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,4 +59,20 @@ class RewrittenScriptStoreTest {
|
|||||||
assertNull(store.load("", 1));
|
assertNull(store.load("", 1));
|
||||||
assertFalse(store.load("no-such-tid", 9) != null);
|
assertFalse(store.load("no-such-tid", 9) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** P0:templateId 路径穿越(../)不得读取脚本库根之外的 .groovy 文件,返回 null。 */
|
||||||
|
@Test
|
||||||
|
void load_路径穿越templateId拒绝读库外文件(@TempDir Path tmp) throws IOException {
|
||||||
|
Path root = tmp.resolve("rewritten");
|
||||||
|
Files.createDirectories(root);
|
||||||
|
// 在 root 之外(同 tmp 下的兄弟目录)放一个真实可读的脚本目录
|
||||||
|
Path evil = tmp.resolve("evil");
|
||||||
|
Files.createDirectories(evil);
|
||||||
|
Files.writeString(evil.resolve("1.x.groovy"), "showToast(\"pwned\");", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
RewrittenScriptStore store = new RewrittenScriptStore(root.toString());
|
||||||
|
// ../evil 解析后落在 root 之外 → 包含校验拒绝 → null(即便目标文件真实存在)
|
||||||
|
assertNull(store.load("../evil", 1), "穿越出脚本库根必须拒绝");
|
||||||
|
assertNull(store.load("../../evil", 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|||||||
|
|
||||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||||
|
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||||
|
import com.dsasp.server.common.util.UserSession;
|
||||||
import com.eip4.platform.metadata.security.IdentifierWhitelist;
|
import com.eip4.platform.metadata.security.IdentifierWhitelist;
|
||||||
import com.eip4.platform.metadata.security.IdentifierWhitelistExceptionHandler;
|
import com.eip4.platform.metadata.security.IdentifierWhitelistExceptionHandler;
|
||||||
import com.eip4.platform.metadata.security.IllegalIdentifierException;
|
import com.eip4.platform.metadata.security.IllegalIdentifierException;
|
||||||
@@ -165,6 +167,56 @@ class EntityControllerWhitelistTest {
|
|||||||
assertFalse(String.valueOf(resp.getBody().get("msg")).contains("'"));
|
assertFalse(String.valueOf(resp.getBody().get("msg")).contains("'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void P0_JWT身份权威_忽略客户端asUser冒充提权() {
|
||||||
|
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||||
|
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||||
|
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(new HashMap<>());
|
||||||
|
EntityController c = new EntityController(engine, wl,
|
||||||
|
mock(JdbcTemplate.class), mock(PickerController.class));
|
||||||
|
|
||||||
|
// 模拟 JwtAuthFilter 已绑定真实非 ADMIN 用户 userA 到引擎上下文
|
||||||
|
Properties jwtBound = new Properties();
|
||||||
|
jwtBound.setProperty(LoggedInUser.CURRENTUSER, "userA");
|
||||||
|
UserSession.set(jwtBound);
|
||||||
|
try {
|
||||||
|
// 攻击:已认证 userA 传 asUser=ADMIN&roles=ADMIN 试图冒充提权
|
||||||
|
c.list(TABLE, 1, 10, "ADMIN", "ADMIN", null, null, null, null, new HashMap<>());
|
||||||
|
|
||||||
|
ArgumentCaptor<Properties> ctxCap = ArgumentCaptor.forClass(Properties.class);
|
||||||
|
verify(engine).listSelect(any(), eq(TABLE), ctxCap.capture());
|
||||||
|
Properties used = ctxCap.getValue();
|
||||||
|
assertEquals("userA", used.getProperty(LoggedInUser.CURRENTUSER),
|
||||||
|
"必须以 JWT 身份 userA 为准,绝不采用客户端 asUser=ADMIN");
|
||||||
|
assertFalse(used.containsKey(LoggedInUser.ROLES),
|
||||||
|
"客户端 roles=ADMIN 必须被忽略,不得注入 ADMIN 角色");
|
||||||
|
} finally {
|
||||||
|
UserSession.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
void 无JWT身份时asUser测试通道仍生效_对拍依赖() {
|
||||||
|
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||||
|
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||||
|
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(new HashMap<>());
|
||||||
|
EntityController c = new EntityController(engine, wl,
|
||||||
|
mock(JdbcTemplate.class), mock(PickerController.class));
|
||||||
|
|
||||||
|
// 无 JWT 绑定(对拍免令牌路径):asUser/roles 通道生效
|
||||||
|
UserSession.remove();
|
||||||
|
c.list(TABLE, 1, 10, "userB", "ROLE_X", null, null, null, null, new HashMap<>());
|
||||||
|
|
||||||
|
ArgumentCaptor<Properties> ctxCap = ArgumentCaptor.forClass(Properties.class);
|
||||||
|
verify(engine).listSelect(any(), eq(TABLE), ctxCap.capture());
|
||||||
|
Properties used = ctxCap.getValue();
|
||||||
|
assertEquals("userB", used.getProperty(LoggedInUser.CURRENTUSER),
|
||||||
|
"无 JWT 身份时 asUser 测试通道生效(对拍框架依赖)");
|
||||||
|
assertEquals(List.of("ROLE_X"), used.get(LoggedInUser.ROLES));
|
||||||
|
}
|
||||||
|
|
||||||
/** 单字段 GeneralPOJO 桩:主键 + 一个引用列 MENUROOT=值。 */
|
/** 单字段 GeneralPOJO 桩:主键 + 一个引用列 MENUROOT=值。 */
|
||||||
private static GeneralPOJO refRow(String id, String menuRoot) {
|
private static GeneralPOJO refRow(String id, String menuRoot) {
|
||||||
GeneralPOJO p = mock(GeneralPOJO.class);
|
GeneralPOJO p = mock(GeneralPOJO.class);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.dsasp.server.common.dataDic.bean.SYS_Entity;
|
|||||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||||
|
import com.dsasp.server.common.util.UserSession;
|
||||||
import com.dsasp.server.common.exception.PrivilegeException;
|
import com.dsasp.server.common.exception.PrivilegeException;
|
||||||
import com.eip4.platform.metadata.flow.UserColumnResolver;
|
import com.eip4.platform.metadata.flow.UserColumnResolver;
|
||||||
import com.eip4.platform.metadata.security.IdentifierWhitelist;
|
import com.eip4.platform.metadata.security.IdentifierWhitelist;
|
||||||
@@ -319,6 +320,38 @@ class PickerControllerTest {
|
|||||||
assertTrue(roles.contains("role-a") && roles.contains("role-b"));
|
assertTrue(roles.contains("role-a") && roles.contains("role-b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("6b. P0:JWT 身份权威 → 忽略客户端 asUser/roles 冒充提权(EntityController 孪生修复)")
|
||||||
|
void jwtIdentityOverridesClientAsUser() {
|
||||||
|
POJOCRUDService engine = mock(POJOCRUDService.class);
|
||||||
|
DataDicService dic = mock(DataDicService.class);
|
||||||
|
IdentifierWhitelist wl = mock(IdentifierWhitelist.class);
|
||||||
|
when(dic.getReferenceEntityTableName(REF_ID)).thenReturn(TABLE);
|
||||||
|
when(engine.listSelect(any(), eq(TABLE), any(Properties.class))).thenReturn(engineResult());
|
||||||
|
seedPoInfoCache(TABLE, fakeInfo());
|
||||||
|
PickerController c = new PickerController(engine, dic, wl, emptyTemplateJdbc(),
|
||||||
|
new UserColumnResolver(emptyTemplateJdbc()));
|
||||||
|
|
||||||
|
// 模拟 JwtAuthFilter 已绑定真实用户 userA 到引擎上下文
|
||||||
|
Properties jwtBound = new Properties();
|
||||||
|
jwtBound.setProperty(LoggedInUser.CURRENTUSER, "userA");
|
||||||
|
UserSession.set(jwtBound);
|
||||||
|
try {
|
||||||
|
// 攻击:已认证 userA 经 picker 传 asUser=victim&roles=ADMIN 试图冒充提权
|
||||||
|
c.list(REF_ID, null, 1, 20, null, null, null, "victim", "ADMIN", null, null, null);
|
||||||
|
|
||||||
|
ArgumentCaptor<Properties> ctxCap = ArgumentCaptor.forClass(Properties.class);
|
||||||
|
verify(engine).listSelect(any(), eq(TABLE), ctxCap.capture());
|
||||||
|
Properties ctx = ctxCap.getValue();
|
||||||
|
assertEquals("userA", ctx.getProperty(LoggedInUser.CURRENTUSER),
|
||||||
|
"必须以 JWT 身份 userA 为准,绝不采用客户端 asUser=victim");
|
||||||
|
assertFalse(ctx.containsKey(LoggedInUser.ROLES),
|
||||||
|
"客户端 roles=ADMIN 必须被忽略,不得注入 ADMIN 角色");
|
||||||
|
} finally {
|
||||||
|
UserSession.remove(); // 防 ThreadLocal 泄漏污染同线程其余用例
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("7. 引用实体无主键 → 拒绝作选择窗数据源(400)")
|
@DisplayName("7. 引用实体无主键 → 拒绝作选择窗数据源(400)")
|
||||||
void rejectsEntityWithoutKey() {
|
void rejectsEntityWithoutKey() {
|
||||||
|
|||||||
@@ -1,169 +1,28 @@
|
|||||||
package com.eip4.platform.metadata.web;
|
package com.eip4.platform.metadata.web;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.io.TempDir;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
import com.eip4.platform.metadata.flow.EnumDisplayResolver;
|
|
||||||
import com.eip4.platform.metadata.script.RewrittenScriptStore;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* P4-5 单测:改写后脚本挂回执行端点(/api/script/execute-template)。
|
* 开发/调试脚本执行端点单测(/api/script/execute,执行请求体里的任意脚本)。
|
||||||
*
|
*
|
||||||
* <p>构造一个落盘的改写后脚本(templateId/seq 命名 + 头注释块),经端点取出去头执行,
|
* <p>P0 拆分(2026-06-24 架构评审)后,本控制器 {@code @Profile(SecurityProfiles.BYPASS)}
|
||||||
* 断言返回 amis 事件动作指令数组(actionType/componentId/args),是「改写后脚本挂回」取数→
|
* 仅 dev/local/ci/parity 装配,生产不可达;改写后脚本「生产重放」端点已迁至
|
||||||
* 执行→指令产出的端到端单测(脚本经保真层引擎真实跑通,非桩)。
|
* {@link ScriptReplayController}(见 {@code ScriptReplayControllerTest})。
|
||||||
*/
|
*/
|
||||||
class ScriptExecuteControllerTest {
|
class ScriptExecuteControllerTest {
|
||||||
|
|
||||||
private ScriptExecuteController controller(Path root) {
|
|
||||||
return new ScriptExecuteController(mock(JdbcTemplate.class), new RewrittenScriptStore(root.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeScript(Path root, String tid, String fileName, String content) throws IOException {
|
|
||||||
Path dir = root.resolve(tid);
|
|
||||||
Files.createDirectories(dir);
|
|
||||||
Files.writeString(dir.resolve(fileName), content, StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
void executeTemplateRewritten_取改写脚本执行产出amis指令(@TempDir Path root) throws IOException {
|
void execute_直接执行脚本仍可用() {
|
||||||
// 福利保险结算单 seq=1:setFieldVisible("BEGINDATE", false) → hidden
|
ScriptExecuteController c = new ScriptExecuteController(mock(JdbcTemplate.class));
|
||||||
writeScript(root, "0d9eac07", "1.FULL_AUTO.groovy",
|
|
||||||
"// === EIP4 P4 脚本迁移产出 ===\n// seq : 1\n\nsetFieldVisible(\"BEGINDATE\", false);");
|
|
||||||
ScriptExecuteController c = controller(root);
|
|
||||||
|
|
||||||
Map<String, Object> body = new LinkedHashMap<>();
|
|
||||||
body.put("templateId", "0d9eac07");
|
|
||||||
body.put("seq", 1);
|
|
||||||
body.put("item", new LinkedHashMap<>());
|
|
||||||
Map<String, Object> resp = c.executeTemplateRewritten(body);
|
|
||||||
|
|
||||||
assertEquals(Boolean.TRUE, resp.get("passed"));
|
|
||||||
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
|
||||||
assertEquals(1, cmds.size());
|
|
||||||
assertEquals("hidden", cmds.get(0).get("actionType"));
|
|
||||||
assertEquals("BEGINDATE", cmds.get(0).get("componentId"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
|
||||||
void executeTemplateRewritten_服务端语义动词从item求值并联动(@TempDir Path root) throws IOException {
|
|
||||||
// 办公用品领用申请 seq=2:addSubTableButton + bindField(getFieldValue("STORE_ID"))
|
|
||||||
writeScript(root, "021e3ba7", "2.FULL_AUTO.groovy",
|
|
||||||
"// header\naddSubTableButton(\"GOODSDETAIL\", \"SELECT\", 0);\n"
|
|
||||||
+ "bindField(\"OLD_STORE_ID\",getFieldValue(\"STORE_ID\"));");
|
|
||||||
ScriptExecuteController c = controller(root);
|
|
||||||
|
|
||||||
Map<String, Object> item = new LinkedHashMap<>();
|
|
||||||
item.put("STORE_ID", "S-99");
|
|
||||||
Map<String, Object> body = new LinkedHashMap<>();
|
|
||||||
body.put("templateId", "021e3ba7");
|
|
||||||
body.put("seq", "2"); // 字符串 seq 也能解析
|
|
||||||
body.put("item", item);
|
|
||||||
Map<String, Object> resp = c.executeTemplateRewritten(body);
|
|
||||||
|
|
||||||
assertEquals(Boolean.TRUE, resp.get("passed"));
|
|
||||||
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
|
||||||
assertEquals(2, cmds.size());
|
|
||||||
assertEquals("addSubTableButton", cmds.get(0).get("actionType"));
|
|
||||||
Map<String, Object> setValue = cmds.get(1);
|
|
||||||
assertEquals("setValue", setValue.get("actionType"));
|
|
||||||
assertEquals("OLD_STORE_ID", setValue.get("componentId"));
|
|
||||||
Map<String, Object> args = (Map<String, Object>) setValue.get("args");
|
|
||||||
assertEquals("S-99", args.get("value")); // getFieldValue 从 item 求值闭环
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 缺 templateId 是真错 → passed=false + error(保留)。 */
|
|
||||||
@Test
|
|
||||||
void executeTemplateRewritten_缺templateId时passed为false(@TempDir Path root) {
|
|
||||||
ScriptExecuteController c = controller(root);
|
|
||||||
|
|
||||||
Map<String, Object> noTid = new LinkedHashMap<>();
|
|
||||||
Map<String, Object> r1 = c.executeTemplateRewritten(noTid);
|
|
||||||
assertEquals(Boolean.FALSE, r1.get("passed"));
|
|
||||||
assertNotNull(r1.get("error"));
|
|
||||||
assertTrue(((String) r1.get("error")).contains("templateId"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** WS-B C1-b:脚本未找到(残余缺脚本/seq 偏差)退化为 no-op(passed=true + 空 commands),不报 ajax 错。 */
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
|
||||||
void executeTemplateRewritten_脚本未找到时退化为noop(@TempDir Path root) {
|
|
||||||
ScriptExecuteController c = controller(root);
|
|
||||||
|
|
||||||
Map<String, Object> missing = new LinkedHashMap<>();
|
|
||||||
missing.put("templateId", "no-such");
|
|
||||||
missing.put("seq", 1);
|
|
||||||
Map<String, Object> r2 = c.executeTemplateRewritten(missing);
|
|
||||||
assertEquals(Boolean.TRUE, r2.get("passed")); // no-op,非用户可见报错
|
|
||||||
assertNull(r2.get("error")); // 不再返 error
|
|
||||||
List<Map<String, Object>> cmds = (List<Map<String, Object>>) r2.get("commands");
|
|
||||||
assertTrue(cmds.isEmpty()); // 空 commands → 前端无动作可重放
|
|
||||||
assertEquals(0, r2.get("commandCount"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 小修#2:执行前 item 枚举裸码 → 显示串,使 onselectedscript 里 {@code item['ISPLACE'] == "未归档"}
|
|
||||||
* 成立 → 触发 enableButton("文件归档", true)。复刻新闻 ddb75614 文件归档永不点亮根因的修复闭环。
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
|
||||||
void executeTemplateRewritten_枚举显示值注入使按钮点亮(@TempDir Path root) throws IOException {
|
|
||||||
// 复刻新闻 seq1 文件归档分支:item['ISPLACE'] 是显示串时点亮文件归档
|
|
||||||
writeScript(root, "ddb75614", "1.NO_S3.groovy",
|
|
||||||
"if (item['ISPLACE'] == \"未归档\") enableButton(\"文件归档\", true);");
|
|
||||||
|
|
||||||
// 桩 jdbc:ISPLACE→SYS_FILINGUP_STATUS,code 0→未归档
|
|
||||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
|
||||||
org.mockito.Mockito.lenient().when(jdbc.queryForList(
|
|
||||||
org.mockito.ArgumentMatchers.contains("sys_entityattribute"),
|
|
||||||
org.mockito.ArgumentMatchers.eq("OA_NEWSMANAGE")))
|
|
||||||
.thenReturn(List.of(Map.of("col", "ISPLACE", "etype", "SYS_FILINGUP_STATUS")));
|
|
||||||
org.mockito.Mockito.lenient().when(jdbc.queryForList(
|
|
||||||
org.mockito.ArgumentMatchers.contains("sys_enumerate"),
|
|
||||||
org.mockito.ArgumentMatchers.eq("SYS_FILINGUP_STATUS")))
|
|
||||||
.thenReturn(List.of(Map.of("codevalue", 0, "codedes", "未归档")));
|
|
||||||
|
|
||||||
ScriptExecuteController c = new ScriptExecuteController(
|
|
||||||
jdbc, new RewrittenScriptStore(root.toString()), new EnumDisplayResolver(jdbc));
|
|
||||||
|
|
||||||
Map<String, Object> item = new LinkedHashMap<>();
|
|
||||||
item.put("OA_NEWSMANAGE_ID", "row-1");
|
|
||||||
item.put("ISPLACE", 0); // 裸码(_SEARCH 合成流平展的真实形态)
|
|
||||||
Map<String, Object> body = new LinkedHashMap<>();
|
|
||||||
body.put("templateId", "ddb75614");
|
|
||||||
body.put("seq", 1);
|
|
||||||
body.put("item", item);
|
|
||||||
|
|
||||||
Map<String, Object> resp = c.executeTemplateRewritten(body);
|
|
||||||
assertEquals(Boolean.TRUE, resp.get("passed"));
|
|
||||||
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
|
||||||
assertEquals(1, cmds.size(), "ISPLACE 富化为「未归档」→ 文件归档点亮 enable 指令");
|
|
||||||
assertEquals("文件归档", cmds.get(0).get("componentId"));
|
|
||||||
assertEquals("enabled", cmds.get(0).get("actionType"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
|
||||||
void execute_直接执行脚本仍可用(@TempDir Path root) {
|
|
||||||
ScriptExecuteController c = controller(root);
|
|
||||||
Map<String, Object> body = new LinkedHashMap<>();
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
body.put("script", "showToast(\"ok\");");
|
body.put("script", "showToast(\"ok\");");
|
||||||
body.put("item", new LinkedHashMap<>());
|
body.put("item", new LinkedHashMap<>());
|
||||||
@@ -172,4 +31,12 @@ class ScriptExecuteControllerTest {
|
|||||||
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
||||||
assertEquals("toast", cmds.get(0).get("actionType"));
|
assertEquals("toast", cmds.get(0).get("actionType"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void execute_缺script时passed为false() {
|
||||||
|
ScriptExecuteController c = new ScriptExecuteController(mock(JdbcTemplate.class));
|
||||||
|
Map<String, Object> resp = c.execute(new LinkedHashMap<>());
|
||||||
|
assertEquals(Boolean.FALSE, resp.get("passed"));
|
||||||
|
assertEquals("缺少 script", resp.get("error"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
package com.eip4.platform.metadata.web;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import com.eip4.platform.metadata.flow.EnumDisplayResolver;
|
||||||
|
import com.eip4.platform.metadata.script.RewrittenScriptStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* P4-5 单测:改写后脚本挂回执行端点(/api/script/execute-template),P0 拆分后落在生产可装配的
|
||||||
|
* {@link ScriptReplayController}(脚本只取自脚本库内已审产物,非请求体,故随生产 jar 装配)。
|
||||||
|
*
|
||||||
|
* <p>构造一个落盘的改写后脚本(templateId/seq 命名 + 头注释块),经端点取出去头执行,
|
||||||
|
* 断言返回 amis 事件动作指令数组(脚本经保真层引擎真实跑通,非桩)。
|
||||||
|
*/
|
||||||
|
class ScriptReplayControllerTest {
|
||||||
|
|
||||||
|
private ScriptReplayController controller(Path root) {
|
||||||
|
return new ScriptReplayController(new RewrittenScriptStore(root.toString()),
|
||||||
|
new EnumDisplayResolver(mock(JdbcTemplate.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeScript(Path root, String tid, String fileName, String content) throws IOException {
|
||||||
|
Path dir = root.resolve(tid);
|
||||||
|
Files.createDirectories(dir);
|
||||||
|
Files.writeString(dir.resolve(fileName), content, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
void executeTemplateRewritten_取改写脚本执行产出amis指令(@TempDir Path root) throws IOException {
|
||||||
|
writeScript(root, "0d9eac07", "1.FULL_AUTO.groovy",
|
||||||
|
"// === EIP4 P4 脚本迁移产出 ===\n// seq : 1\n\nsetFieldVisible(\"BEGINDATE\", false);");
|
||||||
|
ScriptReplayController c = controller(root);
|
||||||
|
|
||||||
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
|
body.put("templateId", "0d9eac07");
|
||||||
|
body.put("seq", 1);
|
||||||
|
body.put("item", new LinkedHashMap<>());
|
||||||
|
Map<String, Object> resp = c.executeTemplateRewritten(body);
|
||||||
|
|
||||||
|
assertEquals(Boolean.TRUE, resp.get("passed"));
|
||||||
|
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
||||||
|
assertEquals(1, cmds.size());
|
||||||
|
assertEquals("hidden", cmds.get(0).get("actionType"));
|
||||||
|
assertEquals("BEGINDATE", cmds.get(0).get("componentId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
void executeTemplateRewritten_服务端语义动词从item求值并联动(@TempDir Path root) throws IOException {
|
||||||
|
writeScript(root, "021e3ba7", "2.FULL_AUTO.groovy",
|
||||||
|
"// header\naddSubTableButton(\"GOODSDETAIL\", \"SELECT\", 0);\n"
|
||||||
|
+ "bindField(\"OLD_STORE_ID\",getFieldValue(\"STORE_ID\"));");
|
||||||
|
ScriptReplayController c = controller(root);
|
||||||
|
|
||||||
|
Map<String, Object> item = new LinkedHashMap<>();
|
||||||
|
item.put("STORE_ID", "S-99");
|
||||||
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
|
body.put("templateId", "021e3ba7");
|
||||||
|
body.put("seq", "2"); // 字符串 seq 也能解析
|
||||||
|
body.put("item", item);
|
||||||
|
Map<String, Object> resp = c.executeTemplateRewritten(body);
|
||||||
|
|
||||||
|
assertEquals(Boolean.TRUE, resp.get("passed"));
|
||||||
|
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
||||||
|
assertEquals(2, cmds.size());
|
||||||
|
assertEquals("addSubTableButton", cmds.get(0).get("actionType"));
|
||||||
|
Map<String, Object> setValue = cmds.get(1);
|
||||||
|
assertEquals("setValue", setValue.get("actionType"));
|
||||||
|
assertEquals("OLD_STORE_ID", setValue.get("componentId"));
|
||||||
|
Map<String, Object> args = (Map<String, Object>) setValue.get("args");
|
||||||
|
assertEquals("S-99", args.get("value")); // getFieldValue 从 item 求值闭环
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 缺 templateId 是真错 → passed=false + error(保留)。 */
|
||||||
|
@Test
|
||||||
|
void executeTemplateRewritten_缺templateId时passed为false(@TempDir Path root) {
|
||||||
|
ScriptReplayController c = controller(root);
|
||||||
|
|
||||||
|
Map<String, Object> noTid = new LinkedHashMap<>();
|
||||||
|
Map<String, Object> r1 = c.executeTemplateRewritten(noTid);
|
||||||
|
assertEquals(Boolean.FALSE, r1.get("passed"));
|
||||||
|
assertNotNull(r1.get("error"));
|
||||||
|
assertTrue(((String) r1.get("error")).contains("templateId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** WS-B C1-b:脚本未找到退化为 no-op(passed=true + 空 commands),不报 ajax 错。 */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
void executeTemplateRewritten_脚本未找到时退化为noop(@TempDir Path root) {
|
||||||
|
ScriptReplayController c = controller(root);
|
||||||
|
|
||||||
|
Map<String, Object> missing = new LinkedHashMap<>();
|
||||||
|
missing.put("templateId", "no-such");
|
||||||
|
missing.put("seq", 1);
|
||||||
|
Map<String, Object> r2 = c.executeTemplateRewritten(missing);
|
||||||
|
assertEquals(Boolean.TRUE, r2.get("passed"));
|
||||||
|
assertNull(r2.get("error"));
|
||||||
|
List<Map<String, Object>> cmds = (List<Map<String, Object>>) r2.get("commands");
|
||||||
|
assertTrue(cmds.isEmpty());
|
||||||
|
assertEquals(0, r2.get("commandCount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* P0:路径穿越的 templateId 不得读取脚本库外文件 → 退化 no-op(RewrittenScriptStore 包含校验)。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
void executeTemplateRewritten_路径穿越templateId退化noop(@TempDir Path tmp) throws IOException {
|
||||||
|
Path root = tmp.resolve("rewritten");
|
||||||
|
Files.createDirectories(root);
|
||||||
|
// 在 root 之外落一个恶意脚本目录
|
||||||
|
Path outsideDir = tmp.resolve("evil");
|
||||||
|
Files.createDirectories(outsideDir);
|
||||||
|
Files.writeString(outsideDir.resolve("1.x.groovy"), "showToast(\"pwned\");", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
ScriptReplayController c = new ScriptReplayController(
|
||||||
|
new RewrittenScriptStore(root.toString()), new EnumDisplayResolver(mock(JdbcTemplate.class)));
|
||||||
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
|
body.put("templateId", "../evil"); // 试图穿越出脚本库根
|
||||||
|
body.put("seq", 1);
|
||||||
|
body.put("item", new LinkedHashMap<>());
|
||||||
|
Map<String, Object> resp = c.executeTemplateRewritten(body);
|
||||||
|
|
||||||
|
assertEquals(Boolean.TRUE, resp.get("passed")); // no-op(脚本未找到)
|
||||||
|
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
||||||
|
assertTrue(cmds.isEmpty(), "穿越 templateId 必须读不到库外脚本,不得执行");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行前 item 枚举裸码 → 显示串,使 onselectedscript 里 {@code item['ISPLACE'] == "未归档"} 成立。
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
void executeTemplateRewritten_枚举显示值注入使按钮点亮(@TempDir Path root) throws IOException {
|
||||||
|
writeScript(root, "ddb75614", "1.NO_S3.groovy",
|
||||||
|
"if (item['ISPLACE'] == \"未归档\") enableButton(\"文件归档\", true);");
|
||||||
|
|
||||||
|
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||||
|
org.mockito.Mockito.lenient().when(jdbc.queryForList(
|
||||||
|
org.mockito.ArgumentMatchers.contains("sys_entityattribute"),
|
||||||
|
org.mockito.ArgumentMatchers.eq("OA_NEWSMANAGE")))
|
||||||
|
.thenReturn(List.of(Map.of("col", "ISPLACE", "etype", "SYS_FILINGUP_STATUS")));
|
||||||
|
org.mockito.Mockito.lenient().when(jdbc.queryForList(
|
||||||
|
org.mockito.ArgumentMatchers.contains("sys_enumerate"),
|
||||||
|
org.mockito.ArgumentMatchers.eq("SYS_FILINGUP_STATUS")))
|
||||||
|
.thenReturn(List.of(Map.of("codevalue", 0, "codedes", "未归档")));
|
||||||
|
|
||||||
|
ScriptReplayController c = new ScriptReplayController(
|
||||||
|
new RewrittenScriptStore(root.toString()), new EnumDisplayResolver(jdbc));
|
||||||
|
|
||||||
|
Map<String, Object> item = new LinkedHashMap<>();
|
||||||
|
item.put("OA_NEWSMANAGE_ID", "row-1");
|
||||||
|
item.put("ISPLACE", 0); // 裸码
|
||||||
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
|
body.put("templateId", "ddb75614");
|
||||||
|
body.put("seq", 1);
|
||||||
|
body.put("item", item);
|
||||||
|
|
||||||
|
Map<String, Object> resp = c.executeTemplateRewritten(body);
|
||||||
|
assertEquals(Boolean.TRUE, resp.get("passed"));
|
||||||
|
List<Map<String, Object>> cmds = (List<Map<String, Object>>) resp.get("commands");
|
||||||
|
assertEquals(1, cmds.size(), "ISPLACE 富化为「未归档」→ 文件归档点亮 enable 指令");
|
||||||
|
assertEquals("文件归档", cmds.get(0).get("componentId"));
|
||||||
|
assertEquals("enabled", cmds.get(0).get("actionType"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,11 @@ psql -h "$CI_PG_HOST" -p "$CI_PG_PORT" -U "$CI_PG_USER" -d "$CI_DB" -q \
|
|||||||
|
|
||||||
JDBC="jdbc:postgresql://${CI_PG_HOST}:${CI_PG_PORT}/${CI_DB}"
|
JDBC="jdbc:postgresql://${CI_PG_HOST}:${CI_PG_PORT}/${CI_DB}"
|
||||||
echo "==[3/4] 起服务(:${CI_PORT} → ${JDBC})=="
|
echo "==[3/4] 起服务(:${CI_PORT} → ${JDBC})=="
|
||||||
|
# profile=ci:对拍冒烟依赖免令牌 permitAll + asUser/roles 旁路(见 SecurityProfiles)。
|
||||||
|
# P0 fail-safe 修复后默认严格链(无 profile=强制认证),故 CI 必须显式声明 ci profile,
|
||||||
|
# 否则健康检查 /api/entity/... 被拒 401、ParityCli 免令牌重放失效。
|
||||||
java -jar platform-app/target/platform-app-*.jar \
|
java -jar platform-app/target/platform-app-*.jar \
|
||||||
|
--spring.profiles.active=ci \
|
||||||
--server.port="$CI_PORT" \
|
--server.port="$CI_PORT" \
|
||||||
--spring.datasource.url="$JDBC" \
|
--spring.datasource.url="$JDBC" \
|
||||||
--spring.datasource.username="$CI_PG_USER" \
|
--spring.datasource.username="$CI_PG_USER" \
|
||||||
|
|||||||
Reference in New Issue
Block a user