P2-4: 多维数据权限全形态实测——R1 风险判定(引擎多维隔离语义成立)
普查(客户库只读):1079 条活跃规则归型——多规则同实体 303/345(角色 OR 88%)、 多条件 op 串联 117、type 分布 CURRENTUSERORGID 323/OWNNERPROJECT 165/CURRENTUSERDEPARTID 27、 SPECIALDEPART/ORG 客户零用;OwnProjectWhere SysConfig 实际值取证。 实测(本地 eip4m0,可写):bootstrap-multidim.sql 构造 7 受控实体 + 规则矩阵, MultiDimPrivilegeRunner + ParityCli --multidim 多维 ctx 驱动引擎过滤 vs JDBC 等价 WHERE 逐行对拍——14 形态 100% 一致(39 行)+ 7/7 负例被拒。覆盖部门/组织/SPECIALDEPART/ OWNNERPROJECT 单维、op=AND 串联、多规则角色 OR 三态、建筑三维 OWNER×部门×项目。 客户库抽测(只读,P2-1 口径):DM_FILE(299)/SYS_USER(806)组织维 count+行级 MATCH + 负例被拒。 测试通道:EntityController 加 asDepart/asOrg(与 asUser 同性质,不传零回归), 使引擎可解析 CURRENTUSERDEPARTID/CURRENTUSERORGID 维度。 单测:MultiDimDataPrivilegeTest 9 测(getWhereClause 拼接矩阵,FakePOInfo 模式)。 全模块 test + ArchUnit 绿。手册新增 §5.34/§5.35。 R1 判定:引擎多维隔离语义成立,不构成 P2 阻塞;缺口(OWNNERPROJECT 客户库直拍/ 生产 ctx 注入/SPECIALDEPART 无真实样本)如实登记跟踪。未触发决策会 S1。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,7 +33,7 @@ public class EntityController {
|
||||
* 这些键不是实体列,是协议/控制参数,不过白名单(但仍各自做语义校验,见 list 方法)。
|
||||
*/
|
||||
private static final Set<String> RESERVED_KEYS = Set.of(
|
||||
"page", "perPage", "asUser", "roles", "orderBy", "orderDir");
|
||||
"page", "perPage", "asUser", "roles", "asDepart", "asOrg", "orderBy", "orderDir");
|
||||
|
||||
private final POJOCRUDService pojoCRUDService;
|
||||
private final IdentifierWhitelist identifierWhitelist;
|
||||
@@ -58,6 +58,8 @@ public class EntityController {
|
||||
@RequestParam(defaultValue = "10") int perPage,
|
||||
@RequestParam(required = false) String asUser,
|
||||
@RequestParam(required = false) String roles,
|
||||
@RequestParam(required = false) String asDepart,
|
||||
@RequestParam(required = false) String asOrg,
|
||||
@RequestParam(required = false) String orderBy,
|
||||
@RequestParam(required = false) String orderDir,
|
||||
@RequestParam Map<String, String> allParams) {
|
||||
@@ -65,7 +67,7 @@ public class EntityController {
|
||||
// 安全第 1 层:表名必须存在于 SYS_ENTITY,否则 400(非法表名不进引擎拼接)
|
||||
identifierWhitelist.requireLegalTable(t);
|
||||
|
||||
Properties ctx = buildCtx(asUser, roles);
|
||||
Properties ctx = buildCtx(asUser, roles, asDepart, asOrg);
|
||||
Map<String, Object> cond = new HashMap<>();
|
||||
cond.put(POJOCRUDService.PAGE_START, (page - 1) * perPage);
|
||||
cond.put(POJOCRUDService.PAGE_SIZE, perPage);
|
||||
@@ -139,11 +141,19 @@ public class EntityController {
|
||||
* <li><b>都没有</b>(无令牌、无 asUser)→ ADMIN 视角,不过滤(与原默认行为一致)。</li>
|
||||
* </ol>
|
||||
*/
|
||||
private Properties buildCtx(String asUser, String roles) {
|
||||
private Properties buildCtx(String asUser, String roles, String asDepart, String asOrg) {
|
||||
// 1) 显式 asUser 测试通道优先(保持 C2 既有行为不变)
|
||||
if (asUser != null && !asUser.isBlank()) {
|
||||
Properties ctx = new Properties();
|
||||
ctx.setProperty(LoggedInUser.CURRENTUSER, asUser);
|
||||
// P2-4 多维测试通道:可选注入当前部门/机构,触发引擎 CURRENTUSERDEPARTID/CURRENTUSERORGID
|
||||
// 维度过滤(getFilterSql 读 ctx.CURRENTDEPART / ctx.CURRENTORG)。不传则维持单维(用户)行为。
|
||||
if (asDepart != null && !asDepart.isBlank()) {
|
||||
ctx.setProperty(LoggedInUser.CURRENTDEPART, asDepart);
|
||||
}
|
||||
if (asOrg != null && !asOrg.isBlank()) {
|
||||
ctx.setProperty(LoggedInUser.CURRENTORG, asOrg);
|
||||
}
|
||||
List<String> roleList = new ArrayList<>();
|
||||
if (roles != null && !roles.isBlank()) {
|
||||
for (String r : roles.split(",")) {
|
||||
|
||||
Reference in New Issue
Block a user