Procházet zdrojové kódy

web.mgr.machine 需要有 admin role 才可访问

reghao před 1 rokem
rodič
revize
069e66159b

+ 5 - 0
web/src/main/java/cn/reghao/devops/web/mgr/machine/controller/MachineHostController.java

@@ -10,6 +10,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
@@ -33,6 +34,7 @@ public class MachineHostController {
     }
 
     @ApiOperation(value = "设置机器环境")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @PostMapping(value = "/env/{machineId}", produces = MediaType.APPLICATION_JSON_VALUE)
     public ResponseEntity<String> editExtraMachineInfo(@PathVariable("machineId") String machineId,
                                                        @RequestParam("env") String env) {
@@ -41,6 +43,7 @@ public class MachineHostController {
     }
 
     @ApiOperation(value = "编辑 SSH 认证信息")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @PostMapping(value = "/sshauth/{machineId}", produces = MediaType.APPLICATION_JSON_VALUE)
     public ResponseEntity<String> editSshAuth(@PathVariable("machineId") String machineId, @Valid SshAuth sshAuth) {
         machineService.setMachineSshAuth(machineId, sshAuth);
@@ -48,6 +51,7 @@ public class MachineHostController {
     }
 
     @ApiOperation(value = "删除机器")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @DeleteMapping(value = "/{machineId}", produces = MediaType.APPLICATION_JSON_VALUE)
     public String machine(@PathVariable("machineId") String machineId) {
         if (machineQuery.isAgentOnline(machineId)) {
@@ -59,6 +63,7 @@ public class MachineHostController {
     }
 
     @ApiOperation(value = "设置机器为弃用状态")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @PostMapping(value = "/deprecate", produces = MediaType.APPLICATION_JSON_VALUE)
     public String deleteAll(@RequestParam(value = "ids") List<String> machineIds) {
         Result result = machineService.setMachinesDeprecate(machineIds);

+ 6 - 0
web/src/main/java/cn/reghao/devops/web/mgr/machine/controller/page/MachineHostPageController.java

@@ -18,6 +18,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -44,6 +45,7 @@ public class MachineHostPageController {
     }
 
     @ApiOperation(value = "机器节点页面")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @GetMapping
     public String indexPage(@RequestParam(value = "env", required = false) String env,
                            @RequestParam(value = "machineIpv4", required = false) String machineIpv4,
@@ -68,6 +70,7 @@ public class MachineHostPageController {
     }
 
     @ApiOperation(value = "机器所属环境设置页面")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @GetMapping("/env/{machineId}")
     public String hostEditPage(@PathVariable("machineId") String machineId, Model model) {
         List<KeyValue> envs = new ArrayList<>();
@@ -84,6 +87,7 @@ public class MachineHostPageController {
     }
 
     @ApiOperation(value = "SSH 认证设置页面")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @GetMapping("/sshauth/{machineId}")
     public String sshAuthPage(@PathVariable("machineId") String machineId, Model model) {
         MachineSshAuth machineSshAuth = machineQuery.getMachineSshAuth(machineId);
@@ -106,6 +110,7 @@ public class MachineHostPageController {
     }
 
     @ApiOperation(value = "SSH 控制台页面")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @GetMapping("/webssh/{machineId}")
     public String webSshPage(@PathVariable("machineId") String machineId, Model model) {
         MachineHost machineHost = machineQuery.getMachineHost(machineId);
@@ -128,6 +133,7 @@ public class MachineHostPageController {
     }
 
     @ApiOperation(value = "机器信息详情页面")
+    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @GetMapping("/detail/{machineId}")
     public String getMachineInfo(@PathVariable("machineId") String machineId, Model model) {
         MachineInfo machineInfo = machineQuery.getMachineInfo(machineId);