test(parity): C2 数据行级权限自举 + 对拍样本(3 实体×3 用户 100% + 负例)
自举 + 对拍证明保真层数据权限真实现与物理事实逐行对齐:
- bootstrap-privilege.sql(幂等):建 SYS_FILTERRULE + 中间表 SYS_FILTERRULEROLE
(LIST 多值列经 REFERENCEVALUE→中间表落地)+ 自描述元数据;为 EIP4PT_TASK/
PROJECT/CUSTOMER 各配 1 条 "CREATEBY = {CURRENTUSERID}" 规则,并把 CREATEBY
重分区到 USER_ALICE/BOB/CAROL 使过滤可判别。
- ParityCli 增 --privilege 模式 + PrivilegeCheckRunner:被测侧经引擎
GET /list?asUser&roles 触发行级过滤,基线侧 JDBC 同语义 WHERE,RowDiff 逐行比。
- EngineHttpClient 增 asUser/roles 透传 + statusOf(负例取状态码)。
- EntityController.list 增可选 asUser/roles 构造非 ADMIN ctx(引擎仅非 ADMIN 才过滤)。
实测:正例 3 实体×3 用户=9 例 150 行 100% 逐行一致;负例错误角色 3/3 抛
PrivilegeException(HTTP 500)被拒;回归 ParityCli --all 21/21、1108 行 100%。
报告:platform-auth/C2实测报告.md + parity-reports/privilege-parity-*.{json,md}。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
262
platform-parity/parity-reports/parity-20260611-000638.json
Normal file
262
platform-parity/parity-reports/parity-20260611-000638.json
Normal file
@@ -0,0 +1,262 @@
|
||||
{
|
||||
"summary" : {
|
||||
"entityCount" : 21,
|
||||
"cleanEntities" : 21,
|
||||
"totalRows" : 1108,
|
||||
"entityConsistencyRate" : 1.0,
|
||||
"allClean" : true
|
||||
},
|
||||
"reports" : [ {
|
||||
"label" : "EIP4PT_ALLTYPE",
|
||||
"keyColumns" : [ "EIP4PT_ALLTYPE_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_ASSET",
|
||||
"keyColumns" : [ "EIP4PT_ASSET_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_COMBO",
|
||||
"keyColumns" : [ "EIP4PT_COMBO_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_CONFIG",
|
||||
"keyColumns" : [ "EIP4PT_CONFIG_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_CONTRACT",
|
||||
"keyColumns" : [ "EIP4PT_CONTRACT_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_CUSTOMER",
|
||||
"keyColumns" : [ "EIP4PT_CUSTOMER_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_DEPT",
|
||||
"keyColumns" : [ "EIP4PT_DEPT_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_DEVICE",
|
||||
"keyColumns" : [ "EIP4PT_DEVICE_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_EMPLOYEE",
|
||||
"keyColumns" : [ "EIP4PT_EMPLOYEE_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_INVOICE",
|
||||
"keyColumns" : [ "EIP4PT_INVOICE_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_LOG",
|
||||
"keyColumns" : [ "EIP4PT_LOG_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_ORDER",
|
||||
"keyColumns" : [ "EIP4PT_ORDER_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_ORDERLINE",
|
||||
"keyColumns" : [ "EIP4PT_ORDERLINE_ID" ],
|
||||
"leftRowCount" : 108,
|
||||
"rightRowCount" : 108,
|
||||
"matchedRows" : 108,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_PAYMENT",
|
||||
"keyColumns" : [ "EIP4PT_PAYMENT_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_PRODUCT",
|
||||
"keyColumns" : [ "EIP4PT_PRODUCT_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_PROJECT",
|
||||
"keyColumns" : [ "EIP4PT_PROJECT_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_REFER",
|
||||
"keyColumns" : [ "EIP4PT_REFER_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_STOCK",
|
||||
"keyColumns" : [ "EIP4PT_STOCK_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_SUPPLIER",
|
||||
"keyColumns" : [ "EIP4PT_SUPPLIER_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_TASK",
|
||||
"keyColumns" : [ "EIP4PT_TASK_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_WAREHOUSE",
|
||||
"keyColumns" : [ "EIP4PT_WAREHOUSE_ID" ],
|
||||
"leftRowCount" : 50,
|
||||
"rightRowCount" : 50,
|
||||
"matchedRows" : 50,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
} ]
|
||||
}
|
||||
31
platform-parity/parity-reports/parity-20260611-000638.md
Normal file
31
platform-parity/parity-reports/parity-20260611-000638.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# C1 自对拍报告
|
||||
|
||||
- 实体数: 21
|
||||
- 全一致实体: 21
|
||||
- 总比对行数(JDBC 基线侧): 1108
|
||||
- 实体级一致率: 1.0000 ✅ 全部逐行一致
|
||||
|
||||
| 实体 | 行数 | 内容差异行 | 仅JDBC | 仅引擎 | 逐行一致率 | 结果 |
|
||||
|---|---|---|---|---|---|---|
|
||||
| EIP4PT_ALLTYPE | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_ASSET | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_COMBO | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_CONFIG | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_CONTRACT | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_CUSTOMER | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_DEPT | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_DEVICE | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_EMPLOYEE | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_INVOICE | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_LOG | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_ORDER | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_ORDERLINE | 108 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_PAYMENT | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_PRODUCT | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_PROJECT | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_REFER | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_STOCK | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_SUPPLIER | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_TASK | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_WAREHOUSE | 50 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
{
|
||||
"summary" : {
|
||||
"mode" : "privilege",
|
||||
"positiveCases" : 9,
|
||||
"positiveClean" : 9,
|
||||
"totalRows" : 150,
|
||||
"positiveConsistencyRate" : 1.0,
|
||||
"negativeStatus" : {
|
||||
"EIP4PT_CUSTOMER" : 500,
|
||||
"EIP4PT_PROJECT" : 500,
|
||||
"EIP4PT_TASK" : 500
|
||||
},
|
||||
"allNegativeRejected" : true,
|
||||
"allPass" : true
|
||||
},
|
||||
"positive" : [ {
|
||||
"label" : "EIP4PT_CUSTOMER[USER_ALICE]",
|
||||
"keyColumns" : [ "EIP4PT_CUSTOMER_ID" ],
|
||||
"leftRowCount" : 16,
|
||||
"rightRowCount" : 16,
|
||||
"matchedRows" : 16,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_CUSTOMER[USER_BOB]",
|
||||
"keyColumns" : [ "EIP4PT_CUSTOMER_ID" ],
|
||||
"leftRowCount" : 17,
|
||||
"rightRowCount" : 17,
|
||||
"matchedRows" : 17,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_CUSTOMER[USER_CAROL]",
|
||||
"keyColumns" : [ "EIP4PT_CUSTOMER_ID" ],
|
||||
"leftRowCount" : 17,
|
||||
"rightRowCount" : 17,
|
||||
"matchedRows" : 17,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_PROJECT[USER_ALICE]",
|
||||
"keyColumns" : [ "EIP4PT_PROJECT_ID" ],
|
||||
"leftRowCount" : 16,
|
||||
"rightRowCount" : 16,
|
||||
"matchedRows" : 16,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_PROJECT[USER_BOB]",
|
||||
"keyColumns" : [ "EIP4PT_PROJECT_ID" ],
|
||||
"leftRowCount" : 17,
|
||||
"rightRowCount" : 17,
|
||||
"matchedRows" : 17,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_PROJECT[USER_CAROL]",
|
||||
"keyColumns" : [ "EIP4PT_PROJECT_ID" ],
|
||||
"leftRowCount" : 17,
|
||||
"rightRowCount" : 17,
|
||||
"matchedRows" : 17,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_TASK[USER_ALICE]",
|
||||
"keyColumns" : [ "EIP4PT_TASK_ID" ],
|
||||
"leftRowCount" : 16,
|
||||
"rightRowCount" : 16,
|
||||
"matchedRows" : 16,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_TASK[USER_BOB]",
|
||||
"keyColumns" : [ "EIP4PT_TASK_ID" ],
|
||||
"leftRowCount" : 17,
|
||||
"rightRowCount" : 17,
|
||||
"matchedRows" : 17,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
}, {
|
||||
"label" : "EIP4PT_TASK[USER_CAROL]",
|
||||
"keyColumns" : [ "EIP4PT_TASK_ID" ],
|
||||
"leftRowCount" : 17,
|
||||
"rightRowCount" : 17,
|
||||
"matchedRows" : 17,
|
||||
"mismatchRows" : 0,
|
||||
"onlyInLeft" : [ ],
|
||||
"onlyInRight" : [ ],
|
||||
"clean" : true,
|
||||
"consistencyRate" : 1.0,
|
||||
"mismatches" : [ ]
|
||||
} ]
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
# C2 数据行级权限对拍报告
|
||||
|
||||
- 正例(受控实体 × 用户): 9,全一致: 9
|
||||
- 总比对行数(JDBC 基线侧): 150
|
||||
- 正例逐行一致率: 1.0000 ✅ 全部逐行一致
|
||||
- 负例(错误角色被拒): ✅ 全部被拒
|
||||
|
||||
## 正例:引擎行级过滤 vs JDBC 同语义基线
|
||||
|
||||
| 实体[用户] | 行数 | 内容差异 | 仅JDBC | 仅引擎 | 一致率 | 结果 |
|
||||
|---|---|---|---|---|---|---|
|
||||
| EIP4PT_CUSTOMER[USER_ALICE] | 16 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_CUSTOMER[USER_BOB] | 17 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_CUSTOMER[USER_CAROL] | 17 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_PROJECT[USER_ALICE] | 16 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_PROJECT[USER_BOB] | 17 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_PROJECT[USER_CAROL] | 17 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_TASK[USER_ALICE] | 16 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_TASK[USER_BOB] | 17 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
| EIP4PT_TASK[USER_CAROL] | 17 | 0 | 0 | 0 | 1.0000 | ✅ |
|
||||
|
||||
## 负例:错误角色 ROLE_NOBODY 访问受控实体
|
||||
|
||||
| 实体 | HTTP 状态 | 期望 | 结果 |
|
||||
|---|---|---|---|
|
||||
| EIP4PT_CUSTOMER | 500 | 非200(PrivilegeException) | ✅ 被拒 |
|
||||
| EIP4PT_PROJECT | 500 | 非200(PrivilegeException) | ✅ 被拒 |
|
||||
| EIP4PT_TASK | 500 | 非200(PrivilegeException) | ✅ 被拒 |
|
||||
|
||||
@@ -41,11 +41,19 @@ public class EngineHttpClient {
|
||||
|
||||
/** 抓某实体全量行(自动翻页直到取满 total)。 */
|
||||
public List<Map<String, Object>> listAll(String table) throws Exception {
|
||||
return listAll(table, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 抓某实体全量行,附加查询串(C2 数据权限用:{@code asUser=...&roles=...} 构造非 ADMIN ctx,
|
||||
* 触发引擎行级过滤)。{@code extraQuery} 不含前导 {@code &}。
|
||||
*/
|
||||
public List<Map<String, Object>> listAll(String table, String extraQuery) throws Exception {
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
int page = 1;
|
||||
long total = -1;
|
||||
while (true) {
|
||||
JsonNode data = getList(table, page, perPage);
|
||||
JsonNode data = getList(table, page, perPage, extraQuery);
|
||||
JsonNode items = data.get("items");
|
||||
if (items != null && items.isArray()) {
|
||||
for (JsonNode item : items) {
|
||||
@@ -69,12 +77,13 @@ public class EngineHttpClient {
|
||||
|
||||
/** 取某实体 total(引擎 PAGE_COUNT)。 */
|
||||
public long total(String table) throws Exception {
|
||||
JsonNode data = getList(table, 1, 1);
|
||||
JsonNode data = getList(table, 1, 1, "");
|
||||
return data.has("total") ? data.get("total").asLong() : 0;
|
||||
}
|
||||
|
||||
private JsonNode getList(String table, int page, int size) throws Exception {
|
||||
String url = baseUrl + "/api/entity/" + table + "/list?page=" + page + "&perPage=" + size;
|
||||
private JsonNode getList(String table, int page, int size, String extraQuery) throws Exception {
|
||||
String url = baseUrl + "/api/entity/" + table + "/list?page=" + page + "&perPage=" + size
|
||||
+ (extraQuery == null || extraQuery.isBlank() ? "" : "&" + extraQuery);
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(url))
|
||||
.timeout(Duration.ofSeconds(60)).GET().build();
|
||||
HttpResponse<String> resp = http.send(req, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
|
||||
@@ -90,6 +99,19 @@ public class EngineHttpClient {
|
||||
return root.path("data");
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅取 HTTP 状态码(C2 负例断言用:无命中角色 → 引擎抛 PrivilegeException → 非 200)。
|
||||
* 返回状态码,不解析 body。
|
||||
*/
|
||||
public int statusOf(String table, String extraQuery) throws Exception {
|
||||
String url = baseUrl + "/api/entity/" + table + "/list?page=1&perPage=1"
|
||||
+ (extraQuery == null || extraQuery.isBlank() ? "" : "&" + extraQuery);
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(url))
|
||||
.timeout(Duration.ofSeconds(60)).GET().build();
|
||||
HttpResponse<String> resp = http.send(req, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
|
||||
return resp.statusCode();
|
||||
}
|
||||
|
||||
private Map<String, Object> jsonToRow(JsonNode item) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
item.fields().forEachRemaining(e -> {
|
||||
|
||||
@@ -24,10 +24,14 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
* java -cp ... com.eip4.platform.parity.selfcheck.ParityCli \
|
||||
* --entities=EIP4PT_ALLTYPE,EIP4PT_ORDER # 或 --all
|
||||
* [--seed] # 先灌种子(建 ≥20 实体 + 每实体 50 行)
|
||||
* [--privilege] # C2 数据行级权限对拍(3 受控实体×3 用户 + 负例)
|
||||
* [--jdbc=jdbc:postgresql://localhost:5433/eip4m0] [--user=zhengwr] [--pass=]
|
||||
* [--engine=http://localhost:8084] [--out=parity-reports]
|
||||
* }</pre>
|
||||
*
|
||||
* <p>{@code --privilege} 前置条件:已跑 bootstrap-privilege.sql(建 SYS_FILTERRULE/中间表 +
|
||||
* 为 EIP4PT_TASK/PROJECT/CUSTOMER 各配 1 条 {@code CREATEBY = {CURRENTUSERID}} 规则)。
|
||||
*
|
||||
* <p>对每个实体:直连 JDBC SELECT(基线) vs 引擎 REST list(被测) 逐行逐列 diff,
|
||||
* 报告写 {@code parity-reports/parity-YYYYMMDD-HHmmss.json} + {@code .md}。
|
||||
* 退出码:全一致=0,有差异=2,运行错误=1。
|
||||
@@ -49,6 +53,12 @@ public final class ParityCli {
|
||||
SimpleDriverDataSource ds = new SimpleDriverDataSource(
|
||||
new org.postgresql.Driver(), jdbcUrl, user, pass == null ? "" : pass);
|
||||
|
||||
// C2 数据行级权限对拍模式:--privilege
|
||||
if (opt.containsKey("privilege")) {
|
||||
int code = runPrivilege(engine, ds, outDir);
|
||||
System.exit(code);
|
||||
}
|
||||
|
||||
List<String> entities = new ArrayList<>();
|
||||
if (opt.containsKey("seed")) {
|
||||
System.out.println("[seed] 建实体 + 灌数据(固定种子 " + ParitySeeder.SEED + ")...");
|
||||
@@ -100,6 +110,127 @@ public final class ParityCli {
|
||||
System.exit(cleanCount == entities.size() ? 0 : 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* C2 数据行级权限对拍:对 3 个受控实体 × 3 个用户跑正例逐行 diff,并断言负例(错误角色被拒)。
|
||||
* 写 {@code privilege-parity-*.json/.md} 报告。退出码:全一致且负例全部被拒=0,否则=2。
|
||||
*/
|
||||
private static int runPrivilege(String engine, javax.sql.DataSource ds, Path outDir) throws Exception {
|
||||
System.out.println("=== C2 数据行级权限对拍(--privilege)===");
|
||||
PrivilegeCheckRunner runner = new PrivilegeCheckRunner(engine, ds);
|
||||
|
||||
// 正例:引擎过滤 vs JDBC 同语义基线,逐行 diff
|
||||
List<DiffReport> reports = runner.runAllPositive();
|
||||
int cleanCount = 0;
|
||||
long totalRows = 0;
|
||||
for (DiffReport r : reports) {
|
||||
totalRows += r.leftRowCount;
|
||||
boolean clean = r.isClean();
|
||||
if (clean) {
|
||||
cleanCount++;
|
||||
}
|
||||
System.out.printf(" 正例 %-26s 行=%-4d 一致率=%.4f %s%n",
|
||||
r.label, r.leftRowCount, r.consistencyRate(), clean ? "OK" : "DIFF");
|
||||
}
|
||||
|
||||
// 负例:错误角色访问每个受控实体 → 期望 HTTP 非 200(PrivilegeException)
|
||||
List<String> negTables = new ArrayList<>(PrivilegeCheckRunner.CONTROLLED.keySet());
|
||||
negTables.sort(String::compareTo);
|
||||
int negPass = 0;
|
||||
Map<String, Integer> negStatus = new LinkedHashMap<>();
|
||||
for (String t : negTables) {
|
||||
int code = runner.checkNegativeStatus(t, "ROLE_NOBODY");
|
||||
negStatus.put(t, code);
|
||||
boolean rejected = code != 200;
|
||||
if (rejected) {
|
||||
negPass++;
|
||||
}
|
||||
System.out.printf(" 负例 %-26s 错误角色 ROLE_NOBODY → HTTP=%d %s%n",
|
||||
t, code, rejected ? "REJECTED(OK)" : "NOT-REJECTED(FAIL)");
|
||||
}
|
||||
|
||||
boolean allPositiveClean = cleanCount == reports.size();
|
||||
boolean allNegativeRejected = negPass == negTables.size();
|
||||
boolean ok = allPositiveClean && allNegativeRejected;
|
||||
|
||||
String ts = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss"));
|
||||
Path json = outDir.resolve("privilege-parity-" + ts + ".json");
|
||||
Path md = outDir.resolve("privilege-parity-" + ts + ".md");
|
||||
writePrivilegeJson(json, reports, negStatus, cleanCount, totalRows, allNegativeRejected);
|
||||
writePrivilegeMarkdown(md, reports, negStatus, cleanCount, totalRows, allNegativeRejected);
|
||||
|
||||
System.out.println("\n=== C2 汇总 ===");
|
||||
System.out.println("受控实体: " + negTables.size() + " (" + negTables + ")");
|
||||
System.out.println("正例(实体×用户): " + reports.size() + ",全一致: " + cleanCount);
|
||||
System.out.println("总比对行数(JDBC 基线侧): " + totalRows);
|
||||
System.out.println("负例(错误角色被拒): " + negPass + "/" + negTables.size());
|
||||
System.out.println("结果: " + (ok ? "✅ 全部通过" : "⚠️ 存在失败"));
|
||||
System.out.println("报告: " + json + " / " + md);
|
||||
return ok ? 0 : 2;
|
||||
}
|
||||
|
||||
private static void writePrivilegeJson(Path path, List<DiffReport> reports,
|
||||
Map<String, Integer> negStatus, int cleanCount,
|
||||
long totalRows, boolean allNegativeRejected) throws Exception {
|
||||
ObjectMapper m = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
||||
Map<String, Object> root = new LinkedHashMap<>();
|
||||
Map<String, Object> summary = new LinkedHashMap<>();
|
||||
summary.put("mode", "privilege");
|
||||
summary.put("positiveCases", reports.size());
|
||||
summary.put("positiveClean", cleanCount);
|
||||
summary.put("totalRows", totalRows);
|
||||
summary.put("positiveConsistencyRate", reports.isEmpty() ? 1.0 : (double) cleanCount / reports.size());
|
||||
summary.put("negativeStatus", negStatus);
|
||||
summary.put("allNegativeRejected", allNegativeRejected);
|
||||
summary.put("allPass", cleanCount == reports.size() && allNegativeRejected);
|
||||
root.put("summary", summary);
|
||||
List<Map<String, Object>> rs = new ArrayList<>();
|
||||
for (DiffReport r : reports) {
|
||||
rs.add(r.toSummaryMap());
|
||||
}
|
||||
root.put("positive", rs);
|
||||
Files.writeString(path, m.writeValueAsString(root));
|
||||
}
|
||||
|
||||
private static void writePrivilegeMarkdown(Path path, List<DiffReport> reports,
|
||||
Map<String, Integer> negStatus, int cleanCount,
|
||||
long totalRows, boolean allNegativeRejected) throws Exception {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("# C2 数据行级权限对拍报告\n\n");
|
||||
sb.append("- 正例(受控实体 × 用户): ").append(reports.size())
|
||||
.append(",全一致: ").append(cleanCount).append("\n");
|
||||
sb.append("- 总比对行数(JDBC 基线侧): ").append(totalRows).append("\n");
|
||||
sb.append("- 正例逐行一致率: ")
|
||||
.append(String.format("%.4f", reports.isEmpty() ? 1.0 : (double) cleanCount / reports.size()))
|
||||
.append(cleanCount == reports.size() ? " ✅ 全部逐行一致" : " ⚠️ 存在差异").append("\n");
|
||||
sb.append("- 负例(错误角色被拒): ").append(allNegativeRejected ? "✅ 全部被拒" : "⚠️ 存在未拒").append("\n\n");
|
||||
sb.append("## 正例:引擎行级过滤 vs JDBC 同语义基线\n\n");
|
||||
sb.append("| 实体[用户] | 行数 | 内容差异 | 仅JDBC | 仅引擎 | 一致率 | 结果 |\n");
|
||||
sb.append("|---|---|---|---|---|---|---|\n");
|
||||
for (DiffReport r : reports) {
|
||||
sb.append("| ").append(r.label).append(" | ").append(r.leftRowCount)
|
||||
.append(" | ").append(r.mismatches.size())
|
||||
.append(" | ").append(r.onlyInLeft.size())
|
||||
.append(" | ").append(r.onlyInRight.size())
|
||||
.append(" | ").append(String.format("%.4f", r.consistencyRate()))
|
||||
.append(" | ").append(r.isClean() ? "✅" : "⚠️").append(" |\n");
|
||||
}
|
||||
sb.append("\n## 负例:错误角色 ROLE_NOBODY 访问受控实体\n\n");
|
||||
sb.append("| 实体 | HTTP 状态 | 期望 | 结果 |\n|---|---|---|---|\n");
|
||||
for (Map.Entry<String, Integer> e : negStatus.entrySet()) {
|
||||
boolean rejected = e.getValue() != 200;
|
||||
sb.append("| ").append(e.getKey()).append(" | ").append(e.getValue())
|
||||
.append(" | 非200(PrivilegeException) | ")
|
||||
.append(rejected ? "✅ 被拒" : "⚠️ 未拒").append(" |\n");
|
||||
}
|
||||
sb.append("\n");
|
||||
for (DiffReport r : reports) {
|
||||
if (!r.isClean()) {
|
||||
sb.append(r.toMarkdown()).append("\n");
|
||||
}
|
||||
}
|
||||
Files.writeString(path, sb.toString());
|
||||
}
|
||||
|
||||
private static List<String> listEip4ptEntities(javax.sql.DataSource ds) {
|
||||
return new org.springframework.jdbc.core.JdbcTemplate(ds).queryForList(
|
||||
"SELECT tablename FROM sys_entity WHERE tablename LIKE ? AND isactive=1 ORDER BY tablename",
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.eip4.platform.parity.selfcheck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.eip4.platform.parity.diff.DiffReport;
|
||||
import com.eip4.platform.parity.diff.RowDiff;
|
||||
|
||||
/**
|
||||
* C2 数据行级权限对拍执行器。
|
||||
*
|
||||
* <p>对每个受控实体(已在 bootstrap-privilege.sql 配 {@code CREATEBY = {CURRENTUSERID}} 规则),
|
||||
* 用每个测试用户(USER_ALICE/USER_BOB/USER_CAROL)分别:
|
||||
* <ul>
|
||||
* <li><b>被测侧</b>:{@code GET /api/entity/{t}/list?asUser=U&roles=R} —— 经引擎行级过滤路径
|
||||
* (POJOCRUDServiceImpl.listSelect → dataPrivilegeService.getWhereClause 拼 WHERE)。</li>
|
||||
* <li><b>基线侧</b>:直连 JDBC {@code SELECT * FROM t WHERE createby = 'U'} —— 同语义 ground truth。</li>
|
||||
* </ul>
|
||||
* 两侧 {@link RowDiff} 逐行逐列比对,一致率 100% 即证明引擎过滤语义与物理事实逐字节对齐。
|
||||
*
|
||||
* <p>另含<b>负例</b>:用错误角色访问受控实体 → 引擎应抛 PrivilegeException(HTTP 非 200);
|
||||
* 断言之以证明"规则存在但无角色命中 → 拒绝"语义。
|
||||
*/
|
||||
public class PrivilegeCheckRunner {
|
||||
|
||||
/** 受控实体 → 其规则关联的角色(与 bootstrap-privilege.sql 一致)。 */
|
||||
public static final Map<String, String> CONTROLLED = Map.of(
|
||||
"EIP4PT_TASK", "ROLE_TASK",
|
||||
"EIP4PT_PROJECT", "ROLE_PROJECT",
|
||||
"EIP4PT_CUSTOMER", "ROLE_CUSTOMER");
|
||||
|
||||
/** 测试用户(与 bootstrap-privilege.sql 的 CREATEBY 重分区一致)。 */
|
||||
public static final List<String> USERS = List.of("USER_ALICE", "USER_BOB", "USER_CAROL");
|
||||
|
||||
private final EngineHttpClient engine;
|
||||
private final JdbcResultReader jdbc;
|
||||
|
||||
public PrivilegeCheckRunner(String engineBaseUrl, DataSource dataSource) {
|
||||
this.engine = new EngineHttpClient(engineBaseUrl);
|
||||
this.jdbc = new JdbcResultReader(dataSource);
|
||||
}
|
||||
|
||||
/** 一个 (实体, 用户) 正例:引擎过滤结果 vs JDBC 同语义基线,逐行 diff。 */
|
||||
public DiffReport checkPositive(String table, String user) {
|
||||
String t = table.toUpperCase();
|
||||
String role = CONTROLLED.get(t);
|
||||
String label = t + "[" + user + "]";
|
||||
List<Map<String, Object>> left;
|
||||
List<Map<String, Object>> right;
|
||||
try {
|
||||
// 基线:同语义 WHERE createby = user(PG bpchar 比较忽略尾空格,与引擎 P.CREATEBY='user' 一致)
|
||||
left = jdbc.query("SELECT * FROM " + t + " WHERE createby = ?", user);
|
||||
} catch (Exception e) {
|
||||
return error(label, "JDBC 基线读失败: " + e.getMessage());
|
||||
}
|
||||
try {
|
||||
String q = "asUser=" + user + "&roles=" + role;
|
||||
right = engine.listAll(t, q);
|
||||
} catch (Exception e) {
|
||||
return error(label, "引擎过滤路径失败: " + e.getMessage());
|
||||
}
|
||||
String pk = t + "_ID";
|
||||
List<String> keys = (!left.isEmpty() && left.get(0).containsKey(pk))
|
||||
? List.of(pk)
|
||||
: RowDiff.inferKeyColumns(t, left.isEmpty() ? right : left);
|
||||
return new RowDiff(keys).diff(label, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* 负例断言:用错误角色访问受控实体,引擎应抛 PrivilegeException(HTTP 非 200)。
|
||||
* @return 实际 HTTP 状态码(期望 != 200)
|
||||
*/
|
||||
public int checkNegativeStatus(String table, String wrongRole) {
|
||||
try {
|
||||
return engine.statusOf(table.toUpperCase(),
|
||||
"asUser=USER_ALICE&roles=" + wrongRole);
|
||||
} catch (Exception e) {
|
||||
// 网络层异常也视作"被拒绝"
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/** 跑全部受控实体 × 全部用户的正例,返回 DiffReport 列表。 */
|
||||
public List<DiffReport> runAllPositive() {
|
||||
List<DiffReport> out = new ArrayList<>();
|
||||
List<String> tables = new ArrayList<>(CONTROLLED.keySet());
|
||||
tables.sort(String::compareTo);
|
||||
for (String t : tables) {
|
||||
for (String u : USERS) {
|
||||
out.add(checkPositive(t, u));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static DiffReport error(String label, String msg) {
|
||||
DiffReport r = new DiffReport(label);
|
||||
DiffReport.RowMismatch mm = new DiffReport.RowMismatch("RUNNER_ERROR");
|
||||
mm.cells.add(new DiffReport.CellDiff("error", null, msg, "VALUE"));
|
||||
r.mismatches.add(mm);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
-- ============================================================================
|
||||
-- eip4-platform M0 任务 C2 —— 数据行级权限自举 bootstrap-privilege.sql
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- 用途:在已跑过 bootstrap-sys.sql + ParitySeeder(21 个 EIP4PT_* 实体)的本地
|
||||
-- eip4m0 库上,追加「数据行级过滤」所需的平台表 + 自描述元数据 + 过滤规则,
|
||||
-- 让保真层移植的 DataPrivilegeServiceImpl 能真实走引擎读路径产生行级过滤。
|
||||
--
|
||||
-- 口径权威来源(已逐一核对源码):
|
||||
-- * 触发点 = POJOCRUDServiceImpl.listSelectSpecialCol:仅当 ctx.CURRENTUSER != ADMIN
|
||||
-- 时调 dataPrivilegeService.getWhereClause(ctx, table),把返回的 " AND (...)" 拼进 WHERE。
|
||||
-- * 规则装载 = DataPrivilegeServiceImpl.getEntityDataFilterRule:
|
||||
-- listSelect(SYS_FILTERRULE WHERE ENTITYID=<实体id>) → 逐行 loadPOJO(...,true)
|
||||
-- → DataFilterHelper.converToDataFilterRule(po):取 po.get_Value("ROLES")(List<String>)
|
||||
-- 与 po.get_Value("FILTERRULE")(Conditional JSON)。
|
||||
-- * ROLES 多值落地 = LIST 显示类型 + 中间表(MIDTABLE):
|
||||
-- ROLES 列 referenceid='LIST',referencevalue 指向一条 SYS_REFERENCEVALUE,
|
||||
-- 该 referencevalue.ENTITYID→SYS_FILTERRULEROLE(中间表),ENTITYATTRIBUTEID→FILTERRULEID(回引列)。
|
||||
-- loadPOJO(isHierarchical=true) 的 hierarchicalQuery 对 LIST 列:
|
||||
-- SELECT * FROM SYS_FILTERRULEROLE WHERE FILTERRULEID=<规则id>
|
||||
-- 收集"另一列"ROLEID 的全部值 → List<String> 设回 ROLES。
|
||||
-- (见 POInfo.getReferenceValueTable/ColumnName + POJOServiceImpl.hierarchicalQuery
|
||||
-- 第 1256-1262 行:中间表恰好 2 列,referenceColumn 之外那列即取值列。)
|
||||
-- * 过滤 SQL = getFilterSql:CURRENTUSER 类型 → "P.<列> <sign> 'currentUserValue'"
|
||||
-- (StringUtil.TO_STRING 自动加单引号);本脚本用 CREATEBY = {CURRENTUSERID} 等值过滤。
|
||||
--
|
||||
-- 纪律:可重复执行(DROP IF EXISTS + DELETE 幂等);表名/列名小写。规则 ENTITYID 动态
|
||||
-- SELECT 自 sys_entity(EIP4PT_* 实体 id 由 ParitySeeder 随机生成,不可硬编码)。
|
||||
-- ============================================================================
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- 0. 清理(逆序)
|
||||
-- 规则/中间表行随物理表 DROP CASCADE 一并清除,无需单独 DELETE
|
||||
-- (首次执行表尚不存在,DELETE 会报错)。
|
||||
-- ---------------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS sys_filterrulerole CASCADE;
|
||||
DROP TABLE IF EXISTS sys_filterrule CASCADE;
|
||||
-- 元数据残留(本脚本固定 id 前缀)
|
||||
DELETE FROM sys_referencevalue WHERE sys_referencevalue_id LIKE 'd1000000-%';
|
||||
DELETE FROM sys_reference WHERE sys_reference_id LIKE 'c1000000-%';
|
||||
DELETE FROM sys_entityattribute WHERE entityid IN
|
||||
('e1000000-0000-0000-0000-000000000008', 'e1000000-0000-0000-0000-000000000009');
|
||||
DELETE FROM sys_entity WHERE sys_entity_id IN
|
||||
('e1000000-0000-0000-0000-000000000008', 'e1000000-0000-0000-0000-000000000009');
|
||||
|
||||
-- ===========================================================================
|
||||
-- 1. 物理表
|
||||
-- ===========================================================================
|
||||
|
||||
-- 1.1 SYS_FILTERRULE —— 行级过滤规则主表
|
||||
-- ROLES 是 LIST(多值)列,不落物理列(值在中间表 SYS_FILTERRULEROLE);
|
||||
-- 物理表只含标量列。FILTERRULE 存 Conditional[] 的 JSON 文本(用 text 防超长)。
|
||||
CREATE TABLE sys_filterrule (
|
||||
sys_filterrule_id character(36) NOT NULL,
|
||||
entityid character(36),
|
||||
filterrule text,
|
||||
isactive integer DEFAULT 1 NOT NULL,
|
||||
createtime bigint,
|
||||
updatetime bigint,
|
||||
createby character(36),
|
||||
updateby character(36),
|
||||
version integer DEFAULT 0 NOT NULL,
|
||||
PRIMARY KEY (sys_filterrule_id)
|
||||
);
|
||||
|
||||
-- 1.2 SYS_FILTERRULEROLE —— 规则↔角色 中间表(MIDTABLE,恰 2 列:回引列 + 取值列)
|
||||
-- 引擎 hierarchicalQuery 对 ROLES(LIST)列查此表,收集 ROLEID 列得 List<String>。
|
||||
CREATE TABLE sys_filterrulerole (
|
||||
filterruleid character(36) NOT NULL,
|
||||
roleid character varying(100) NOT NULL
|
||||
);
|
||||
|
||||
-- ===========================================================================
|
||||
-- 2. 自描述元数据
|
||||
-- 固定实体 id:
|
||||
-- SYS_FILTERRULE = e1000000-0000-0000-0000-000000000008
|
||||
-- SYS_FILTERRULEROLE = e1000000-0000-0000-0000-000000000009(tabletype=2 中间表)
|
||||
-- ===========================================================================
|
||||
INSERT INTO sys_entity
|
||||
(sys_entity_id, name, description, tablename, entitytype, isview, ischangelog,
|
||||
accesslevel, tabletype, isactive, createtime, updatetime, createby, updateby, version)
|
||||
VALUES
|
||||
('e1000000-0000-0000-0000-000000000008', '数据过滤规则', '行级数据权限过滤规则', 'SYS_FILTERRULE', 'a0000000-0000-0000-0000-0000000000ff', 0, 0, 0, 0, 1, 0, 0, 'ADMIN', 'ADMIN', 0),
|
||||
('e1000000-0000-0000-0000-000000000009', '过滤规则角色', '规则与角色的中间表', 'SYS_FILTERRULEROLE', 'a0000000-0000-0000-0000-0000000000ff', 0, 0, 0, 2, 1, 0, 0, 'ADMIN', 'ADMIN', 0);
|
||||
|
||||
-- --- SYS_FILTERRULE 的自描述属性 ---
|
||||
-- ROLES 列:referenceid='LIST' 使 displayType=LIST/ColumnClass=List.class;
|
||||
-- referencevalue 指向下方 SYS_REFERENCEVALUE(d1000000-...-0001),
|
||||
-- 解析到中间表 SYS_FILTERRULEROLE + 回引列 FILTERRULEID。
|
||||
INSERT INTO sys_entityattribute
|
||||
(sys_entityattribute_id, entityid, columnname, displayname, referenceid, referencevalue,
|
||||
ismandatory, isreadonly, iskey, isidentifier, iscombidentifier, isentitydisplay,
|
||||
entitydisplayseq, fieldlength, isactive, createby, updateby, version)
|
||||
VALUES
|
||||
('a1000000-0000-0000-0000-000000000801', 'e1000000-0000-0000-0000-000000000008', 'SYS_FILTERRULE_ID', '主键', 'CHAR', NULL, 1, 1, 1, 0, 0, 0, 1, 36, 1, 'ADMIN', 'ADMIN', 0),
|
||||
('a1000000-0000-0000-0000-000000000802', 'e1000000-0000-0000-0000-000000000008', 'ENTITYID', '实体ID', 'CHAR', NULL, 1, 0, 0, 0, 0, 1, 2, 36, 1, 'ADMIN', 'ADMIN', 0),
|
||||
('a1000000-0000-0000-0000-000000000803', 'e1000000-0000-0000-0000-000000000008', 'FILTERRULE', '过滤条件', 'NVARCHAR', NULL, 0, 0, 0, 0, 0, 0, 3, 4000, 1, 'ADMIN', 'ADMIN', 0),
|
||||
('a1000000-0000-0000-0000-000000000804', 'e1000000-0000-0000-0000-000000000008', 'ROLES', '角色', 'LIST', 'd1000000-0000-0000-0000-000000000001', 0, 0, 0, 0, 0, 0, 4, 0, 1, 'ADMIN', 'ADMIN', 0),
|
||||
('a1000000-0000-0000-0000-000000000805', 'e1000000-0000-0000-0000-000000000008', 'ISACTIVE', '是否有效', 'BOOLEAN', NULL, 0, 0, 0, 0, 0, 0, 5, 0, 1, 'ADMIN', 'ADMIN', 0),
|
||||
('a1000000-0000-0000-0000-000000000806', 'e1000000-0000-0000-0000-000000000008', 'VERSION', '版本', 'INTEGER', NULL, 0, 0, 0, 0, 0, 0, 6, 0, 1, 'ADMIN', 'ADMIN', 0);
|
||||
|
||||
-- --- SYS_FILTERRULEROLE 的自描述属性(恰 2 列;seq 决定 getColumnName(0/1) 次序) ---
|
||||
-- 第 0 列 = FILTERRULEID(回引 SYS_FILTERRULE),第 1 列 = ROLEID(取值列)。
|
||||
INSERT INTO sys_entityattribute
|
||||
(sys_entityattribute_id, entityid, columnname, displayname, referenceid, referencevalue,
|
||||
ismandatory, isreadonly, iskey, isidentifier, iscombidentifier, isentitydisplay,
|
||||
entitydisplayseq, fieldlength, isactive, createby, updateby, version)
|
||||
VALUES
|
||||
('a1000000-0000-0000-0000-000000000901', 'e1000000-0000-0000-0000-000000000009', 'FILTERRULEID', '规则ID', 'CHAR', NULL, 1, 0, 0, 0, 0, 0, 1, 36, 1, 'ADMIN', 'ADMIN', 0),
|
||||
('a1000000-0000-0000-0000-000000000902', 'e1000000-0000-0000-0000-000000000009', 'ROLEID', '角色', 'NVARCHAR', NULL, 1, 0, 0, 0, 0, 1, 2, 100, 1, 'ADMIN', 'ADMIN', 0);
|
||||
|
||||
-- ===========================================================================
|
||||
-- 3. ROLES(LIST)列的引用值映射
|
||||
-- SYS_REFERENCEVALUE.ENTITYID → SYS_FILTERRULEROLE 实体(得中间表表名)
|
||||
-- SYS_REFERENCEVALUE.ENTITYATTRIBUTEID → FILTERRULEID 属性(得回引列名)
|
||||
-- (引擎 DataDicServiceImpl.getEntityTableNameByReferenceValue /
|
||||
-- getColumnNameByReferenceValue 两条 JOIN 解析。)
|
||||
-- 另需一条 SYS_REFERENCE(entityid=中间表实体)以满足通用引用约束。
|
||||
-- ===========================================================================
|
||||
INSERT INTO sys_reference
|
||||
(sys_reference_id, entityid, name, description, isactive, createtime, updatetime, createby, updateby, version)
|
||||
VALUES
|
||||
('c1000000-0000-0000-0000-000000000001', 'e1000000-0000-0000-0000-000000000009', 'ROLES->SYS_FILTERRULEROLE', 'C2 行级权限角色引用', 1, 0, 0, 'ADMIN', 'ADMIN', 0);
|
||||
|
||||
INSERT INTO sys_referencevalue
|
||||
(sys_referencevalue_id, entityid, entityattributeid, name, isactive, createtime, updatetime, createby, updateby, version)
|
||||
VALUES
|
||||
('d1000000-0000-0000-0000-000000000001', 'e1000000-0000-0000-0000-000000000009', 'a1000000-0000-0000-0000-000000000901', 'ROLES 中间表映射', 1, 0, 0, 'ADMIN', 'ADMIN', 0);
|
||||
|
||||
-- ===========================================================================
|
||||
-- 4. 受控实体的 CREATEBY 重分区 —— 让 "CREATEBY = {CURRENTUSERID}" 过滤可判别
|
||||
-- ParitySeeder 把 50 行 CREATEBY 全置 'ADMIN';这里按 BIZNO 后缀的数字奇偶/三分,
|
||||
-- 把 CREATEBY 改成 USER_ALICE / USER_BOB / USER_CAROL,使不同用户视角看到不同子集。
|
||||
-- 确定性:对每实体的 50 行,按 ctid 行序号 % 3 分配,可重复执行(结果幂等)。
|
||||
-- ===========================================================================
|
||||
-- EIP4PT_TASK
|
||||
WITH ranked AS (
|
||||
SELECT eip4pt_task_id, row_number() OVER (ORDER BY eip4pt_task_id) AS rn FROM eip4pt_task
|
||||
)
|
||||
UPDATE eip4pt_task t SET createby = CASE (r.rn % 3)
|
||||
WHEN 0 THEN 'USER_ALICE' WHEN 1 THEN 'USER_BOB' ELSE 'USER_CAROL' END
|
||||
FROM ranked r WHERE t.eip4pt_task_id = r.eip4pt_task_id;
|
||||
|
||||
-- EIP4PT_PROJECT
|
||||
WITH ranked AS (
|
||||
SELECT eip4pt_project_id, row_number() OVER (ORDER BY eip4pt_project_id) AS rn FROM eip4pt_project
|
||||
)
|
||||
UPDATE eip4pt_project t SET createby = CASE (r.rn % 3)
|
||||
WHEN 0 THEN 'USER_ALICE' WHEN 1 THEN 'USER_BOB' ELSE 'USER_CAROL' END
|
||||
FROM ranked r WHERE t.eip4pt_project_id = r.eip4pt_project_id;
|
||||
|
||||
-- EIP4PT_CUSTOMER
|
||||
WITH ranked AS (
|
||||
SELECT eip4pt_customer_id, row_number() OVER (ORDER BY eip4pt_customer_id) AS rn FROM eip4pt_customer
|
||||
)
|
||||
UPDATE eip4pt_customer t SET createby = CASE (r.rn % 3)
|
||||
WHEN 0 THEN 'USER_ALICE' WHEN 1 THEN 'USER_BOB' ELSE 'USER_CAROL' END
|
||||
FROM ranked r WHERE t.eip4pt_customer_id = r.eip4pt_customer_id;
|
||||
|
||||
-- ===========================================================================
|
||||
-- 5. 过滤规则种子 —— 为 3 个 EIP4PT_* 实体各配 1 条行级过滤规则
|
||||
-- 规则语义:CREATEBY = {CURRENTUSERID}(只看自己创建的行)。
|
||||
-- 规则 ENTITYID 动态取自 sys_entity(实体 id 不可硬编码)。
|
||||
-- FILTERRULE = Conditional[] 的 JSON:type=CURRENTUSERID 触发 getFilterSql
|
||||
-- 的 "P.CREATEBY ='<currentUser>'" 分支。
|
||||
-- 每条规则关联 1 个角色(ROLE_TASK / ROLE_PROJECT / ROLE_CUSTOMER),经中间表落地。
|
||||
-- ===========================================================================
|
||||
-- 规则固定 id 前缀 f1000000-,便于幂等清理
|
||||
INSERT INTO sys_filterrule (sys_filterrule_id, entityid, filterrule, isactive, createtime, updatetime, createby, updateby, version)
|
||||
SELECT 'f1000000-0000-0000-0000-000000000001', sys_entity_id,
|
||||
'[{"preConditional":"CREATEBY","sign":"=","backConditional":"{CURRENTUSERID}","type":"CURRENTUSERID","op":null}]',
|
||||
1, 0, 0, 'ADMIN', 'ADMIN', 0
|
||||
FROM sys_entity WHERE tablename = 'EIP4PT_TASK';
|
||||
|
||||
INSERT INTO sys_filterrule (sys_filterrule_id, entityid, filterrule, isactive, createtime, updatetime, createby, updateby, version)
|
||||
SELECT 'f1000000-0000-0000-0000-000000000002', sys_entity_id,
|
||||
'[{"preConditional":"CREATEBY","sign":"=","backConditional":"{CURRENTUSERID}","type":"CURRENTUSERID","op":null}]',
|
||||
1, 0, 0, 'ADMIN', 'ADMIN', 0
|
||||
FROM sys_entity WHERE tablename = 'EIP4PT_PROJECT';
|
||||
|
||||
INSERT INTO sys_filterrule (sys_filterrule_id, entityid, filterrule, isactive, createtime, updatetime, createby, updateby, version)
|
||||
SELECT 'f1000000-0000-0000-0000-000000000003', sys_entity_id,
|
||||
'[{"preConditional":"CREATEBY","sign":"=","backConditional":"{CURRENTUSERID}","type":"CURRENTUSERID","op":null}]',
|
||||
1, 0, 0, 'ADMIN', 'ADMIN', 0
|
||||
FROM sys_entity WHERE tablename = 'EIP4PT_CUSTOMER';
|
||||
|
||||
-- 规则↔角色(中间表):每条规则 1 个角色
|
||||
INSERT INTO sys_filterrulerole (filterruleid, roleid) VALUES
|
||||
('f1000000-0000-0000-0000-000000000001', 'ROLE_TASK'),
|
||||
('f1000000-0000-0000-0000-000000000002', 'ROLE_PROJECT'),
|
||||
('f1000000-0000-0000-0000-000000000003', 'ROLE_CUSTOMER');
|
||||
Reference in New Issue
Block a user