fix(系统设置): 加载插件时,插件类型选择错误,导致平台插件功能异常

--bug=1025743 --user=陈建星 【系统设置】-服务集成-选择禅道-测试连接-无连接成功或失败的提示 https://www.tapd.cn/55049933/s/1368526
--bug=1025843 --user=陈建星 【系统设置】第三方平台插件上传-使用场景选择错误后修正上传成功,服务集成中测试连接失败 https://www.tapd.cn/55049933/s/1368528
This commit is contained in:
chenjianxing 2023-05-04 18:44:26 +08:00 committed by jianxing
parent 9891c37375
commit 3c9e39412c
4 changed files with 26 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import io.metersphere.commons.utils.FileUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.PluginResourceDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.plugin.core.api.UiScriptApi;
import io.metersphere.plugin.core.ui.PluginResource;
import io.metersphere.utils.CommonUtil;
@ -29,6 +30,8 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@Service
@Transactional(rollbackFor = Exception.class)
@ -61,6 +64,7 @@ public class ApiPluginService {
}
private boolean loadJar(String jarPath) {
validatePluginType(jarPath);
try {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
try {
@ -84,6 +88,22 @@ public class ApiPluginService {
return false;
}
/**
* 校验是否是平台插件,避免被系统类加载器加载后,无法卸载,影响功能
* @param jarPath
*/
private void validatePluginType(String jarPath) {
try {
JarFile jar = new JarFile(jarPath);
JarEntry entry = jar.getJarEntry("json/frontend.json");
if (entry != null) {
MSException.throwException(Translator.get("plugin_type_error"));
}
} catch (Exception e) {
LogUtil.error(e);
}
}
private List<PluginResourceDTO> getMethod(String path, String fileName) {
List<PluginResourceDTO> resources = new LinkedList<>();
try {

View File

@ -3,4 +3,5 @@ read_permission_file_fail=Failed to read permission file!
platform_plugin_not_exit=Platform docking function has been plug-in, please download the corresponding version of the plug-in:
workspace_name_exceeds_length_limit=Workspace name exceeds length limit
platform_plugin_exit=plugin is already exist!
plugin_parse_error=Plugin parse error
plugin_parse_error=Plugin parse error
plugin_type_error=Plugin type selection error!

View File

@ -3,4 +3,5 @@ read_permission_file_fail=读取权限文件失败!
platform_plugin_not_exit=平台对接功能已插件化,请下载对应版本的插件:
workspace_name_exceeds_length_limit=工作空间名称超出长度限制
platform_plugin_exit=插件已存在!
plugin_parse_error=插件解析失败
plugin_parse_error=插件解析失败
plugin_type_error=插件类型选择错误!

View File

@ -3,4 +3,5 @@ read_permission_file_fail=讀取權限文件失敗!
platform_plugin_not_exit=平臺對接功能已插件化,請下載對應版本的插件:
workspace_name_exceeds_length_limit=工作空間名稱超出長度限制
platform_plugin_exit=插件已存在!
plugin_parse_error=插件解析失敗!
plugin_parse_error=插件解析失敗!
plugin_type_error=插件類型選擇錯誤!