fix #557: guide permission-driven VPD flow
This commit is contained in:
@@ -19,9 +19,12 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class PermissionService {
|
||||
|
||||
private static final Set<String> RULE_TYPES = Set.of("ALL", "=", "!=", "MY_DEPT", "SELF", "DEPT", "EMP_NO");
|
||||
private static final Set<String> VALUE_REQUIRED_RULE_TYPES = Set.of("=", "!=", "DEPT", "EMP_NO");
|
||||
private static final Set<String> DEFAULT_COLUMN_RULE_TYPES = Set.of("MY_DEPT", "SELF", "DEPT", "EMP_NO");
|
||||
private static final Set<String> RULE_TYPES = Set.of(
|
||||
"ALL", "=", "!=", "MY_DEPT", "SELF", "DEPT", "EMP_NO", "TAG");
|
||||
private static final Set<String> VALUE_REQUIRED_RULE_TYPES = Set.of(
|
||||
"=", "!=", "DEPT", "EMP_NO", "TAG");
|
||||
private static final Set<String> DEFAULT_COLUMN_RULE_TYPES = Set.of(
|
||||
"MY_DEPT", "SELF", "DEPT", "EMP_NO", "TAG");
|
||||
private static final Set<String> PERMISSION_EFFECTS = Set.of("ALLOW", "DENY");
|
||||
private static final Set<String> SENSITIVITY_LEVELS = Set.of(
|
||||
"PUBLIC", "INTERNAL", "CONFIDENTIAL", "RESTRICTED");
|
||||
@@ -124,12 +127,13 @@ public class PermissionService {
|
||||
|
||||
permissionMapper.deleteRules(permissionId);
|
||||
for (RuleCommand rule : command.rules()) {
|
||||
String type = normalize(rule.ruleType());
|
||||
permissionMapper.insertRule(new PermissionRule(
|
||||
permissionMapper.nextRuleId(),
|
||||
permissionId,
|
||||
normalizeNullable(rule.ruleColumn()),
|
||||
normalize(rule.ruleType()),
|
||||
clean(rule.ruleValue())
|
||||
type,
|
||||
normalizeRuleValue(type, rule.ruleValue())
|
||||
));
|
||||
}
|
||||
|
||||
@@ -191,16 +195,23 @@ public class PermissionService {
|
||||
if (column != null && !allowedColumns.contains(column)) {
|
||||
throw new AppException("행 규칙 컬럼은 보호 객체 컬럼이어야 합니다: " + column);
|
||||
}
|
||||
if (!seen.add(column + ":" + type + ":" + clean(rule.ruleValue()))) {
|
||||
String ruleValue = normalizeRuleValue(type, rule.ruleValue());
|
||||
if (!seen.add(column + ":" + type + ":" + ruleValue)) {
|
||||
throw new AppException("중복된 행 규칙이 있습니다.");
|
||||
}
|
||||
hasAll = hasAll || "ALL".equals(type);
|
||||
if (!"ALL".equals(type) && column == null && !DEFAULT_COLUMN_RULE_TYPES.contains(type)) {
|
||||
throw new AppException(type + " 규칙에는 컬럼이 필요합니다.");
|
||||
}
|
||||
if (VALUE_REQUIRED_RULE_TYPES.contains(type) && clean(rule.ruleValue()).isBlank()) {
|
||||
if ("TAG".equals(type) && column == null && !allowedColumns.contains("TECH_TAG")) {
|
||||
throw new AppException("TAG 규칙의 기본 컬럼 TECH_TAG가 보호 객체에 없습니다. 컬럼을 지정하세요.");
|
||||
}
|
||||
if (VALUE_REQUIRED_RULE_TYPES.contains(type) && ruleValue.isBlank()) {
|
||||
throw new AppException(type + " 규칙에는 값이 필요합니다.");
|
||||
}
|
||||
if ("TAG".equals(type) && !ruleValue.matches("[A-Z0-9_-]+")) {
|
||||
throw new AppException("TAG 값은 영문 대문자, 숫자, '_' 또는 '-'만 사용할 수 있습니다.");
|
||||
}
|
||||
}
|
||||
if (hasAll && rules.size() > 1) {
|
||||
throw new AppException("ALL 규칙은 다른 규칙과 함께 저장할 수 없습니다.");
|
||||
@@ -255,6 +266,11 @@ public class PermissionService {
|
||||
return cleaned.isBlank() ? null : cleaned.toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private String normalizeRuleValue(String type, String value) {
|
||||
String cleaned = clean(value);
|
||||
return "TAG".equals(type) ? cleaned.toUpperCase(Locale.ROOT) : cleaned;
|
||||
}
|
||||
|
||||
private String clean(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user