diff --git a/modules/agent/src/main/java/io/jpom/controller/manage/ProjectFileControl.java b/modules/agent/src/main/java/io/jpom/controller/manage/ProjectFileControl.java index 672c61ec1..b5a594a26 100644 --- a/modules/agent/src/main/java/io/jpom/controller/manage/ProjectFileControl.java +++ b/modules/agent/src/main/java/io/jpom/controller/manage/ProjectFileControl.java @@ -299,15 +299,13 @@ public class ProjectFileControl extends BaseAgentController { return JsonMessage.getString(500, "删除失败:" + file.getAbsolutePath()); } else { // 删除文件 - String fileName = pathSafe(filename); - if (StrUtil.isEmpty(fileName)) { - return JsonMessage.getString(405, "非法操作"); - } + Assert.hasText(filename, "请选择要删除的文件"); + File file; if (StrUtil.isEmpty(levelName)) { - file = FileUtil.file(pim.allLib(), fileName); + file = FileUtil.file(pim.allLib(), filename); } else { - file = FileUtil.file(pim.allLib(), levelName, fileName); + file = FileUtil.file(pim.allLib(), levelName, filename); } if (file.exists()) { if (FileUtil.del(file)) { @@ -389,10 +387,11 @@ public class ProjectFileControl extends BaseAgentController { */ @GetMapping(value = "download", produces = MediaType.APPLICATION_JSON_VALUE) public String download(String id, String filename, String levelName) { - String safeFileName = pathSafe(filename); - if (StrUtil.isEmpty(safeFileName)) { - return JsonMessage.getString(405, "非法操作"); - } + Assert.hasText(filename, "请选择文件"); +// String safeFileName = pathSafe(filename); +// if (StrUtil.isEmpty(safeFileName)) { +// return JsonMessage.getString(405, "非法操作"); +// } try { NodeProjectInfoModel pim = projectInfoService.getItem(id); File file = FileUtil.file(pim.allLib(), StrUtil.emptyToDefault(levelName, FileUtil.FILE_SEPARATOR), filename); diff --git a/modules/agent/src/main/java/io/jpom/controller/manage/ProjectStatusController.java b/modules/agent/src/main/java/io/jpom/controller/manage/ProjectStatusController.java index 34c709979..e5cf8b5ff 100644 --- a/modules/agent/src/main/java/io/jpom/controller/manage/ProjectStatusController.java +++ b/modules/agent/src/main/java/io/jpom/controller/manage/ProjectStatusController.java @@ -25,7 +25,6 @@ package io.jpom.controller.manage; import cn.hutool.core.util.StrUtil; import cn.jiangzeyin.common.DefaultSystemLog; import cn.jiangzeyin.common.JsonMessage; -import cn.jiangzeyin.common.validator.ValidatorConfig; import cn.jiangzeyin.common.validator.ValidatorItem; import cn.jiangzeyin.common.validator.ValidatorRule; import com.alibaba.fastjson.JSONArray; @@ -68,7 +67,7 @@ public class ProjectStatusController extends BaseAgentController { * @return json */ @RequestMapping(value = "getProjectStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String getProjectStatus(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确")) String id, String getCopy) { + public String getProjectStatus(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确") String id, String getCopy) { NodeProjectInfoModel nodeProjectInfoModel = tryGetProjectInfoModel(); Assert.notNull(nodeProjectInfoModel, "项目id不存在"); int pid = 0; @@ -176,7 +175,7 @@ public class ProjectStatusController extends BaseAgentController { } @RequestMapping(value = "restart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String restart(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确")) String id, String copyId) { + public String restart(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确") String id, String copyId) { NodeProjectInfoModel item = projectInfoService.getItem(id); Assert.notNull(item, "没有找到对应的项目"); NodeProjectInfoModel.JavaCopyItem copyItem = item.findCopyItem(copyId); @@ -198,7 +197,7 @@ public class ProjectStatusController extends BaseAgentController { @RequestMapping(value = "stop", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String stop(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确")) String id, String copyId) { + public String stop(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确") String id, String copyId) { NodeProjectInfoModel item = projectInfoService.getItem(id); Assert.notNull(item, "没有找到对应的项目"); NodeProjectInfoModel.JavaCopyItem copyItem = item.findCopyItem(copyId); @@ -220,7 +219,7 @@ public class ProjectStatusController extends BaseAgentController { @RequestMapping(value = "start", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String start(@ValidatorConfig(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确")) String id, String copyId) { + public String start(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "项目id 不正确") String id, String copyId) { NodeProjectInfoModel item = projectInfoService.getItem(id); Assert.notNull(item, "没有找到对应的项目"); NodeProjectInfoModel.JavaCopyItem copyItem = item.findCopyItem(copyId); diff --git a/modules/agent/src/main/java/io/jpom/controller/manage/log/LogBackController.java b/modules/agent/src/main/java/io/jpom/controller/manage/log/LogBackController.java index d03f1457b..446adc7cf 100644 --- a/modules/agent/src/main/java/io/jpom/controller/manage/log/LogBackController.java +++ b/modules/agent/src/main/java/io/jpom/controller/manage/log/LogBackController.java @@ -23,7 +23,6 @@ package io.jpom.controller.manage.log; import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; import cn.jiangzeyin.common.DefaultSystemLog; import cn.jiangzeyin.common.JsonMessage; @@ -34,6 +33,7 @@ import io.jpom.common.commander.AbstractProjectCommander; import io.jpom.model.data.NodeProjectInfoModel; import io.jpom.util.FileUtils; import org.springframework.http.MediaType; +import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @@ -50,112 +50,106 @@ import java.io.File; @RequestMapping(value = "manage/log") public class LogBackController extends BaseAgentController { - @RequestMapping(value = "logSize", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String logSize(String id, String copyId) { - NodeProjectInfoModel nodeProjectInfoModel = getProjectInfoModel(); - JSONObject jsonObject = new JSONObject(); - // - NodeProjectInfoModel.JavaCopyItem copyItem = nodeProjectInfoModel.findCopyItem(copyId); - //获取日志备份路径 - File logBack = copyItem == null ? nodeProjectInfoModel.getLogBack() : nodeProjectInfoModel.getLogBack(copyItem); - boolean logBackBool = logBack.exists() && logBack.isDirectory(); - jsonObject.put("logBack", logBackBool); - String info = projectInfoService.getLogSize(nodeProjectInfoModel, copyItem); - jsonObject.put("logSize", info); - return JsonMessage.getString(200, "", jsonObject); - } + @RequestMapping(value = "logSize", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) + public String logSize(String id, String copyId) { + NodeProjectInfoModel nodeProjectInfoModel = getProjectInfoModel(); + JSONObject jsonObject = new JSONObject(); + // + NodeProjectInfoModel.JavaCopyItem copyItem = nodeProjectInfoModel.findCopyItem(copyId); + //获取日志备份路径 + File logBack = copyItem == null ? nodeProjectInfoModel.getLogBack() : nodeProjectInfoModel.getLogBack(copyItem); + boolean logBackBool = logBack.exists() && logBack.isDirectory(); + jsonObject.put("logBack", logBackBool); + String info = projectInfoService.getLogSize(nodeProjectInfoModel, copyItem); + jsonObject.put("logSize", info); + return JsonMessage.getString(200, "", jsonObject); + } - @RequestMapping(value = "resetLog", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String resetLog(String copyId) { - NodeProjectInfoModel pim = getProjectInfoModel(); - NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); - try { - String msg = AbstractProjectCommander.getInstance().backLog(pim, copyItem); - if (msg.contains("ok")) { - return JsonMessage.getString(200, "重置成功"); - } - return JsonMessage.getString(201, "重置失败:" + msg); - } catch (Exception e) { - DefaultSystemLog.getLog().error(e.getMessage(), e); - return JsonMessage.getString(500, "重置日志失败"); - } - } + @RequestMapping(value = "resetLog", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) + public String resetLog(String copyId) { + NodeProjectInfoModel pim = getProjectInfoModel(); + NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); + try { + String msg = AbstractProjectCommander.getInstance().backLog(pim, copyItem); + if (msg.contains("ok")) { + return JsonMessage.getString(200, "重置成功"); + } + return JsonMessage.getString(201, "重置失败:" + msg); + } catch (Exception e) { + DefaultSystemLog.getLog().error(e.getMessage(), e); + return JsonMessage.getString(500, "重置日志失败"); + } + } - @RequestMapping(value = "logBack_delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String clear(String name, String copyId) { - name = pathSafe(name); - if (StrUtil.isEmpty(name)) { - return JsonMessage.getString(405, "非法操作:" + name); - } - NodeProjectInfoModel pim = getProjectInfoModel(); - NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); - File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem); - if (logBack.exists() && logBack.isDirectory()) { - logBack = FileUtil.file(logBack, name); - if (logBack.exists()) { - FileUtil.del(logBack); - return JsonMessage.getString(200, "删除成功"); - } - return JsonMessage.getString(500, "没有对应文件"); - } else { - return JsonMessage.getString(500, "没有对应文件夹"); - } - } + @RequestMapping(value = "logBack_delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) + public String clear(String name, String copyId) { + Assert.hasText(name, "没有对应到文件"); + NodeProjectInfoModel pim = getProjectInfoModel(); + NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); + File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem); + if (logBack.exists() && logBack.isDirectory()) { + logBack = FileUtil.file(logBack, name); + if (logBack.exists()) { + FileUtil.del(logBack); + return JsonMessage.getString(200, "删除成功"); + } + return JsonMessage.getString(500, "没有对应文件"); + } else { + return JsonMessage.getString(500, "没有对应文件夹"); + } + } - @RequestMapping(value = "logBack_download", method = RequestMethod.GET) - public String download(String key, String copyId) { - key = pathSafe(key); - if (StrUtil.isEmpty(key)) { - return JsonMessage.getString(405, "非法操作"); - } - try { - NodeProjectInfoModel pim = getProjectInfoModel(); - NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); - File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem); - if (logBack.exists() && logBack.isDirectory()) { - logBack = FileUtil.file(logBack, key); - ServletUtil.write(getResponse(), logBack); - } else { - return "没有对应文件"; - } - } catch (Exception e) { - DefaultSystemLog.getLog().error("下载文件异常", e); - } - return "下载失败。请刷新页面后重试"; - } + @RequestMapping(value = "logBack_download", method = RequestMethod.GET) + public String download(String key, String copyId) { + Assert.hasText(key, "请选择对应到文件"); + try { + NodeProjectInfoModel pim = getProjectInfoModel(); + NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); + File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem); + if (logBack.exists() && logBack.isDirectory()) { + logBack = FileUtil.file(logBack, key); + ServletUtil.write(getResponse(), logBack); + } else { + return "没有对应文件"; + } + } catch (Exception e) { + DefaultSystemLog.getLog().error("下载文件异常", e); + } + return "下载失败。请刷新页面后重试"; + } - @RequestMapping(value = "logBack", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public String console(String copyId) { - // 查询项目路径 - NodeProjectInfoModel pim = getProjectInfoModel(); - NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); - JSONObject jsonObject = new JSONObject(); + @RequestMapping(value = "logBack", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) + public String console(String copyId) { + // 查询项目路径 + NodeProjectInfoModel pim = getProjectInfoModel(); + NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); + JSONObject jsonObject = new JSONObject(); - File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem); - if (logBack.exists() && logBack.isDirectory()) { - File[] filesAll = logBack.listFiles(); - if (filesAll != null) { - JSONArray jsonArray = FileUtils.parseInfo(filesAll, true, null); - jsonObject.put("array", jsonArray); - } - } - jsonObject.put("id", pim.getId()); - jsonObject.put("logPath", copyItem == null ? pim.getLog() : pim.getLog(copyItem)); - jsonObject.put("logBackPath", logBack.getAbsolutePath()); - return JsonMessage.getString(200, "", jsonObject); - } + File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem); + if (logBack.exists() && logBack.isDirectory()) { + File[] filesAll = logBack.listFiles(); + if (filesAll != null) { + JSONArray jsonArray = FileUtils.parseInfo(filesAll, true, null); + jsonObject.put("array", jsonArray); + } + } + jsonObject.put("id", pim.getId()); + jsonObject.put("logPath", copyItem == null ? pim.getLog() : pim.getLog(copyItem)); + jsonObject.put("logBackPath", logBack.getAbsolutePath()); + return JsonMessage.getString(200, "", jsonObject); + } - @RequestMapping(value = "export.html", method = RequestMethod.GET) - @ResponseBody - public String export(String copyId) { - NodeProjectInfoModel pim = getProjectInfoModel(); - NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); - File file = copyItem == null ? new File(pim.getLog()) : pim.getLog(copyItem); - if (!file.exists()) { - return JsonMessage.getString(400, "没有日志文件:" + file.getPath()); - } - HttpServletResponse response = getResponse(); - ServletUtil.write(response, file); - return JsonMessage.getString(200, ""); - } + @RequestMapping(value = "export.html", method = RequestMethod.GET) + @ResponseBody + public String export(String copyId) { + NodeProjectInfoModel pim = getProjectInfoModel(); + NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); + File file = copyItem == null ? new File(pim.getLog()) : pim.getLog(copyItem); + if (!file.exists()) { + return JsonMessage.getString(400, "没有日志文件:" + file.getPath()); + } + HttpServletResponse response = getResponse(); + ServletUtil.write(response, file); + return JsonMessage.getString(200, ""); + } } diff --git a/modules/agent/src/main/java/io/jpom/controller/system/NginxController.java b/modules/agent/src/main/java/io/jpom/controller/system/NginxController.java index 20e8f8c6a..030a21b75 100644 --- a/modules/agent/src/main/java/io/jpom/controller/system/NginxController.java +++ b/modules/agent/src/main/java/io/jpom/controller/system/NginxController.java @@ -84,8 +84,7 @@ public class NginxController extends BaseAgentController { if (StrUtil.isEmpty(name)) { name = StrUtil.SLASH; } - String newName = pathSafe(name); - JSONArray array = nginxService.list(whitePath, newName); + JSONArray array = nginxService.list(whitePath, name); return JsonMessage.getString(200, "", array); } @@ -242,12 +241,9 @@ public class NginxController extends BaseAgentController { if (!whitelistDirectoryService.checkNgxDirectory(path)) { return JsonMessage.getString(400, "非法操作"); } - String safePath = pathSafe(path); - String safeName = pathSafe(name); - if (StrUtil.isEmpty(safeName)) { - return JsonMessage.getString(400, "删除失败,请正常操作"); - } - File file = FileUtil.file(safePath, safeName); + Assert.hasText(name, "请选择文件"); + + File file = FileUtil.file(path, name); try { FileUtil.rename(file, file.getName() + "_back", false, true); } catch (Exception e) { diff --git a/modules/agent/src/main/java/io/jpom/service/system/NginxService.java b/modules/agent/src/main/java/io/jpom/service/system/NginxService.java index 0a325bfbc..78560698c 100644 --- a/modules/agent/src/main/java/io/jpom/service/system/NginxService.java +++ b/modules/agent/src/main/java/io/jpom/service/system/NginxService.java @@ -41,7 +41,6 @@ import io.jpom.util.JsonFileUtil; import io.jpom.util.StringUtil; import org.springframework.stereotype.Service; -import javax.annotation.Resource; import java.io.File; import java.io.IOException; import java.util.HashSet; @@ -53,8 +52,11 @@ import java.util.List; @Service public class NginxService extends BaseDataService { - @Resource - private WhitelistDirectoryService whitelistDirectoryService; + private final WhitelistDirectoryService whitelistDirectoryService; + + public NginxService(WhitelistDirectoryService whitelistDirectoryService) { + this.whitelistDirectoryService = whitelistDirectoryService; + } public JSONArray list(String whitePath, String fileName) { AgentWhitelist agentWhitelist = whitelistDirectoryService.getWhitelist(); diff --git a/modules/server/src/main/java/io/jpom/common/interceptor/PermissionInterceptor.java b/modules/server/src/main/java/io/jpom/common/interceptor/PermissionInterceptor.java index 0d213ceb7..5abf6e3c8 100644 --- a/modules/server/src/main/java/io/jpom/common/interceptor/PermissionInterceptor.java +++ b/modules/server/src/main/java/io/jpom/common/interceptor/PermissionInterceptor.java @@ -29,12 +29,16 @@ import cn.jiangzeyin.common.JsonMessage; import cn.jiangzeyin.common.interceptor.InterceptorPattens; import cn.jiangzeyin.common.spring.SpringUtil; import io.jpom.common.BaseServerController; +import io.jpom.model.BaseNodeModel; import io.jpom.model.data.NodeModel; import io.jpom.model.data.UserModel; +import io.jpom.permission.NodeDataPermission; import io.jpom.permission.SystemPermission; import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; +import io.jpom.service.h2db.BaseNodeService; import io.jpom.service.node.NodeService; +import io.jpom.service.user.UserBindWorkspaceService; import io.jpom.system.AgentException; import org.springframework.http.MediaType; import org.springframework.web.method.HandlerMethod; @@ -52,6 +56,10 @@ import javax.servlet.http.HttpServletResponse; public class PermissionInterceptor extends BaseJpomInterceptor { private NodeService nodeService; + private UserBindWorkspaceService userBindWorkspaceService; + /** + * demo 账号不能使用的功能 + */ private static final MethodFeature[] DEMO = new MethodFeature[]{ MethodFeature.DEL, MethodFeature.UPLOAD, @@ -63,6 +71,9 @@ public class PermissionInterceptor extends BaseJpomInterceptor { if (nodeService == null) { nodeService = SpringUtil.getBean(NodeService.class); } + if (userBindWorkspaceService == null) { + userBindWorkspaceService = SpringUtil.getBean(UserBindWorkspaceService.class); + } } private SystemPermission getSystemPermission(HandlerMethod handlerMethod) { @@ -73,17 +84,30 @@ public class PermissionInterceptor extends BaseJpomInterceptor { return systemPermission; } + private NodeDataPermission getNodeDataPermission(HandlerMethod handlerMethod) { + NodeDataPermission nodeDataPermission = handlerMethod.getMethodAnnotation(NodeDataPermission.class); + if (nodeDataPermission == null) { + nodeDataPermission = handlerMethod.getBeanType().getAnnotation(NodeDataPermission.class); + } + return nodeDataPermission; + } + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { this.init(); this.addNode(request); UserModel userModel = BaseServerController.getUserModel(); if (userModel == null || userModel.isSuperSystemUser()) { - // 没有登录、或者超级管理自己放过 + // 没有登录、或者超级管理直接放过 return true; } - boolean systemPermission = this.checkSystemPermission(userModel, response, handlerMethod); - if (!systemPermission) { + // + boolean permission = this.checkSystemPermission(userModel, response, handlerMethod); + if (!permission) { + return false; + } + permission = this.checkNodeDataPermission(userModel, request, response, handlerMethod); + if (!permission) { return false; } Feature feature = handlerMethod.getMethodAnnotation(Feature.class); @@ -98,8 +122,47 @@ public class PermissionInterceptor extends BaseJpomInterceptor { return true; } - private boolean checkSystemPermission(UserModel userModel, HttpServletResponse response, HandlerMethod handlerMethod) { + /** + * 检查管理员权限 + * + * @param userModel 用户 + * @param response 响应 + * @param handlerMethod 拦截到到方法 + * @return true 有权限 + */ + private boolean checkNodeDataPermission(UserModel userModel, HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) { + NodeDataPermission nodeDataPermission = this.getNodeDataPermission(handlerMethod); + if (nodeDataPermission == null || userModel.isSuperSystemUser()) { + return true; + } + NodeModel node = (NodeModel) request.getAttribute("node"); + if (node != null) { + String parameterName = nodeDataPermission.parameterName(); + BaseNodeService baseNodeService = SpringUtil.getBean(nodeDataPermission.cls()); + String dataId = request.getParameter(parameterName); + if (StrUtil.isNotEmpty(dataId)) { + BaseNodeModel data = baseNodeService.getData(node.getId(), dataId); + if (data != null) { + boolean exists = userBindWorkspaceService.exists(userModel.getId(), data.getWorkspaceId()); + if (!exists) { + this.errorMsg(response, "你没有对应到数据权限:-3"); + return false; + } + } + } + } + return true; + } + /** + * 检查管理员权限 + * + * @param userModel 用户 + * @param response 响应 + * @param handlerMethod 拦截到到方法 + * @return true 有权限 + */ + private boolean checkSystemPermission(UserModel userModel, HttpServletResponse response, HandlerMethod handlerMethod) { SystemPermission systemPermission = this.getSystemPermission(handlerMethod); if (systemPermission == null) { return true; diff --git a/modules/server/src/main/java/io/jpom/controller/node/manage/EditProjectController.java b/modules/server/src/main/java/io/jpom/controller/node/manage/EditProjectController.java index 1e397490c..3ac6705aa 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/manage/EditProjectController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/manage/EditProjectController.java @@ -8,6 +8,7 @@ import io.jpom.common.BaseServerController; import io.jpom.common.forward.NodeForward; import io.jpom.common.forward.NodeUrl; import io.jpom.model.data.NodeModel; +import io.jpom.permission.NodeDataPermission; import io.jpom.plugin.ClassFeature; import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; @@ -16,12 +17,10 @@ import io.jpom.service.system.WhitelistDirectoryService; import io.jpom.system.ConfigBean; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -import javax.annotation.Resource; import java.util.List; /** @@ -30,34 +29,35 @@ import java.util.List; * @author jiangzeyin * @date 2018/9/29 */ -@Controller +@RestController @RequestMapping(value = "/node/manage/") @Feature(cls = ClassFeature.PROJECT) +@NodeDataPermission(cls = ProjectInfoCacheService.class) public class EditProjectController extends BaseServerController { private final ProjectInfoCacheService projectInfoCacheService; - @Resource - private WhitelistDirectoryService whitelistDirectoryService; + private final WhitelistDirectoryService whitelistDirectoryService; - public EditProjectController(ProjectInfoCacheService projectInfoCacheService) { + public EditProjectController(ProjectInfoCacheService projectInfoCacheService, + WhitelistDirectoryService whitelistDirectoryService) { this.projectInfoCacheService = projectInfoCacheService; + this.whitelistDirectoryService = whitelistDirectoryService; } @RequestMapping(value = "getProjectData.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody public String getProjectData(@ValidatorItem String id) { JSONObject projectInfo = projectInfoCacheService.getItem(getNode(), id); return JsonMessage.getString(200, "", projectInfo); } /** - * @return - * @author Hotstrip * get project access list * 获取项目的白名单 + * + * @return json + * @author Hotstrip */ @RequestMapping(value = "project-access-list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody public String projectAccessList() { List jsonArray = whitelistDirectoryService.getProjectDirectory(getNode()); return JsonMessage.getString(200, "success", jsonArray); @@ -70,7 +70,6 @@ public class EditProjectController extends BaseServerController { * @return json */ @RequestMapping(value = "saveProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(method = MethodFeature.EDIT) public String saveProject(String id) { // 防止和Jpom冲突 @@ -92,7 +91,6 @@ public class EditProjectController extends BaseServerController { * @return json */ @RequestMapping(value = "judge_lib.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody public String saveProject() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_Jude_Lib).toString(); } diff --git a/modules/server/src/main/java/io/jpom/controller/node/manage/ProjectManageControl.java b/modules/server/src/main/java/io/jpom/controller/node/manage/ProjectManageControl.java index 9e327fb26..c1601b690 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/manage/ProjectManageControl.java +++ b/modules/server/src/main/java/io/jpom/controller/node/manage/ProjectManageControl.java @@ -12,6 +12,7 @@ import io.jpom.model.data.NodeModel; import io.jpom.model.data.OutGivingModel; import io.jpom.model.data.ProjectInfoModel; import io.jpom.model.enums.BuildReleaseMethod; +import io.jpom.permission.NodeDataPermission; import io.jpom.plugin.ClassFeature; import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; @@ -34,6 +35,7 @@ import java.util.List; @RestController @RequestMapping(value = "/node/manage/") @Feature(cls = ClassFeature.PROJECT) +@NodeDataPermission(cls = ProjectInfoCacheService.class) public class ProjectManageControl extends BaseServerController { private final OutGivingServer outGivingServer; @@ -58,7 +60,6 @@ public class ProjectManageControl extends BaseServerController { */ @RequestMapping(value = "project_copy_list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Feature(method = MethodFeature.LIST) - @ResponseBody public String projectCopyList() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_ProjectCopyList).toString(); } @@ -69,7 +70,6 @@ public class ProjectManageControl extends BaseServerController { * @return json */ @RequestMapping(value = "getProjectPort", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody public String getProjectPort() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_GetProjectPort).toString(); } @@ -80,7 +80,6 @@ public class ProjectManageControl extends BaseServerController { * @return json */ @RequestMapping(value = "getProjectCopyPort", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody public String getProjectCopyPort() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_GetProjectCopyPort).toString(); } @@ -142,7 +141,6 @@ public class ProjectManageControl extends BaseServerController { * @return json */ @RequestMapping(value = "restart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(method = MethodFeature.EXECUTE) public String restart() { NodeModel nodeModel = getNode(); @@ -158,7 +156,6 @@ public class ProjectManageControl extends BaseServerController { * @return json */ @RequestMapping(value = "start", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(method = MethodFeature.EXECUTE) public String start() { NodeModel nodeModel = getNode(); @@ -174,7 +171,6 @@ public class ProjectManageControl extends BaseServerController { * @return json */ @RequestMapping(value = "stop", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(method = MethodFeature.EXECUTE) public String stop() { NodeModel nodeModel = getNode(); diff --git a/modules/server/src/main/java/io/jpom/controller/node/manage/file/ProjectFileControl.java b/modules/server/src/main/java/io/jpom/controller/node/manage/file/ProjectFileControl.java index 06435baac..064bd83b1 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/manage/file/ProjectFileControl.java +++ b/modules/server/src/main/java/io/jpom/controller/node/manage/file/ProjectFileControl.java @@ -3,6 +3,7 @@ package io.jpom.controller.node.manage.file; import io.jpom.common.BaseServerController; import io.jpom.common.forward.NodeForward; import io.jpom.common.forward.NodeUrl; +import io.jpom.permission.NodeDataPermission; import io.jpom.plugin.ClassFeature; import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; @@ -18,22 +19,15 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping(value = "/node/manage/file/") @Feature(cls = ClassFeature.PROJECT_FILE) +@NodeDataPermission(cls = ProjectInfoCacheService.class) public class ProjectFileControl extends BaseServerController { - private final ProjectInfoCacheService projectInfoService; - - public ProjectFileControl(ProjectInfoCacheService projectInfoService) { - this.projectInfoService = projectInfoService; - } - /** * 列出目录下的文件 * * @return json */ @RequestMapping(value = "getFileList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - // @ProjectPermission() @Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.LIST) public String getFileList() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_GetFileList).toString(); @@ -46,7 +40,6 @@ public class ProjectFileControl extends BaseServerController { * @return json */ @RequestMapping(value = "upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.UPLOAD) public String upload() { return NodeForward.requestMultipart(getNode(), getMultiRequest(), NodeUrl.Manage_File_Upload).toString(); @@ -56,7 +49,6 @@ public class ProjectFileControl extends BaseServerController { * 下载文件 */ @RequestMapping(value = "download", method = RequestMethod.GET) - @ResponseBody @Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.DOWNLOAD) public void download() { NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.Manage_File_Download); @@ -68,7 +60,6 @@ public class ProjectFileControl extends BaseServerController { * @return json */ @RequestMapping(value = "deleteFile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.DEL) public String deleteFile() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_DeleteFile).toString(); @@ -81,7 +72,6 @@ public class ProjectFileControl extends BaseServerController { * @return json */ @PostMapping(value = "update_config_file", produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.EDIT) public String updateConfigFile() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_UpdateConfigFile).toString(); @@ -93,7 +83,6 @@ public class ProjectFileControl extends BaseServerController { * @return json */ @GetMapping(value = "read_file", produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.LIST) public String readFile() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_ReadFile).toString(); @@ -108,22 +97,5 @@ public class ProjectFileControl extends BaseServerController { @Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.REMOTE_DOWNLOAD) public String remoteDownload() { return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_Remote_Download).toString(); - } - - -// /** -// * 获取可编辑文件格式 -// * -// * @return json -// */ -// @RequestMapping(value = "geFileFormat", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// @Feature(method = MethodFeature.GET_FILE_FOMAT) -// public String geFileFormat() { -// String[] file = fileFormat.split("\\|"); -// JSONObject jsonObject = new JSONObject(); -// jsonObject.put("fileFormat", file); -// return JsonMessage.getString(200, "获取成功", jsonObject); -// } } diff --git a/modules/server/src/main/java/io/jpom/controller/node/manage/log/LogBackController.java b/modules/server/src/main/java/io/jpom/controller/node/manage/log/LogBackController.java index f78183c74..98e29030c 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/manage/log/LogBackController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/manage/log/LogBackController.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; import io.jpom.common.BaseServerController; import io.jpom.common.forward.NodeForward; import io.jpom.common.forward.NodeUrl; +import io.jpom.permission.NodeDataPermission; import io.jpom.plugin.ClassFeature; import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; @@ -24,6 +25,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping(value = "node/manage/log") @Feature(cls = ClassFeature.PROJECT_LOG) +@NodeDataPermission(cls = ProjectInfoCacheService.class) public class LogBackController extends BaseServerController { private final ProjectInfoCacheService projectInfoCacheService; diff --git a/modules/server/src/main/java/io/jpom/controller/node/script/ScriptController.java b/modules/server/src/main/java/io/jpom/controller/node/script/ScriptController.java index 39fdaac6c..93b6e8915 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/script/ScriptController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/script/ScriptController.java @@ -7,6 +7,7 @@ import io.jpom.common.forward.NodeUrl; import io.jpom.model.PageResultDto; import io.jpom.model.data.NodeModel; import io.jpom.model.data.ScriptModel; +import io.jpom.permission.NodeDataPermission; import io.jpom.plugin.ClassFeature; import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; @@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping(value = "/node/script") @Feature(cls = ClassFeature.NODE_SCRIPT) +@NodeDataPermission(cls = ScriptServer.class) public class ScriptController extends BaseServerController { private final ScriptServer scriptServer; diff --git a/modules/server/src/main/java/io/jpom/controller/user/role/UserRoleDynamicController.java b/modules/server/src/main/java/io/jpom/controller/user/role/UserRoleDynamicController.java deleted file mode 100644 index c23361a89..000000000 --- a/modules/server/src/main/java/io/jpom/controller/user/role/UserRoleDynamicController.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 Code Technology Studio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -///* -// * The MIT License (MIT) -// * -// * Copyright (c) 2019 码之科技工作室 -// * -// * Permission is hereby granted, free of charge, to any person obtaining a copy of -// * this software and associated documentation files (the "Software"), to deal in -// * the Software without restriction, including without limitation the rights to -// * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// * the Software, and to permit persons to whom the Software is furnished to do so, -// * subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included in all -// * copies or substantial portions of the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// */ -//package io.jpom.controller.user.role; -// -//import cn.hutool.core.collection.CollUtil; -//import cn.jiangzeyin.common.JsonMessage; -//import cn.jiangzeyin.common.spring.SpringUtil; -//import com.alibaba.fastjson.JSONArray; -//import com.alibaba.fastjson.JSONObject; -//import io.jpom.common.BaseServerController; -//import io.jpom.common.interceptor.OptLog; -//import io.jpom.model.data.RoleModel; -//import io.jpom.model.log.UserOperateLogV1; -//import io.jpom.permission.BaseDynamicService; -//import io.jpom.permission.DynamicData; -//import io.jpom.plugin.ClassFeature; -//import io.jpom.plugin.Feature; -//import io.jpom.plugin.MethodFeature; -//import io.jpom.service.user.RoleService; -//import org.springframework.http.MediaType; -//import org.springframework.stereotype.Controller; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RequestMethod; -//import org.springframework.web.bind.annotation.ResponseBody; -// -//import javax.annotation.Resource; -//import java.util.ArrayList; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -//import java.util.function.Predicate; -//import java.util.stream.Collectors; -// -///** -// * @author bwcx_jzy -// * @date 2019/8/15 -// */ -//@Controller -//@RequestMapping(value = "/user/role") -//@Feature(cls = ClassFeature.USER_ROLE) -//public class UserRoleDynamicController extends BaseServerController { -// -// @Resource -// private RoleService roleService; -// -//// @RequestMapping(value = "dynamicData.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE) -//// @Feature(method = MethodFeature.EDIT) -//// public String list() { -//// Map dynamicDataMap = DynamicData.getDynamicDataMap(); -//// setAttribute("dynamicDataMap", dynamicDataMap); -//// return "user/role/dynamicData"; -//// } -// -// /** -// * @return -// * @author Hotstrip -// * load role dynamic data -// * 加载角色的动态资源数据 -// */ -// @RequestMapping(value = "dynamic-list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// public String roleDynamicData() { -// Map dynamicDataMap = DynamicData.getDynamicDataMap(); -// List> list = new ArrayList<>(); -// dynamicDataMap.keySet().forEach(key -> { -// HashMap valueMap = new HashMap<>(); -// valueMap.put("id", key.name()); -// valueMap.put("name", key.getName()); -// if (key.getParent() != null) { -// valueMap.put("parent", key.getParent().name()); -// } -// list.add(valueMap); -// }); -// return JsonMessage.getString(200, "success", list); -// } -// -// @RequestMapping(value = "getDynamic.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// @Feature(method = MethodFeature.EDIT) -// public String getDynamic(String id, String dynamic) { -// ClassFeature classFeature = ClassFeature.valueOf(dynamic); -// JSONArray jsonArray = roleService.listDynamic(id, classFeature, null); -// return JsonMessage.getString(200, "", jsonArray); -// } -// -// @RequestMapping(value = "saveDynamic.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// @Feature(method = MethodFeature.EDIT) -// @OptLog(value = UserOperateLogV1.OptType.EditRole) -// public String saveDynamic(String id, String dynamic) { -// RoleModel item = roleService.getItem(id); -// if (item == null) { -// return JsonMessage.getString(404, "角色信息错误"); -// } -// // -// JSONObject jsonObject = JSONObject.parseObject(dynamic); -// Map> dynamicData1 = new HashMap<>(jsonObject.keySet().size()); -// // -// List root = DynamicData.getRoot(); -// for (ClassFeature classFeature : root) { -// JSONArray value = jsonObject.getJSONArray(classFeature.name()); -// if (value == null || value.isEmpty()) { -// continue; -// } -// DynamicData dynamicData = DynamicData.getDynamicData(classFeature); -// if (dynamicData == null) { -// return JsonMessage.getString(404, classFeature.getName() + "没有配置对应动态数据"); -// } -// Class baseOperService = dynamicData.getBaseOperService(); -// BaseDynamicService bean = SpringUtil.getBean(baseOperService); -// List list = bean.parserValue(classFeature, value); -// if (CollUtil.isEmpty(list)) { -// continue; -// } -// if (classFeature.getParent() != null) { -// list = list.stream().filter(treeLevel -> CollUtil.isNotEmpty(treeLevel.getChildren())).collect(Collectors.toList()); -// } -// dynamicData1.put(classFeature, list); -// } -// item.setDynamicData2(dynamicData1); -// roleService.updateItem(item); -// return JsonMessage.getString(200, "保存成功"); -// } -//} diff --git a/modules/server/src/main/java/io/jpom/controller/user/role/UserRoleListController.java b/modules/server/src/main/java/io/jpom/controller/user/role/UserRoleListController.java deleted file mode 100644 index b2be1eed9..000000000 --- a/modules/server/src/main/java/io/jpom/controller/user/role/UserRoleListController.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 Code Technology Studio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -///* -// * The MIT License (MIT) -// * -// * Copyright (c) 2019 码之科技工作室 -// * -// * Permission is hereby granted, free of charge, to any person obtaining a copy of -// * this software and associated documentation files (the "Software"), to deal in -// * the Software without restriction, including without limitation the rights to -// * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// * the Software, and to permit persons to whom the Software is furnished to do so, -// * subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included in all -// * copies or substantial portions of the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// */ -//package io.jpom.controller.user.role; -// -//import cn.hutool.core.util.BooleanUtil; -//import cn.hutool.core.util.IdUtil; -//import cn.hutool.core.util.StrUtil; -//import cn.jiangzeyin.common.JsonMessage; -//import cn.jiangzeyin.common.validator.ValidatorItem; -//import cn.jiangzeyin.common.validator.ValidatorRule; -//import com.alibaba.fastjson.JSONArray; -//import com.alibaba.fastjson.JSONObject; -//import io.jpom.common.BaseServerController; -//import io.jpom.common.interceptor.OptLog; -//import io.jpom.model.data.RoleModel; -//import io.jpom.model.data.UserModel; -//import io.jpom.model.log.UserOperateLogV1; -//import io.jpom.permission.CacheControllerFeature; -//import io.jpom.plugin.ClassFeature; -//import io.jpom.plugin.Feature; -//import io.jpom.plugin.MethodFeature; -//import io.jpom.service.user.RoleService; -//import io.jpom.service.user.UserService; -//import org.springframework.http.MediaType; -//import org.springframework.stereotype.Controller; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RequestMethod; -//import org.springframework.web.bind.annotation.ResponseBody; -// -//import javax.annotation.Resource; -//import java.util.*; -// -///** -// * 用户权限基本管理 -// * -// * @author bwcx_jzy -// * @date 2019/8/15 -// */ -//@Controller -//@RequestMapping(value = "/user/role") -//@Feature(cls = ClassFeature.USER_ROLE) -//public class UserRoleListController extends BaseServerController { -// -// @Resource -// private RoleService roleService; -// private final UserService userService; -// -// public UserRoleListController(UserService userService) { -// this.userService = userService; -// } -// -//// @RequestMapping(value = "list.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE) -//// @Feature(method = MethodFeature.LIST) -//// public String list() { -//// return "user/role/list"; -//// } -// -//// @RequestMapping(value = "edit.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE) -//// @Feature(method = MethodFeature.EDIT) -//// public String edit(String id) { -//// if (StrUtil.isNotEmpty(id)) { -//// RoleModel item = roleService.getItem(id); -//// setAttribute("item", item); -//// } -//// return "user/role/edit"; -//// } -// -// -// /** -// * 查询所有用户 -// * -// * @return json -// */ -// @RequestMapping(value = "list_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// @Feature(method = MethodFeature.LIST) -// public String listData() { -// List list = roleService.list(); -// if (list != null) { -// // 统计用户角色信息 -// List userList = userService.list(); -// Map roleCount = new HashMap<>(list.size()); -// if (userList != null) { -// userList.forEach(userModel -> { -// Set roles = userModel.getRoles(); -// if (roles == null) { -// return; -// } -// roles.forEach(s -> { -// Integer integer = roleCount.computeIfAbsent(s, s1 -> 0); -// roleCount.put(s, integer + 1); -// }); -// }); -// } -// list.forEach(roleModel -> { -// Integer integer = roleCount.get(roleModel.getId()); -// if (integer == null) { -// integer = 0; -// } -// roleModel.setBindCount(integer); -// }); -// } -// return JsonMessage.getString(200, "", list); -// } -// -// @RequestMapping(value = "getFeature.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// @Feature(method = MethodFeature.EDIT) -// public String getFeature(String id) { -// // -// RoleModel item = roleService.getItem(id); -// -// Map> featureMap = CacheControllerFeature.getFeatureMap(); -// Set>> entries = featureMap.entrySet(); -// JSONArray jsonArray = new JSONArray(); -// entries.forEach(classFeatureSetEntry -> { -// ClassFeature classFeature = classFeatureSetEntry.getKey(); -// JSONObject jsonObject = new JSONObject(); -// jsonObject.put("title", classFeature.getName()); -// jsonObject.put("id", classFeature.name()); -// Set value = classFeatureSetEntry.getValue(); -// JSONArray children = new JSONArray(); -// value.forEach(methodFeature -> { -// JSONObject cJson = new JSONObject(); -// cJson.put("title", methodFeature.getName()); -// cJson.put("id", classFeature.name() + "_" + methodFeature.name()); -// // -// if (item != null) { -// List methodFeature1 = item.getMethodFeature(classFeature); -// if (methodFeature1 != null && methodFeature1.contains(methodFeature)) { -// cJson.put("checked", true); -// } -// } -// children.add(cJson); -// }); -// jsonObject.put("children", children); -// jsonObject.put("spread", true); -// jsonArray.add(jsonObject); -// }); -// return JsonMessage.getString(200, "", jsonArray); -// } -// -// @RequestMapping(value = "save.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// @Feature(method = MethodFeature.EDIT) -// @OptLog(value = UserOperateLogV1.OptType.EditRole) -// public String save(String id, -// @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "请输入角色名称") String name, -// @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "请输入选择权限") String feature, -// String canAdd) { -// JSONArray jsonArray = JSONArray.parseArray(feature); -// RoleModel item = roleService.getItem(id); -// if (item == null) { -// item = new RoleModel(); -// item.setId(IdUtil.fastSimpleUUID()); -// } -// item.setName(name); -// List roleFeatures = new ArrayList<>(); -// jsonArray.forEach(o -> { -// JSONObject jsonObject = (JSONObject) o; -// JSONArray children = jsonObject.getJSONArray("children"); -// if (children == null || children.isEmpty()) { -// return; -// } -// String id1 = jsonObject.getString("id"); -// ClassFeature classFeature = ClassFeature.valueOf(id1); -// RoleModel.RoleFeature roleFeature = new RoleModel.RoleFeature(); -// roleFeature.setFeature(classFeature); -// roleFeatures.add(roleFeature); -// // -// List methodFeatures = new ArrayList<>(); -// children.forEach(o1 -> { -// JSONObject childrenItem = (JSONObject) o1; -// String id11 = childrenItem.getString("id"); -// id11 = id11.substring(id1.length() + 1); -// MethodFeature methodFeature = MethodFeature.valueOf(id11); -// methodFeatures.add(methodFeature); -// }); -// roleFeature.setMethodFeatures(methodFeatures); -// }); -// item.setCanAdd(BooleanUtil.toBoolean(canAdd)); -// item.setFeatures(roleFeatures); -// // -// if (StrUtil.isNotEmpty(id)) { -// roleService.updateItem(item); -// } else { -// roleService.addItem(item); -// } -// return JsonMessage.getString(200, "操作成功"); -// } -// -// @RequestMapping(value = "del.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) -// @ResponseBody -// @Feature(method = MethodFeature.DEL) -// @OptLog(value = UserOperateLogV1.OptType.DelRole) -// public String del(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id) { -// List userList = userService.list(); -// if (userList != null) { -// for (UserModel userModel : userList) { -// Set roles = userModel.getRoles(); -// if (roles == null) { -// continue; -// } -// if (roles.contains(id)) { -// return JsonMessage.getString(100, "当前角色存在关联用户不能删除"); -// } -// } -// } -// roleService.deleteItem(id); -// return JsonMessage.getString(200, "删除成功"); -// } -//} diff --git a/modules/server/src/main/java/io/jpom/permission/NodeDataPermission.java b/modules/server/src/main/java/io/jpom/permission/NodeDataPermission.java new file mode 100644 index 000000000..215c5f67f --- /dev/null +++ b/modules/server/src/main/java/io/jpom/permission/NodeDataPermission.java @@ -0,0 +1,30 @@ +package io.jpom.permission; + +import io.jpom.service.h2db.BaseNodeService; + +import java.lang.annotation.*; + +/** + * @author bwcx_jzy + * @since 2021/12/23 + */ + +@Documented +@Target({ElementType.METHOD, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface NodeDataPermission { + + /** + * 参数名 + * + * @return 默认ID + */ + String parameterName() default "id"; + + /** + * 数据 class + * + * @return cls + */ + Class> cls(); +} diff --git a/modules/server/src/main/java/io/jpom/plugin/ThymeleafUtil.java b/modules/server/src/main/java/io/jpom/plugin/ThymeleafUtil.java deleted file mode 100644 index 84bb75b12..000000000 --- a/modules/server/src/main/java/io/jpom/plugin/ThymeleafUtil.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 Code Technology Studio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -//package io.jpom.plugin; -// -//import cn.hutool.core.io.FileUtil; -//import cn.jiangzeyin.common.spring.SpringUtil; -//import io.jpom.common.BaseServerController; -//import io.jpom.common.interceptor.LoginInterceptor; -//import io.jpom.model.data.UserModel; -//import org.springframework.context.annotation.Configuration; -//import org.thymeleaf.context.Context; -//import org.thymeleaf.spring5.SpringTemplateEngine; -// -//import javax.annotation.Resource; -//import java.util.HashMap; -//import java.util.Map; -// -///** -// * 模板工具 -// * -// * @author bwcx_jzy -// * @date 2019/8/13 -// */ -//@Configuration -//public class ThymeleafUtil { -// /** -// * 页面变量 -// */ -// public static final String PAGE_VARIABLE = "pagePluginHtml"; -// -// @Resource -// private SpringTemplateEngine springTemplateEngine; -// -// /** -// * 模板名称需要在 classpath:templates/plugin 下 -// * -// * @param template 模板名称 -// * @param variables 变量 -// * @return 转换后的 -// */ -// public static String process(String template, Map variables) { -// Context context = new Context(); -// if (variables == null) { -// variables = new HashMap<>(10); -// } -// String normalize = FileUtil.normalize("plugin/" + template); -// // 用户变量 -// UserModel userModel = BaseServerController.getUserModel(); -// variables.put(LoginInterceptor.SESSION_NAME, userModel); -// context.setVariables(variables); -// ThymeleafUtil thymeleafUtil = SpringUtil.getBean(ThymeleafUtil.class); -// return thymeleafUtil.springTemplateEngine.process(normalize, context); -// } -//} diff --git a/modules/server/src/main/java/io/jpom/service/h2db/BaseNodeService.java b/modules/server/src/main/java/io/jpom/service/h2db/BaseNodeService.java index 87394c7b0..122884746 100644 --- a/modules/server/src/main/java/io/jpom/service/h2db/BaseNodeService.java +++ b/modules/server/src/main/java/io/jpom/service/h2db/BaseNodeService.java @@ -238,7 +238,12 @@ public abstract class BaseNodeService extends BaseWorks }); } - + /** + * 填充数据ID + * + * @param item 对象 + * @param nodeModel 节点 + */ private void fullData(T item, NodeModel nodeModel) { item.dataId(item.getId()); item.setId(null); @@ -264,6 +269,20 @@ public abstract class BaseNodeService extends BaseWorks return super.del(entity); } + /** + * 根据 节点和数据ID查询数据 + * + * @param nodeId 节点ID + * @param dataId 数据ID + * @return data + */ + public T getData(String nodeId, String dataId) { + T data = ReflectUtil.newInstance(this.tClass); + data.setNodeId(nodeId); + data.dataId(dataId); + return super.queryByBean(data); + } + /** * 查询远端项目 * diff --git a/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java b/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java index db085c5aa..cfb6cf9e2 100644 --- a/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java +++ b/modules/server/src/main/java/io/jpom/service/h2db/BaseWorkspaceService.java @@ -31,7 +31,6 @@ import io.jpom.common.BaseServerController; import io.jpom.common.Const; import io.jpom.model.BaseWorkspaceModel; import io.jpom.model.PageResultDto; -import io.jpom.model.data.UserBindWorkspaceModel; import io.jpom.model.data.UserModel; import io.jpom.service.user.UserBindWorkspaceService; import org.springframework.util.Assert; @@ -172,10 +171,8 @@ public abstract class BaseWorkspaceService extends return; } // 查询绑定的权限 - UserBindWorkspaceModel workspaceModel = new UserBindWorkspaceModel(); - workspaceModel.setId(UserBindWorkspaceModel.getId(userModel.getId(), workspaceId)); UserBindWorkspaceService userBindWorkspaceService = SpringUtil.getBean(UserBindWorkspaceService.class); - boolean exists = userBindWorkspaceService.exists(workspaceModel); + boolean exists = userBindWorkspaceService.exists(userModel.getId(), workspaceId); Assert.state(exists, "没有对应的工作空间权限"); } diff --git a/modules/server/src/main/java/io/jpom/service/user/UserBindWorkspaceService.java b/modules/server/src/main/java/io/jpom/service/user/UserBindWorkspaceService.java index 92e74fd64..fdb000cae 100644 --- a/modules/server/src/main/java/io/jpom/service/user/UserBindWorkspaceService.java +++ b/modules/server/src/main/java/io/jpom/service/user/UserBindWorkspaceService.java @@ -129,4 +129,17 @@ public class UserBindWorkspaceService extends BaseDbService