use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class WorkspaceController method delete.
/**
* 删除工作空间
*
* @param id 工作空间 ID
* @return json
*/
@GetMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
@SystemPermission(superUser = true)
public Object delete(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "数据 id 不能为空") String id) {
//
Assert.state(!StrUtil.equals(id, Const.WORKSPACE_DEFAULT_ID), "不能删除默认工作空间");
// 判断是否存在关联数据
Set<Class<?>> classes = ClassUtil.scanPackage("io.jpom.model", BaseWorkspaceModel.class::isAssignableFrom);
StringBuilder autoDelete = new StringBuilder(StrUtil.EMPTY);
for (Class<?> aClass : classes) {
TableName tableName = aClass.getAnnotation(TableName.class);
if (tableName == null) {
continue;
}
if (aClass == UserOperateLogV1.class) {
// 用户操作日志
String sql = "delete from " + tableName.value() + " where workspaceId=?";
int execute = workspaceService.execute(sql, id);
if (execute > 0) {
autoDelete.append(StrUtil.format(" 自动删除 {} 表中数据 {} 条数据", execute));
}
continue;
}
String sql = "select count(1) as cnt from " + tableName.value() + " where workspaceId=?";
List<Entity> query = workspaceService.query(sql, id);
Entity first = CollUtil.getFirst(query);
if (first != null) {
Assert.notEmpty(first, "没有对应的用户信息");
Integer cnt = first.getInt("cnt");
Assert.state(cnt == null || cnt <= 0, "当前工作空间下还存在关联数据:" + tableName.name());
}
}
// 判断用户绑定关系
boolean workspace = userBindWorkspaceService.existsWorkspace(id);
Assert.state(!workspace, "当前工作空间下还绑定着用户信息");
// 删除信息
workspaceService.delByKey(id);
return JsonMessage.toJson(200, "删除成功 " + autoDelete);
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class OutGivingWhitelistController method whitelistDirectorySubmit.
/**
* 保存节点白名单
*
* @param outGiving 数据
* @return json
*/
@RequestMapping(value = "whitelistDirectory_submit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission
@Feature(method = MethodFeature.EDIT)
public String whitelistDirectorySubmit(String outGiving, String allowRemoteDownloadHost) {
List<String> list = AgentWhitelist.parseToList(outGiving, true, "项目路径白名单不能为空");
list = AgentWhitelist.covertToArray(list, "项目路径白名单不能位于Jpom目录下");
ServerWhitelist serverWhitelist = outGivingWhitelistService.getServerWhitelistData(getRequest());
serverWhitelist.setOutGiving(list);
//
List<String> allowRemoteDownloadHostList = AgentWhitelist.parseToList(allowRemoteDownloadHost, "运行远程下载的 host 不能配置为空");
//
if (CollUtil.isNotEmpty(allowRemoteDownloadHostList)) {
for (String s : allowRemoteDownloadHostList) {
Assert.state(ReUtil.isMatch(RegexPool.URL_HTTP, s), "配置的远程地址不规范,请重新填写:" + s);
}
}
serverWhitelist.setAllowRemoteDownloadHost(allowRemoteDownloadHostList == null ? null : CollUtil.newHashSet(allowRemoteDownloadHostList));
//
String workspaceId = nodeService.getCheckUserWorkspace(getRequest());
String id = ServerWhitelist.workspaceId(workspaceId);
systemParametersServer.upsert(id, serverWhitelist, id);
String resultData = AgentWhitelist.convertToLine(list);
return JsonMessage.getString(200, "保存成功", resultData);
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class SshInstallAgentController method uploadAgent.
@RequestMapping(value = "upload_agent.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
@SystemPermission
public String uploadAgent() throws Exception {
ServerConfigBean instance = ServerConfigBean.getInstance();
String tempFilePath = instance.getUserTempPath().getAbsolutePath();
MultipartFileBuilder multipartFileBuilder = createMultipart().setFileExt("zip").addFieldName("file").setSavePath(tempFilePath);
String filePath = multipartFileBuilder.save();
File tempAgent = FileUtil.file(tempFilePath, "temp_agent");
FileUtil.del(tempAgent);
// 解析压缩包
File jarFile = JpomManifest.zipFileFind(filePath, Type.Agent, FileUtil.getAbsolutePath(tempAgent));
// 验证文件是否正确
JsonMessage<Tuple> tupleJsonMessage = JpomManifest.checkJpomJar(FileUtil.getAbsolutePath(jarFile), Type.Agent, false);
Assert.state(tupleJsonMessage.getCode() == 200, tupleJsonMessage::getMsg);
//
File outFle = FileUtil.file(tempFilePath, Type.Agent.name() + "_" + IdUtil.fastSimpleUUID());
try {
this.unZipGetTag(filePath, outFle);
// 保存插件包
File agentZipPath = instance.getAgentZipPath();
FileUtil.copy(FileUtil.file(filePath), agentZipPath, true);
return JsonMessage.getString(200, "上传成功");
} finally {
FileUtil.del(filePath);
FileUtil.del(jarFile);
}
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class NodeUpdateController method uploadAgent.
@RequestMapping(value = "upload_agent", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission
@Feature(method = MethodFeature.UPLOAD)
public String uploadAgent() throws IOException {
String saveDir = ServerConfigBean.getInstance().getAgentPath().getAbsolutePath();
MultipartFileBuilder multipartFileBuilder = createMultipart();
multipartFileBuilder.setFileExt("jar", "zip").addFieldName("file").setUseOriginalFilename(true).setSavePath(saveDir);
String path = multipartFileBuilder.save();
// 解析压缩包
File file = JpomManifest.zipFileFind(path, Type.Agent, saveDir);
path = FileUtil.getAbsolutePath(file);
// 基础检查
JsonMessage<Tuple> error = JpomManifest.checkJpomJar(path, Type.Agent, false);
if (error.getCode() != HttpStatus.HTTP_OK) {
FileUtil.del(path);
return error.toString();
}
// 保存文件
this.saveAgentFile(error.getData());
return JsonMessage.getString(200, "上传成功");
}
use of io.jpom.permission.SystemPermission in project Jpom by dromara.
the class ServerWebSocketInterceptor method checkPermission.
/**
* 检查权限
*
* @param userInfo 用户
* @param attributes 属性
* @param handlerType 功能类型
* @return 错误消息
*/
private String checkPermission(UserModel userInfo, Map<String, Object> attributes, HandlerType handlerType) {
if (userInfo.isSuperSystemUser()) {
return StrUtil.EMPTY;
}
if (userInfo.isDemoUser()) {
return PermissionInterceptor.DEMO_TIP;
}
if (handlerType == HandlerType.nodeUpdate) {
return "您没有对应功能【" + ClassFeature.NODE_UPGRADE.getName() + "】管理权限";
}
Object dataItem = attributes.get("dataItem");
Object nodeInfo = attributes.get("nodeInfo");
String workspaceId = BeanUtil.getProperty(dataItem == null ? nodeInfo : dataItem, "workspaceId");
// ? : BeanUtil.getProperty(dataItem, "workspaceId");
//
attributes.put("workspaceId", workspaceId);
Class<?> handlerClass = handlerType.getHandlerClass();
SystemPermission systemPermission = handlerClass.getAnnotation(SystemPermission.class);
if (systemPermission != null) {
if (!userInfo.isSuperSystemUser()) {
return "您没有对应功能【" + ClassFeature.NODE_UPGRADE.getName() + "】管理权限";
}
}
Feature feature = handlerClass.getAnnotation(Feature.class);
MethodFeature method = feature.method();
ClassFeature cls = feature.cls();
UserBindWorkspaceService userBindWorkspaceService = SpringUtil.getBean(UserBindWorkspaceService.class);
boolean exists = userBindWorkspaceService.exists(userInfo.getId(), workspaceId + StrUtil.DASHED + method.name());
if (exists) {
return StrUtil.EMPTY;
}
return "您没有对应功能【" + cls.getName() + "-" + method.getName() + "】管理权限";
}
Aggregations