@@ -5,6 +5,7 @@ import com.cloudhandson.vpdbackoffice.domain.permission.AppRole;
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.PermissionRule;
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.PermissionSet;
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.PermissionSetCommand;
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.PermissionView;
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.RuleCommand;
|
||||
import com.cloudhandson.vpdbackoffice.domain.protectedobject.ProtectedColumn;
|
||||
import com.cloudhandson.vpdbackoffice.mapper.PermissionMapper;
|
||||
@@ -38,6 +39,10 @@ public class PermissionService {
|
||||
return permissionMapper.findRoles();
|
||||
}
|
||||
|
||||
public List<PermissionView> findPermissionViews() {
|
||||
return permissionMapper.findPermissionViews();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PermissionSet savePermissionSet(PermissionSetCommand command) {
|
||||
if (!"SELECT".equalsIgnoreCase(command.action())) {
|
||||
@@ -83,6 +88,18 @@ public class PermissionService {
|
||||
return new PermissionSet(permissionId, command.roleId(), command.objectId(), "SELECT", List.of(), List.of());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deletePermission(long permissionId) {
|
||||
permissionMapper.deleteRules(permissionId);
|
||||
permissionMapper.deleteVisibleColumns(permissionId);
|
||||
int deleted = permissionMapper.deletePermission(permissionId);
|
||||
if (deleted == 0) {
|
||||
throw new AppException("삭제할 권한을 찾을 수 없습니다.");
|
||||
}
|
||||
auditService.record(new AuditEvent("PERMISSION_DELETED", null, null, "SUCCESS", null, null,
|
||||
"permissionId=" + permissionId));
|
||||
}
|
||||
|
||||
private void validateRules(List<RuleCommand> rules) {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
throw new AppException("행 규칙은 하나 이상 필요합니다.");
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
package com.cloudhandson.vpdbackoffice.service;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.domain.audit.AuditEvent;
|
||||
import com.cloudhandson.vpdbackoffice.domain.protectedobject.ProtectedColumn;
|
||||
import com.cloudhandson.vpdbackoffice.domain.protectedobject.ProtectedObject;
|
||||
import com.cloudhandson.vpdbackoffice.domain.protectedobject.ProtectedObjectCreateCommand;
|
||||
import com.cloudhandson.vpdbackoffice.mapper.ProtectedObjectMapper;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class ProtectedObjectService {
|
||||
|
||||
private final ProtectedObjectMapper mapper;
|
||||
private final AuditService auditService;
|
||||
|
||||
public ProtectedObjectService(ProtectedObjectMapper mapper) {
|
||||
public ProtectedObjectService(ProtectedObjectMapper mapper, AuditService auditService) {
|
||||
this.mapper = mapper;
|
||||
this.auditService = auditService;
|
||||
}
|
||||
|
||||
public List<ProtectedObject> findEnabled() {
|
||||
@@ -30,4 +39,38 @@ public class ProtectedObjectService {
|
||||
public List<ProtectedColumn> findColumns(long objectId) {
|
||||
return mapper.findColumns(objectId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createObject(ProtectedObjectCreateCommand command) {
|
||||
long objectId = mapper.nextObjectId();
|
||||
mapper.insertObject(objectId, command);
|
||||
Set<String> sensitive = splitCsv(command.sensitiveColumns());
|
||||
for (String column : splitCsv(command.columns())) {
|
||||
mapper.insertColumn(mapper.nextColumnId(), objectId, column, sensitive.contains(column) ? "Y" : "N");
|
||||
}
|
||||
auditService.record(new AuditEvent("PROTECTED_OBJECT_CREATED", null, objectId, "SUCCESS", null, null,
|
||||
command.objectName()));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void disableObject(long objectId) {
|
||||
int updated = mapper.disableObject(objectId);
|
||||
if (updated == 0) {
|
||||
throw new AppException("보호 객체를 찾을 수 없습니다.");
|
||||
}
|
||||
auditService.record(new AuditEvent("PROTECTED_OBJECT_DISABLED", null, objectId, "SUCCESS", null, null, null));
|
||||
}
|
||||
|
||||
private Set<String> splitCsv(String value) {
|
||||
Set<String> result = new HashSet<>();
|
||||
if (value == null || value.isBlank()) {
|
||||
return result;
|
||||
}
|
||||
Arrays.stream(value.split(","))
|
||||
.map(String::trim)
|
||||
.filter(token -> !token.isBlank())
|
||||
.map(token -> token.toUpperCase(Locale.ROOT))
|
||||
.forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.cloudhandson.vpdbackoffice.service;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.domain.audit.AuditEvent;
|
||||
import com.cloudhandson.vpdbackoffice.domain.user.AppUser;
|
||||
import com.cloudhandson.vpdbackoffice.domain.user.UserCreateCommand;
|
||||
import com.cloudhandson.vpdbackoffice.domain.user.UserRoleView;
|
||||
import com.cloudhandson.vpdbackoffice.mapper.UserMapper;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final AuditService auditService;
|
||||
|
||||
public UserService(UserMapper userMapper, AuditService auditService) {
|
||||
this.userMapper = userMapper;
|
||||
this.auditService = auditService;
|
||||
}
|
||||
|
||||
public List<AppUser> findAll() {
|
||||
return userMapper.findAll();
|
||||
}
|
||||
|
||||
public List<UserRoleView> findUserRoles() {
|
||||
return userMapper.findUserRoles();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createUser(UserCreateCommand command) {
|
||||
long userId = userMapper.nextUserId();
|
||||
userMapper.insertUser(userId, command);
|
||||
auditService.record(new AuditEvent("USER_CREATED", null, null, "SUCCESS", null, null, command.username()));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setActive(long userId, boolean active) {
|
||||
int updated = userMapper.updateActive(userId, active ? "Y" : "N");
|
||||
if (updated == 0) {
|
||||
throw new AppException("사용자를 찾을 수 없습니다.");
|
||||
}
|
||||
auditService.record(new AuditEvent("USER_ACTIVE_CHANGED", null, null, "SUCCESS", null, null,
|
||||
"userId=" + userId + ",active=" + active));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void grantRole(long userId, long roleId) {
|
||||
userMapper.insertUserRole(userId, roleId);
|
||||
auditService.record(new AuditEvent("USER_ROLE_GRANTED", null, null, "SUCCESS", null, null,
|
||||
"userId=" + userId + ",roleId=" + roleId));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void revokeRole(long userId, long roleId) {
|
||||
int deleted = userMapper.deleteUserRole(userId, roleId);
|
||||
if (deleted == 0) {
|
||||
throw new AppException("삭제할 사용자 역할 매핑을 찾을 수 없습니다.");
|
||||
}
|
||||
auditService.record(new AuditEvent("USER_ROLE_REVOKED", null, null, "SUCCESS", null, null,
|
||||
"userId=" + userId + ",roleId=" + roleId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user