use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class CertModel method decodeCert.
/**
* 解析证书
*
* @param key zip里面文件
* @param file 证书文件
* @return 处理后的json
*/
public static JSONObject decodeCert(String file, String key) {
if (file == null) {
return null;
}
if (!FileUtil.exist(file)) {
return null;
}
InputStream inputStream = null;
try {
inputStream = ResourceUtil.getStream(key);
PrivateKey privateKey = PemUtil.readPemPrivateKey(inputStream);
IoUtil.close(inputStream);
inputStream = ResourceUtil.getStream(file);
PublicKey publicKey = PemUtil.readPemPublicKey(inputStream);
IoUtil.close(inputStream);
RSA rsa = new RSA(privateKey, publicKey);
String encryptStr = rsa.encryptBase64(KEY, KeyType.PublicKey);
String decryptStr = rsa.decryptStr(encryptStr, KeyType.PrivateKey);
if (!KEY.equals(decryptStr)) {
throw new JpomRuntimeException("证书和私钥证书不匹配");
}
} finally {
IoUtil.close(inputStream);
}
try {
inputStream = ResourceUtil.getStream(file);
// 创建证书对象
X509Certificate oCert = (X509Certificate) KeyUtil.readX509Certificate(inputStream);
// 到期时间
Date expirationTime = oCert.getNotAfter();
// 生效日期
Date effectiveTime = oCert.getNotBefore();
// 域名
String name = oCert.getSubjectDN().getName();
int i = name.indexOf("=");
String domain = name.substring(i + 1);
JSONObject jsonObject = new JSONObject();
jsonObject.put("expirationTime", expirationTime.getTime());
jsonObject.put("effectiveTime", effectiveTime.getTime());
jsonObject.put("domain", domain);
jsonObject.put("pemPath", file);
jsonObject.put("keyPath", key);
return jsonObject;
} catch (Exception e) {
DefaultSystemLog.getLog().error(e.getMessage(), e);
} finally {
IoUtil.close(inputStream);
}
return null;
}
use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class NodeProjectInfoModel method repairWhitelist.
private void repairWhitelist() {
if (StrUtil.isEmpty(whitelistDirectory) && StrUtil.isEmpty(lib)) {
throw new JpomRuntimeException("当前项目lib数据异常");
}
if (StrUtil.isNotEmpty(whitelistDirectory)) {
return;
}
WhitelistDirectoryService whitelistDirectoryService = SpringUtil.getBean(WhitelistDirectoryService.class);
List<String> project = whitelistDirectoryService.getWhitelist().getProject();
for (String path : project) {
if (lib.startsWith(path)) {
String itemWhitelistDirectory = lib.substring(0, path.length());
lib = lib.substring(path.length());
setWhitelistDirectory(itemWhitelistDirectory);
setLib(lib);
}
}
}
use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class JsonFileUtil method readJson.
/**
* 读取json 文件,同步
*
* @param path 路径
* @return JSON
* @throws FileNotFoundException 文件异常
*/
public static JSON readJson(String path) throws FileNotFoundException {
File file = new File(path);
if (!file.exists()) {
throw new FileNotFoundException("没有找到对应配置文件:" + path);
}
READ_LOCK.lock();
// 防止多线程操作文件异常
try {
String json = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
if (StrUtil.isEmpty(json)) {
return new JSONObject();
}
try {
return (JSON) JSON.parse(json);
} catch (Exception e) {
throw new JpomRuntimeException("数据文件内容错误,请检查文件是否被非法修改:" + path, e);
}
} finally {
READ_LOCK.unlock();
}
}
use of io.jpom.system.JpomRuntimeException 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.system.JpomRuntimeException in project Jpom by dromara.
the class RepositoryController method editRepository.
/**
* edit
*
* @param repositoryModelReq 仓库实体
* @return json
*/
@PostMapping(value = "/build/repository/edit")
@Feature(method = MethodFeature.EDIT)
public Object editRepository(RepositoryModel repositoryModelReq) {
this.checkInfo(repositoryModelReq);
// 检查 rsa 私钥
boolean andUpdateSshKey = this.checkAndUpdateSshKey(repositoryModelReq);
Assert.state(andUpdateSshKey, "rsa 私钥文件不存在或者有误");
if (repositoryModelReq.getRepoType() == RepositoryModel.RepoType.Git.getCode()) {
RepositoryModel repositoryModel = repositoryService.getByKey(repositoryModelReq.getId(), false);
if (repositoryModel != null) {
repositoryModelReq.setRsaPrv(StrUtil.emptyToDefault(repositoryModelReq.getRsaPrv(), repositoryModel.getRsaPrv()));
repositoryModelReq.setPassword(StrUtil.emptyToDefault(repositoryModelReq.getPassword(), repositoryModel.getPassword()));
}
// 验证 git 仓库信息
try {
IPlugin plugin = PluginFactory.getPlugin("git-clone");
Map<String, Object> map = repositoryModelReq.toMap();
Tuple branchAndTagList = (Tuple) plugin.execute("branchAndTagList", map);
// Tuple tuple = GitUtil.getBranchAndTagList(repositoryModelReq);
} catch (JpomRuntimeException jpomRuntimeException) {
throw jpomRuntimeException;
} catch (Exception e) {
DefaultSystemLog.getLog().warn("获取仓库分支失败", e);
return JsonMessage.toJson(500, "无法连接此仓库," + e.getMessage());
}
}
if (StrUtil.isEmpty(repositoryModelReq.getId())) {
// insert data
repositoryService.insert(repositoryModelReq);
} else {
// update data
// repositoryModelReq.setWorkspaceId(repositoryService.getCheckUserWorkspace(getRequest()));
repositoryService.updateById(repositoryModelReq, getRequest());
}
return JsonMessage.toJson(200, "操作成功");
}
Aggregations