use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class PermissionInterceptor method checkNodeDataPermission.
/**
* 检查管理员权限
*
* @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;
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class PermissionInterceptor method addNode.
private void addNode(HttpServletRequest request) {
String nodeId = request.getParameter("nodeId");
if (!StrUtil.isBlankOrUndefined(nodeId)) {
// 节点信息
NodeModel nodeModel = nodeService.getByKey(nodeId);
if (nodeModel != null && !nodeModel.isOpenStatus()) {
throw new AgentException(nodeModel.getName() + "节点未启用");
}
request.setAttribute("node", nodeModel);
}
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class IndexControl method menusData.
/**
* @return json
* @api {post} menus_data.json 获取系统菜单相关数据
* @apiGroup index
* @apiUse loginUser
* @apiParam {String} nodeId 节点ID
* @apiSuccess {JSON} data 菜单相关字段
*/
@RequestMapping(value = "menus_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String menusData() {
NodeModel nodeModel = tryGetNode();
UserModel userModel = getUserModel();
String workspaceId = nodeService.getCheckUserWorkspace(getRequest());
JSONObject config = systemParametersServer.getConfigDefNewInstance(StrUtil.format("menus_config_{}", workspaceId), JSONObject.class);
// 菜单
InputStream inputStream;
JSONArray showArray;
if (nodeModel == null) {
inputStream = ResourceUtil.getStream("classpath:/menus/index.json");
showArray = config.getJSONArray("serverMenuKeys");
} else {
inputStream = ResourceUtil.getStream("classpath:/menus/node-index.json");
showArray = config.getJSONArray("nodeMenuKeys");
}
String json = IoUtil.read(inputStream, CharsetUtil.CHARSET_UTF_8);
JSONArray jsonArray = JSONArray.parseArray(json);
List<Object> collect1 = jsonArray.stream().filter(o -> {
JSONObject jsonObject = (JSONObject) o;
if (!testMenus(jsonObject, userModel, nodeModel, showArray)) {
return false;
}
JSONArray childs = jsonObject.getJSONArray("childs");
if (childs != null) {
List<Object> collect = childs.stream().filter(o1 -> {
JSONObject jsonObject1 = (JSONObject) o1;
return testMenus(jsonObject1, userModel, nodeModel, showArray);
}).collect(Collectors.toList());
if (collect.isEmpty()) {
return false;
}
jsonObject.put("childs", collect);
}
return true;
}).collect(Collectors.toList());
Assert.notEmpty(jsonArray, "没有任何菜单,请联系管理员");
return JsonMessage.getString(200, "", collect1);
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class ReleaseManage method diffSyncProject.
/**
* 差异上传发布
*
* @param nodeModel 节点
* @param projectId 项目ID
* @param afterOpt 发布后的操作
*/
private void diffSyncProject(NodeModel nodeModel, String projectId, AfterOpt afterOpt, boolean clearOld) {
File resultFile = this.resultFile;
String resultFileParent = resultFile.isFile() ? FileUtil.getAbsolutePath(resultFile.getParent()) : FileUtil.getAbsolutePath(this.resultFile);
//
List<File> files = FileUtil.loopFiles(resultFile);
List<JSONObject> collect = files.stream().map(file -> {
//
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", StringUtil.delStartPath(file, resultFileParent, true));
jsonObject.put("sha1", SecureUtil.sha1(file));
return jsonObject;
}).collect(Collectors.toList());
//
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", projectId);
jsonObject.put("data", collect);
JsonMessage<JSONObject> requestBody = NodeForward.requestBody(nodeModel, NodeUrl.MANAGE_FILE_DIFF_FILE, this.userModel, jsonObject);
if (requestBody.getCode() != HttpStatus.HTTP_OK) {
throw new JpomRuntimeException("对比项目文件失败:" + requestBody);
}
JSONObject data = requestBody.getData();
JSONArray diff = data.getJSONArray("diff");
JSONArray del = data.getJSONArray("del");
int delSize = CollUtil.size(del);
int diffSize = CollUtil.size(diff);
if (clearOld) {
logRecorder.info(StrUtil.format("对比文件结果,产物文件 {} 个、需要上传 {} 个、需要删除 {} 个", CollUtil.size(collect), CollUtil.size(diff), delSize));
} else {
logRecorder.info(StrUtil.format("对比文件结果,产物文件 {} 个、需要上传 {} 个", CollUtil.size(collect), CollUtil.size(diff)));
}
// 清空发布才先执行删除
if (delSize > 0 && clearOld) {
jsonObject.put("data", del);
requestBody = NodeForward.requestBody(nodeModel, NodeUrl.MANAGE_FILE_BATCH_DELETE, this.userModel, jsonObject);
if (requestBody.getCode() != HttpStatus.HTTP_OK) {
throw new JpomRuntimeException("删除项目文件失败:" + requestBody);
}
}
for (int i = 0; i < diffSize; i++) {
boolean last = (i == diffSize - 1);
JSONObject diffData = (JSONObject) diff.get(i);
String name = diffData.getString("name");
File file = FileUtil.file(resultFileParent, name);
//
String startPath = StringUtil.delStartPath(file, resultFileParent, false);
//
JsonMessage<String> jsonMessage = OutGivingRun.fileUpload(file, startPath, projectId, false, last ? afterOpt : AfterOpt.No, nodeModel, this.userModel, false);
if (jsonMessage.getCode() != HttpStatus.HTTP_OK) {
throw new JpomRuntimeException("同步项目文件失败:" + jsonMessage);
}
if (last) {
// 最后一个
logRecorder.info("发布项目包成功:" + jsonMessage);
}
}
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeForward method addUser.
/**
* 添加agent 授权信息header
*
* @param httpRequest request
* @param nodeModel 节点
* @param userModel 用户
*/
private static void addUser(HttpRequest httpRequest, NodeModel nodeModel, NodeUrl nodeUrl, UserModel userModel) {
// 判断开启状态
if (!nodeModel.isOpenStatus()) {
throw new AgentException(nodeModel.getName() + "节点未启用");
}
if (userModel != null) {
httpRequest.header(ConfigBean.JPOM_SERVER_USER_NAME, URLUtil.encode(userModel.getId()));
// httpRequest.header(ConfigBean.JPOM_SERVER_SYSTEM_USER_ROLE, userModel.getUserRole(nodeModel).name());
}
if (StrUtil.isEmpty(nodeModel.getLoginPwd())) {
NodeService nodeService = SpringUtil.getBean(NodeService.class);
NodeModel model = nodeService.getByKey(nodeModel.getId(), false);
nodeModel.setLoginPwd(model.getLoginPwd());
nodeModel.setLoginName(model.getLoginName());
}
httpRequest.header(ConfigBean.JPOM_AGENT_AUTHORIZE, nodeModel.toAuthorize());
httpRequest.header(Const.WORKSPACEID_REQ_HEADER, nodeModel.getWorkspaceId());
//
int timeOut = nodeModel.getTimeOut();
if (nodeUrl.getTimeOut() != -1 && timeOut > 0) {
//
timeOut = Math.max(timeOut, 2);
httpRequest.timeout(timeOut * 1000);
}
// 添加 http proxy
Proxy proxy = nodeModel.proxy();
httpRequest.setProxy(proxy);
}
Aggregations