diff --git a/src/main/java/com/cloudhandson/vpdbackoffice/mapper/PermissionMapper.java b/src/main/java/com/cloudhandson/vpdbackoffice/mapper/PermissionMapper.java index c5341e6..1428a88 100644 --- a/src/main/java/com/cloudhandson/vpdbackoffice/mapper/PermissionMapper.java +++ b/src/main/java/com/cloudhandson/vpdbackoffice/mapper/PermissionMapper.java @@ -29,6 +29,10 @@ public interface PermissionMapper { Long findPermissionId(@Param("roleId") long roleId, @Param("objectId") long objectId); + Long findObjectIdByPermissionId(@Param("permissionId") long permissionId); + + int countPermissionsByObjectId(@Param("objectId") long objectId); + void insertPermission(@Param("permissionId") long permissionId, @Param("roleId") long roleId, @Param("objectId") long objectId, diff --git a/src/main/java/com/cloudhandson/vpdbackoffice/mapper/ProtectedObjectMapper.java b/src/main/java/com/cloudhandson/vpdbackoffice/mapper/ProtectedObjectMapper.java index e4b89c3..dd7821d 100644 --- a/src/main/java/com/cloudhandson/vpdbackoffice/mapper/ProtectedObjectMapper.java +++ b/src/main/java/com/cloudhandson/vpdbackoffice/mapper/ProtectedObjectMapper.java @@ -13,6 +13,8 @@ public interface ProtectedObjectMapper { List findEnabled(); + List findEnabledWithPermissions(); + ProtectedObject findById(@Param("objectId") long objectId); ProtectedObject findByOwnerAndName(@Param("owner") String owner, @Param("objectName") String objectName); diff --git a/src/main/java/com/cloudhandson/vpdbackoffice/service/PermissionService.java b/src/main/java/com/cloudhandson/vpdbackoffice/service/PermissionService.java index ba70218..ba3f37d 100644 --- a/src/main/java/com/cloudhandson/vpdbackoffice/service/PermissionService.java +++ b/src/main/java/com/cloudhandson/vpdbackoffice/service/PermissionService.java @@ -110,12 +110,16 @@ public class PermissionService { @Transactional public void deletePermission(long permissionId) { + Long objectId = permissionMapper.findObjectIdByPermissionId(permissionId); permissionMapper.deleteRules(permissionId); permissionMapper.deleteVisibleColumns(permissionId); int deleted = permissionMapper.deletePermission(permissionId); if (deleted == 0) { throw new AppException("삭제할 권한을 찾을 수 없습니다."); } + if (objectId != null && permissionMapper.countPermissionsByObjectId(objectId) == 0) { + protectedObjectService.disableObject(objectId); + } auditService.record(new AuditEvent("PERMISSION_DELETED", null, null, "SUCCESS", null, null, "permissionId=" + permissionId)); } diff --git a/src/main/java/com/cloudhandson/vpdbackoffice/service/ProtectedObjectService.java b/src/main/java/com/cloudhandson/vpdbackoffice/service/ProtectedObjectService.java index aa82f47..553b934 100644 --- a/src/main/java/com/cloudhandson/vpdbackoffice/service/ProtectedObjectService.java +++ b/src/main/java/com/cloudhandson/vpdbackoffice/service/ProtectedObjectService.java @@ -35,6 +35,10 @@ public class ProtectedObjectService { return mapper.findEnabled(); } + public List findEnabledWithPermissions() { + return mapper.findEnabledWithPermissions(); + } + public List findDatabaseObjects() { CacheEntry> cached = databaseObjectsCache; if (cached != null && !cached.expired()) { @@ -83,6 +87,7 @@ public class ProtectedObjectService { for (String column : splitCsv(normalized.columns())) { mapper.insertColumn(mapper.nextColumnId(), objectId, column, sensitive.contains(column) ? "Y" : "N"); } + databaseObjectsCache = null; protectedColumnsCache.remove(objectId); auditService.record(new AuditEvent("PROTECTED_OBJECT_CREATED", null, objectId, "SUCCESS", null, null, normalized.objectName())); @@ -96,6 +101,8 @@ public class ProtectedObjectService { if (existing != null) { if (!existing.enabled()) { mapper.enableObject(existing.objectId()); + databaseObjectsCache = null; + protectedColumnsCache.remove(existing.objectId()); auditService.record(new AuditEvent("PROTECTED_OBJECT_RE_ENABLED", null, existing.objectId(), "SUCCESS", null, null, existing.displayName())); return mapper.findById(existing.objectId()); @@ -119,6 +126,7 @@ public class ProtectedObjectService { for (String column : columns) { mapper.insertColumn(mapper.nextColumnId(), objectId, column, "N"); } + databaseObjectsCache = null; protectedColumnsCache.remove(objectId); auditService.record(new AuditEvent("PROTECTED_OBJECT_AUTO_CREATED", null, objectId, "SUCCESS", null, null, command.objectName())); @@ -162,6 +170,8 @@ public class ProtectedObjectService { if (updated == 0) { throw new AppException("보호 객체를 찾을 수 없습니다."); } + databaseObjectsCache = null; + protectedColumnsCache.remove(objectId); auditService.record(new AuditEvent("PROTECTED_OBJECT_DISABLED", null, objectId, "SUCCESS", null, null, null)); } diff --git a/src/main/java/com/cloudhandson/vpdbackoffice/web/PermissionController.java b/src/main/java/com/cloudhandson/vpdbackoffice/web/PermissionController.java index 798133f..42f8ba6 100644 --- a/src/main/java/com/cloudhandson/vpdbackoffice/web/PermissionController.java +++ b/src/main/java/com/cloudhandson/vpdbackoffice/web/PermissionController.java @@ -63,7 +63,7 @@ public class PermissionController { @GetMapping("/permissions") public String permissions(Model model) { long started = System.nanoTime(); - var objects = protectedObjectService.findEnabled(); + var objects = protectedObjectService.findEnabledWithPermissions(); long objectsAt = System.nanoTime(); var roles = permissionService.findRoles(); long rolesAt = System.nanoTime(); diff --git a/src/main/resources/mapper/PermissionMapper.xml b/src/main/resources/mapper/PermissionMapper.xml index 5b2e133..955219b 100644 --- a/src/main/resources/mapper/PermissionMapper.xml +++ b/src/main/resources/mapper/PermissionMapper.xml @@ -84,6 +84,20 @@ AND o.object_id = #{objectId} + + + + + +