@@ -31,6 +31,7 @@ public class PermissionController {
|
||||
public String permissions(Model model) {
|
||||
model.addAttribute("roles", permissionService.findRoles());
|
||||
model.addAttribute("objects", protectedObjectService.findEnabled());
|
||||
model.addAttribute("dbObjects", protectedObjectService.findDatabaseObjects());
|
||||
model.addAttribute("permissions", permissionService.findPermissionViews());
|
||||
return "permissions";
|
||||
}
|
||||
@@ -38,12 +39,13 @@ public class PermissionController {
|
||||
@PostMapping("/permissions")
|
||||
public String save(
|
||||
@RequestParam long roleId,
|
||||
@RequestParam long objectId,
|
||||
@RequestParam String objectRef,
|
||||
@RequestParam String ruleType,
|
||||
@RequestParam(required = false) String ruleValue,
|
||||
@RequestParam(required = false) String visibleColumns,
|
||||
RedirectAttributes redirectAttributes
|
||||
) {
|
||||
long objectId = resolveObjectId(objectRef);
|
||||
permissionService.savePermissionSet(new PermissionSetCommand(
|
||||
roleId,
|
||||
objectId,
|
||||
@@ -55,6 +57,24 @@ public class PermissionController {
|
||||
return "redirect:/permissions";
|
||||
}
|
||||
|
||||
private long resolveObjectId(String objectRef) {
|
||||
if (objectRef == null || objectRef.isBlank()) {
|
||||
throw new IllegalArgumentException("보호 객체를 선택하세요.");
|
||||
}
|
||||
if (objectRef.startsWith("protected:")) {
|
||||
return Long.parseLong(objectRef.substring("protected:".length()));
|
||||
}
|
||||
if (objectRef.startsWith("db:")) {
|
||||
String value = objectRef.substring("db:".length());
|
||||
int dot = value.indexOf('.');
|
||||
if (dot < 1 || dot == value.length() - 1) {
|
||||
throw new IllegalArgumentException("DB 객체 형식이 올바르지 않습니다.");
|
||||
}
|
||||
return protectedObjectService.ensureProtectedObject(value.substring(0, dot), value.substring(dot + 1)).objectId();
|
||||
}
|
||||
throw new IllegalArgumentException("보호 객체 형식이 올바르지 않습니다.");
|
||||
}
|
||||
|
||||
private List<String> splitColumns(String visibleColumns) {
|
||||
if (visibleColumns == null || visibleColumns.isBlank()) {
|
||||
return List.of();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.cloudhandson.vpdbackoffice.web;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.domain.probe.ProbeCommand;
|
||||
import com.cloudhandson.vpdbackoffice.service.BearerTokenService;
|
||||
import com.cloudhandson.vpdbackoffice.service.OrdsProbeService;
|
||||
import com.cloudhandson.vpdbackoffice.service.ProtectedObjectService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -14,35 +13,30 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
public class ProbeController {
|
||||
|
||||
private final OrdsProbeService probeService;
|
||||
private final BearerTokenService tokenService;
|
||||
private final ProtectedObjectService protectedObjectService;
|
||||
|
||||
public ProbeController(
|
||||
OrdsProbeService probeService,
|
||||
BearerTokenService tokenService,
|
||||
ProtectedObjectService protectedObjectService
|
||||
) {
|
||||
this.probeService = probeService;
|
||||
this.tokenService = tokenService;
|
||||
this.protectedObjectService = protectedObjectService;
|
||||
}
|
||||
|
||||
@GetMapping("/probe")
|
||||
public String probe(Model model) {
|
||||
model.addAttribute("tokens", tokenService.findAll());
|
||||
model.addAttribute("objects", protectedObjectService.findEnabled());
|
||||
return "probe";
|
||||
}
|
||||
|
||||
@PostMapping("/probe")
|
||||
public String run(
|
||||
@RequestParam long keyId,
|
||||
@RequestParam long objectId,
|
||||
@RequestParam String bearerToken,
|
||||
@RequestParam(defaultValue = "50") int limit,
|
||||
Model model
|
||||
) {
|
||||
model.addAttribute("result", probeService.runProbe(new ProbeCommand(keyId, objectId, bearerToken, limit)));
|
||||
model.addAttribute("result", probeService.runProbe(new ProbeCommand(objectId, bearerToken, limit)));
|
||||
return "fragments/probe-result :: result";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.cloudhandson.vpdbackoffice.web;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.service.PermissionService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
@Controller
|
||||
public class RoleController {
|
||||
|
||||
private final PermissionService permissionService;
|
||||
|
||||
public RoleController(PermissionService permissionService) {
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
@GetMapping("/roles")
|
||||
public String roles(Model model) {
|
||||
model.addAttribute("roles", permissionService.findRoles());
|
||||
return "roles";
|
||||
}
|
||||
|
||||
@PostMapping("/roles")
|
||||
public String create(
|
||||
@RequestParam String roleName,
|
||||
@RequestParam(required = false) String description,
|
||||
RedirectAttributes redirectAttributes
|
||||
) {
|
||||
permissionService.createRole(roleName, description);
|
||||
redirectAttributes.addFlashAttribute("message", "역할을 추가했습니다.");
|
||||
return "redirect:/roles";
|
||||
}
|
||||
|
||||
@PostMapping("/roles/delete")
|
||||
public String delete(@RequestParam long roleId, RedirectAttributes redirectAttributes) {
|
||||
permissionService.deleteRole(roleId);
|
||||
redirectAttributes.addFlashAttribute("message", "역할을 삭제했습니다.");
|
||||
return "redirect:/roles";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user