@@ -0,0 +1,16 @@
|
||||
package com.cloudhandson.vpdbackoffice.web;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.service.AppException;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
@ControllerAdvice
|
||||
public class AppExceptionHandler {
|
||||
|
||||
@ExceptionHandler(AppException.class)
|
||||
public String handleAppException(AppException exception, Model model) {
|
||||
model.addAttribute("errorMessage", exception.getMessage());
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.cloudhandson.vpdbackoffice.web;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.service.BearerTokenService;
|
||||
import com.cloudhandson.vpdbackoffice.service.PermissionService;
|
||||
import com.cloudhandson.vpdbackoffice.service.ProtectedObjectService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class DashboardController {
|
||||
|
||||
private final ProtectedObjectService protectedObjectService;
|
||||
private final PermissionService permissionService;
|
||||
private final BearerTokenService bearerTokenService;
|
||||
|
||||
public DashboardController(
|
||||
ProtectedObjectService protectedObjectService,
|
||||
PermissionService permissionService,
|
||||
BearerTokenService bearerTokenService
|
||||
) {
|
||||
this.protectedObjectService = protectedObjectService;
|
||||
this.permissionService = permissionService;
|
||||
this.bearerTokenService = bearerTokenService;
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public String dashboard(Model model) {
|
||||
model.addAttribute("objects", protectedObjectService.findEnabled());
|
||||
model.addAttribute("roles", permissionService.findRoles());
|
||||
model.addAttribute("tokens", bearerTokenService.findAll());
|
||||
return "dashboard";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.cloudhandson.vpdbackoffice.web;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.PermissionSetCommand;
|
||||
import com.cloudhandson.vpdbackoffice.domain.permission.RuleCommand;
|
||||
import com.cloudhandson.vpdbackoffice.service.PermissionService;
|
||||
import com.cloudhandson.vpdbackoffice.service.ProtectedObjectService;
|
||||
import java.util.List;
|
||||
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 PermissionController {
|
||||
|
||||
private final PermissionService permissionService;
|
||||
private final ProtectedObjectService protectedObjectService;
|
||||
|
||||
public PermissionController(
|
||||
PermissionService permissionService,
|
||||
ProtectedObjectService protectedObjectService
|
||||
) {
|
||||
this.permissionService = permissionService;
|
||||
this.protectedObjectService = protectedObjectService;
|
||||
}
|
||||
|
||||
@GetMapping("/permissions")
|
||||
public String permissions(Model model) {
|
||||
model.addAttribute("roles", permissionService.findRoles());
|
||||
model.addAttribute("objects", protectedObjectService.findEnabled());
|
||||
return "permissions";
|
||||
}
|
||||
|
||||
@PostMapping("/permissions")
|
||||
public String save(
|
||||
@RequestParam long roleId,
|
||||
@RequestParam long objectId,
|
||||
@RequestParam String ruleType,
|
||||
@RequestParam(required = false) String ruleValue,
|
||||
@RequestParam(required = false) List<String> visibleColumns,
|
||||
RedirectAttributes redirectAttributes
|
||||
) {
|
||||
permissionService.savePermissionSet(new PermissionSetCommand(
|
||||
roleId,
|
||||
objectId,
|
||||
"SELECT",
|
||||
List.of(new RuleCommand(ruleType, ruleValue)),
|
||||
visibleColumns == null ? List.of() : visibleColumns
|
||||
));
|
||||
redirectAttributes.addFlashAttribute("message", "권한을 저장했습니다.");
|
||||
return "redirect:/permissions";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
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;
|
||||
|
||||
@Controller
|
||||
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)));
|
||||
return "fragments/probe-result :: result";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.cloudhandson.vpdbackoffice.web;
|
||||
|
||||
import com.cloudhandson.vpdbackoffice.domain.token.TokenIssueCommand;
|
||||
import com.cloudhandson.vpdbackoffice.mapper.UserMapper;
|
||||
import com.cloudhandson.vpdbackoffice.service.BearerTokenService;
|
||||
import java.time.OffsetDateTime;
|
||||
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 TokenController {
|
||||
|
||||
private final BearerTokenService tokenService;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
public TokenController(BearerTokenService tokenService, UserMapper userMapper) {
|
||||
this.tokenService = tokenService;
|
||||
this.userMapper = userMapper;
|
||||
}
|
||||
|
||||
@GetMapping("/tokens")
|
||||
public String tokens(Model model) {
|
||||
model.addAttribute("tokens", tokenService.findAll());
|
||||
model.addAttribute("users", userMapper.findAll());
|
||||
return "tokens";
|
||||
}
|
||||
|
||||
@PostMapping("/tokens")
|
||||
public String issue(
|
||||
@RequestParam long userId,
|
||||
@RequestParam String expiresAt,
|
||||
@RequestParam(required = false) String description,
|
||||
RedirectAttributes redirectAttributes
|
||||
) {
|
||||
var issued = tokenService.issueToken(new TokenIssueCommand(
|
||||
userId,
|
||||
OffsetDateTime.parse(expiresAt),
|
||||
description
|
||||
));
|
||||
redirectAttributes.addFlashAttribute("issued", issued);
|
||||
return "redirect:/tokens";
|
||||
}
|
||||
|
||||
@PostMapping("/tokens/revoke")
|
||||
public String revoke(
|
||||
@RequestParam long keyId,
|
||||
@RequestParam(required = false) String reason,
|
||||
RedirectAttributes redirectAttributes
|
||||
) {
|
||||
tokenService.revokeToken(keyId, reason);
|
||||
redirectAttributes.addFlashAttribute("message", "토큰을 회수했습니다.");
|
||||
return "redirect:/tokens";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user