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:
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
/**
|
||||
@@ -31,19 +32,29 @@ public class EntityController {
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
}
|
||||
|
||||
/** 分页查询:GET /api/entity/{table}/list?page=1&perPage=10&列名=值(amis filter 透传) */
|
||||
/**
|
||||
* 分页查询:GET /api/entity/{table}/list?page=1&perPage=10&列名=值(amis filter 透传)
|
||||
*
|
||||
* <p>C2 数据行级权限驱动:可选传 {@code asUser}(当前用户)+ {@code roles}(逗号分隔角色)
|
||||
* 构造非 ADMIN 上下文,从而触发 {@code POJOCRUDServiceImpl} 的行级过滤
|
||||
* (引擎仅当 {@code ctx.CURRENTUSER != ADMIN} 时调 {@code dataPrivilegeService.getWhereClause})。
|
||||
* 不传则沿用 ADMIN 视角(不过滤),与原有行为一致。
|
||||
*/
|
||||
@GetMapping("/{table}/list")
|
||||
public Map<String, Object> list(@PathVariable String table,
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "10") int perPage,
|
||||
@RequestParam(required = false) String asUser,
|
||||
@RequestParam(required = false) String roles,
|
||||
@RequestParam Map<String, String> allParams) {
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
Properties ctx = buildCtx(asUser, roles);
|
||||
Map<String, Object> cond = new HashMap<>();
|
||||
cond.put(POJOCRUDService.PAGE_START, (page - 1) * perPage);
|
||||
cond.put(POJOCRUDService.PAGE_SIZE, perPage);
|
||||
// amis filter 表单值透传为引擎查询条件(保留大写列名约定,跳过分页参数与空值)
|
||||
// amis filter 表单值透传为引擎查询条件(保留大写列名约定,跳过分页参数、权限参数与空值)
|
||||
allParams.forEach((k, v) -> {
|
||||
if (!"page".equals(k) && !"perPage".equals(k) && v != null && !v.isBlank()) {
|
||||
if (!"page".equals(k) && !"perPage".equals(k) && !"asUser".equals(k) && !"roles".equals(k)
|
||||
&& v != null && !v.isBlank()) {
|
||||
cond.put(k.toUpperCase(), v);
|
||||
}
|
||||
});
|
||||
@@ -73,6 +84,28 @@ public class EntityController {
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造调用上下文。无 asUser → ADMIN 视角(不触发过滤);有 asUser → 非 ADMIN 视角,
|
||||
* 把 CURRENTUSER 与 ROLES(List)放入 Properties,交由引擎按 SYS_FILTERRULE 规则过滤。
|
||||
*/
|
||||
private Properties buildCtx(String asUser, String roles) {
|
||||
if (asUser == null || asUser.isBlank()) {
|
||||
return UserSession.getAdmin();
|
||||
}
|
||||
Properties ctx = new Properties();
|
||||
ctx.setProperty(LoggedInUser.CURRENTUSER, asUser);
|
||||
List<String> roleList = new ArrayList<>();
|
||||
if (roles != null && !roles.isBlank()) {
|
||||
for (String r : roles.split(",")) {
|
||||
if (!r.isBlank()) {
|
||||
roleList.add(r.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.put(LoggedInUser.ROLES, roleList);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/** GeneralPOJO 值存于内部数组(非 bean getter),手工展开为平面 map 供 JSON 序列化。 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> toRows(Object listResult) {
|
||||
|
||||
Reference in New Issue
Block a user