refactor: 统一规范
This commit is contained in:
parent
31d073b81d
commit
23c8b1dc5d
|
@ -21,7 +21,7 @@ public enum CustomFieldType {
|
||||||
RICH_TEXT(false),
|
RICH_TEXT(false),
|
||||||
CASCADING_SELECT(false);
|
CASCADING_SELECT(false);
|
||||||
|
|
||||||
private Boolean hasOption;
|
private final Boolean hasOption;
|
||||||
|
|
||||||
CustomFieldType(Boolean hasOption) {
|
CustomFieldType(Boolean hasOption) {
|
||||||
this.hasOption = hasOption;
|
this.hasOption = hasOption;
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
package io.metersphere.sdk.constants;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ElementConstants {
|
|
||||||
public static final String HASH_TREE = "hashTree";
|
|
||||||
public static final String CLAZZ_NAME = "clazzName";
|
|
||||||
public static final String SCENARIO = "scenario";
|
|
||||||
public static final String SCENARIO_UPPER = "SCENARIO";
|
|
||||||
public static final String HTTP_SAMPLER = "HTTPSamplerProxy";
|
|
||||||
public static final String TCP_SAMPLER = "TCPSampler";
|
|
||||||
public static final String DUBBO_SAMPLER = "DubboSampler";
|
|
||||||
public static final String JDBC_SAMPLER = "JDBCSampler";
|
|
||||||
public static final String JSR223 = "JSR223Processor";
|
|
||||||
public static final String JSR223_PRE = "JSR223PreProcessor";
|
|
||||||
public static final String JSR223_POST = "JSR223PostProcessor";
|
|
||||||
public static final String JDBC_PRE = "JDBCPreProcessor";
|
|
||||||
public static final String JDBC_POST = "JDBCPostProcessor";
|
|
||||||
public static final String JMETER_ELE = "JmeterElement";
|
|
||||||
public static final String TEST_PLAN = "TestPlan";
|
|
||||||
public static final String THREAD_GROUP = "ThreadGroup";
|
|
||||||
public static final String DNS_CACHE = "DNSCacheManager";
|
|
||||||
public static final String DEBUG_SAMPLER = "DebugSampler";
|
|
||||||
public static final String AUTH_MANAGER = "AuthManager";
|
|
||||||
public static final String ABS_SAMPLER = "AbstractSampler";
|
|
||||||
public static final String IF_CONTROLLER = "IfController";
|
|
||||||
public static final String TRANSACTION_CONTROLLER = "TransactionController";
|
|
||||||
public static final String LOOP_CONTROLLER = "LoopController";
|
|
||||||
public static final String CONSTANT_TIMER = "ConstantTimer";
|
|
||||||
public static final String ASSERTIONS = "Assertions";
|
|
||||||
public static final String EXTRACT = "Extract";
|
|
||||||
public static final String STEP_CREATED = "Created";
|
|
||||||
public static final String INDEX = "index";
|
|
||||||
public static final String ID = "id";
|
|
||||||
public static final String REF_ENABLE = "refEnable";
|
|
||||||
|
|
||||||
public final static List<String> REQUESTS = new ArrayList<String>() {{
|
|
||||||
this.add(ElementConstants.HTTP_SAMPLER);
|
|
||||||
this.add(ElementConstants.DUBBO_SAMPLER);
|
|
||||||
this.add(ElementConstants.JDBC_SAMPLER);
|
|
||||||
this.add(ElementConstants.TCP_SAMPLER);
|
|
||||||
this.add(ElementConstants.JSR223);
|
|
||||||
this.add(ElementConstants.JSR223_PRE);
|
|
||||||
this.add(ElementConstants.JSR223_POST);
|
|
||||||
this.add(ElementConstants.JDBC_PRE);
|
|
||||||
this.add(ElementConstants.JDBC_POST);
|
|
||||||
this.add(ElementConstants.JMETER_ELE);
|
|
||||||
this.add(ElementConstants.TEST_PLAN);
|
|
||||||
this.add(ElementConstants.THREAD_GROUP);
|
|
||||||
this.add(ElementConstants.DNS_CACHE);
|
|
||||||
this.add(ElementConstants.DEBUG_SAMPLER);
|
|
||||||
this.add(ElementConstants.AUTH_MANAGER);
|
|
||||||
this.add(ElementConstants.ABS_SAMPLER);
|
|
||||||
}};
|
|
||||||
|
|
||||||
public static final String SCRIPT = "script";
|
|
||||||
public static final String BEANSHELL = "beanshell";
|
|
||||||
public static final String IS_REF = "isRef";
|
|
||||||
public static final String FILE_ID = "fileId";
|
|
||||||
|
|
||||||
public static final String RESOURCE_ID = "resourceId";
|
|
||||||
public static final String FILENAME = "filename";
|
|
||||||
public static final String COVER = "COVER";
|
|
||||||
public static final String MS_KEYSTORE_FILE_PATH = "MS-KEYSTORE-FILE-PATH";
|
|
||||||
public static final String MS_KEYSTORE_FILE_PASSWORD = "MS-KEYSTORE-FILE-PASSWORD";
|
|
||||||
public static final String VIRTUAL_STEPS = "VIRTUAL_STEPS";
|
|
||||||
public static final String REF = "$ref";
|
|
||||||
public static final String TYPE = "type";
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +1,5 @@
|
||||||
package io.metersphere.sdk.constants;
|
package io.metersphere.sdk.constants;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public enum HttpMethodConstants {
|
public enum HttpMethodConstants {
|
||||||
GET,
|
GET,
|
||||||
HEAD,
|
HEAD,
|
||||||
|
@ -11,29 +8,5 @@ public enum HttpMethodConstants {
|
||||||
PATCH,
|
PATCH,
|
||||||
DELETE,
|
DELETE,
|
||||||
OPTIONS,
|
OPTIONS,
|
||||||
TRACE;
|
TRACE
|
||||||
|
|
||||||
private static final Map<String, HttpMethodConstants> mappings = new HashMap(16);
|
|
||||||
|
|
||||||
private HttpMethodConstants() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HttpMethodConstants resolve(String method) {
|
|
||||||
return method != null ? (HttpMethodConstants) mappings.get(method) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(String method) {
|
|
||||||
return this.name().equals(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
HttpMethodConstants[] var0 = values();
|
|
||||||
int var1 = var0.length;
|
|
||||||
|
|
||||||
for (int var2 = 0; var2 < var1; ++var2) {
|
|
||||||
HttpMethodConstants HttpMethodConstants = var0[var2];
|
|
||||||
mappings.put(HttpMethodConstants.name(), HttpMethodConstants);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package io.metersphere.sdk.constants;
|
|
||||||
|
|
||||||
public class KafkaPluginTopicType {
|
|
||||||
public static final String ADD = "ADD";
|
|
||||||
public static final String DELETE = "DELETE";
|
|
||||||
}
|
|
|
@ -2,4 +2,9 @@ package io.metersphere.sdk.constants;
|
||||||
|
|
||||||
public class KafkaTopicConstants {
|
public class KafkaTopicConstants {
|
||||||
public static final String PLUGIN = "PLUGIN";
|
public static final String PLUGIN = "PLUGIN";
|
||||||
|
|
||||||
|
public static class TYPE{
|
||||||
|
public static final String ADD = "ADD";
|
||||||
|
public static final String DELETE = "DELETE";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package io.metersphere.sdk.constants;
|
|
||||||
|
|
||||||
public class RequestTypeConstants {
|
|
||||||
|
|
||||||
public static final String HTTP = "HTTP";
|
|
||||||
|
|
||||||
public static final String DUBBO = "DUBBO";
|
|
||||||
|
|
||||||
public static final String SQL = "SQL";
|
|
||||||
|
|
||||||
public static final String TCP = "TCP";
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
package io.metersphere.sdk.constants;
|
package io.metersphere.sdk.constants;
|
||||||
|
|
||||||
public enum StorageType {
|
public enum StorageType {
|
||||||
MINIO, GIT, FILE_REF, LOCAL
|
MINIO, GIT, LOCAL
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package io.metersphere.sdk.constants;
|
||||||
public enum UserRoleEnum {
|
public enum UserRoleEnum {
|
||||||
GLOBAL("global");
|
GLOBAL("global");
|
||||||
|
|
||||||
private String value;
|
private final String value;
|
||||||
|
|
||||||
UserRoleEnum(String value) {
|
UserRoleEnum(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package io.metersphere.sdk.dto;
|
package io.metersphere.sdk.dto;
|
||||||
|
|
||||||
import io.metersphere.sdk.util.RsaKey;
|
import io.metersphere.sdk.util.RsaKey;
|
||||||
import io.metersphere.sdk.util.RsaUtil;
|
import io.metersphere.sdk.util.RsaUtils;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -21,8 +21,8 @@ public class LoginRequest {
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
try {
|
try {
|
||||||
RsaKey rsaKey = RsaUtil.getRsaKey();
|
RsaKey rsaKey = RsaUtils.getRsaKey();
|
||||||
return RsaUtil.privateDecrypt(username, rsaKey.getPrivateKey());
|
return RsaUtils.privateDecrypt(username, rsaKey.getPrivateKey());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ public class LoginRequest {
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
try {
|
try {
|
||||||
RsaKey rsaKey = RsaUtil.getRsaKey();
|
RsaKey rsaKey = RsaUtils.getRsaKey();
|
||||||
return RsaUtil.privateDecrypt(password, rsaKey.getPrivateKey());
|
return RsaUtils.privateDecrypt(password, rsaKey.getPrivateKey());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package io.metersphere.sdk.dto;
|
package io.metersphere.sdk.dto;
|
||||||
|
|
||||||
import io.metersphere.sdk.util.CodingUtil;
|
import io.metersphere.sdk.util.CodingUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
@ -29,7 +29,7 @@ public class SessionUser extends UserDTO implements Serializable {
|
||||||
BeanUtils.copyProperties(user, sessionUser);
|
BeanUtils.copyProperties(user, sessionUser);
|
||||||
|
|
||||||
List<String> infos = Arrays.asList(user.getId(), RandomStringUtils.randomAlphabetic(6), sessionId, StringUtils.EMPTY + System.currentTimeMillis());
|
List<String> infos = Arrays.asList(user.getId(), RandomStringUtils.randomAlphabetic(6), sessionId, StringUtils.EMPTY + System.currentTimeMillis());
|
||||||
sessionUser.csrfToken = CodingUtil.aesEncrypt(StringUtils.join(infos, "|"), secret, iv);
|
sessionUser.csrfToken = CodingUtils.aesEncrypt(StringUtils.join(infos, "|"), secret, iv);
|
||||||
sessionUser.sessionId = sessionId;
|
sessionUser.sessionId = sessionId;
|
||||||
return sessionUser;
|
return sessionUser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.security.MessageDigest;
|
||||||
*
|
*
|
||||||
* @author kun.mo
|
* @author kun.mo
|
||||||
*/
|
*/
|
||||||
public class CodingUtil {
|
public class CodingUtils {
|
||||||
|
|
||||||
private static final String UTF_8 = "UTF-8";
|
private static final String UTF_8 = "UTF-8";
|
||||||
|
|
|
@ -3,7 +3,7 @@ package io.metersphere.sdk.util;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class EncryptUtils extends CodingUtil {
|
public class EncryptUtils extends CodingUtils {
|
||||||
|
|
||||||
private static final String secretKey = "www.fit2cloud.co";
|
private static final String secretKey = "www.fit2cloud.co";
|
||||||
private static final String iv = "1234567890123456";
|
private static final String iv = "1234567890123456";
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class FilePreviewUtil {
|
public class FilePreviewUtils {
|
||||||
private static final String BASE_FILE_FOLDER = File.separator + "opt" + File.separator + "metersphere" + File.separator + "data" + File.separator + "file" + File.separator + "preview" + File.separator;
|
private static final String BASE_FILE_FOLDER = File.separator + "opt" + File.separator + "metersphere" + File.separator + "data" + File.separator + "file" + File.separator + "preview" + File.separator;
|
||||||
|
|
||||||
public static boolean isImage(String type) {
|
public static boolean isImage(String type) {
|
|
@ -12,7 +12,7 @@ import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
|
|
||||||
public class RsaUtil {
|
public class RsaUtils {
|
||||||
|
|
||||||
public static final String CHARSET = StandardCharsets.UTF_8.name();
|
public static final String CHARSET = StandardCharsets.UTF_8.name();
|
||||||
public static final String RSA_ALGORITHM = "RSA";
|
public static final String RSA_ALGORITHM = "RSA";
|
||||||
|
@ -31,7 +31,7 @@ public class RsaUtil {
|
||||||
|
|
||||||
public static void setRsaKey(RsaKey rsaKey) throws NoSuchAlgorithmException {
|
public static void setRsaKey(RsaKey rsaKey) throws NoSuchAlgorithmException {
|
||||||
// 放到缓存里
|
// 放到缓存里
|
||||||
RsaUtil.rsaKey = rsaKey;
|
RsaUtils.rsaKey = rsaKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RsaKey createKeys() throws NoSuchAlgorithmException {
|
public static RsaKey createKeys() throws NoSuchAlgorithmException {
|
|
@ -59,8 +59,8 @@ public class FileMetadataService {
|
||||||
List<FileMetadata> fileMetadataList = extFileMetadataMapper.selectByKeywordAndFileType(request.getProjectId(), request.getKeyword(), request.getModuleIds(), request.getFileTypes(), false);
|
List<FileMetadata> fileMetadataList = extFileMetadataMapper.selectByKeywordAndFileType(request.getProjectId(), request.getKeyword(), request.getModuleIds(), request.getFileTypes(), false);
|
||||||
fileMetadataList.forEach(fileMetadata -> {
|
fileMetadataList.forEach(fileMetadata -> {
|
||||||
FileInformationDTO fileInformationDTO = new FileInformationDTO(fileMetadata);
|
FileInformationDTO fileInformationDTO = new FileInformationDTO(fileMetadata);
|
||||||
if (FilePreviewUtil.isImage(fileMetadata.getType())) {
|
if (FilePreviewUtils.isImage(fileMetadata.getType())) {
|
||||||
fileInformationDTO.setPreviewSrc(FilePreviewUtil.catchFileIfNotExists(fileMetadata.getPath() + "." + fileMetadata.getType(), this.getFile(fileMetadata)));
|
fileInformationDTO.setPreviewSrc(FilePreviewUtils.catchFileIfNotExists(fileMetadata.getPath() + "." + fileMetadata.getType(), this.getFile(fileMetadata)));
|
||||||
}
|
}
|
||||||
returnList.add(fileInformationDTO);
|
returnList.add(fileInformationDTO);
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,7 @@ import io.metersphere.project.dto.FileInformationDTO;
|
||||||
import io.metersphere.project.dto.FileTableResult;
|
import io.metersphere.project.dto.FileTableResult;
|
||||||
import io.metersphere.project.request.filemanagement.FileMetadataTableRequest;
|
import io.metersphere.project.request.filemanagement.FileMetadataTableRequest;
|
||||||
import io.metersphere.sdk.dto.BaseTreeNode;
|
import io.metersphere.sdk.dto.BaseTreeNode;
|
||||||
import io.metersphere.sdk.util.FilePreviewUtil;
|
import io.metersphere.sdk.util.FilePreviewUtils;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
@ -103,7 +103,7 @@ public class FileManagementBaseUtils {
|
||||||
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getTableData().getList())).size() <= request.getPageSize());
|
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(result.getTableData().getList())).size() <= request.getPageSize());
|
||||||
List<FileInformationDTO> fileInformationDTOList = JSON.parseArray(JSON.toJSONString(result.getTableData().getList()), FileInformationDTO.class);
|
List<FileInformationDTO> fileInformationDTOList = JSON.parseArray(JSON.toJSONString(result.getTableData().getList()), FileInformationDTO.class);
|
||||||
for (FileInformationDTO fileInformationDTO : fileInformationDTOList) {
|
for (FileInformationDTO fileInformationDTO : fileInformationDTOList) {
|
||||||
if (FilePreviewUtil.isImage(fileInformationDTO.getFileType())) {
|
if (FilePreviewUtils.isImage(fileInformationDTO.getFileType())) {
|
||||||
//检查是否有预览文件
|
//检查是否有预览文件
|
||||||
String previewPath = fileInformationDTO.getPreviewSrc();
|
String previewPath = fileInformationDTO.getPreviewSrc();
|
||||||
File file = new File(previewPath);
|
File file = new File(previewPath);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import io.metersphere.sdk.file.FileRepository;
|
||||||
import io.metersphere.sdk.file.FileRequest;
|
import io.metersphere.sdk.file.FileRequest;
|
||||||
import io.metersphere.system.log.constants.OperationLogModule;
|
import io.metersphere.system.log.constants.OperationLogModule;
|
||||||
import io.metersphere.sdk.util.RsaKey;
|
import io.metersphere.sdk.util.RsaKey;
|
||||||
import io.metersphere.sdk.util.RsaUtil;
|
import io.metersphere.sdk.util.RsaUtils;
|
||||||
import org.apache.commons.lang3.SerializationUtils;
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
@ -27,15 +27,15 @@ public class RsaConfig implements ApplicationRunner {
|
||||||
byte[] file = fileRepository.getFile(request);
|
byte[] file = fileRepository.getFile(request);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
RsaKey rsaKey = SerializationUtils.deserialize(file);
|
RsaKey rsaKey = SerializationUtils.deserialize(file);
|
||||||
RsaUtil.setRsaKey(rsaKey);
|
RsaUtils.setRsaKey(rsaKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
// 保存到minio
|
// 保存到minio
|
||||||
RsaKey rsaKey = RsaUtil.getRsaKey();
|
RsaKey rsaKey = RsaUtils.getRsaKey();
|
||||||
byte[] bytes = SerializationUtils.serialize(rsaKey);
|
byte[] bytes = SerializationUtils.serialize(rsaKey);
|
||||||
fileRepository.saveFile(bytes, request);
|
fileRepository.saveFile(bytes, request);
|
||||||
RsaUtil.setRsaKey(rsaKey);
|
RsaUtils.setRsaKey(rsaKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.system.log.constants.OperationLogType;
|
import io.metersphere.system.log.constants.OperationLogType;
|
||||||
import io.metersphere.system.service.BaseUserService;
|
import io.metersphere.system.service.BaseUserService;
|
||||||
import io.metersphere.sdk.util.RsaKey;
|
import io.metersphere.sdk.util.RsaKey;
|
||||||
import io.metersphere.sdk.util.RsaUtil;
|
import io.metersphere.sdk.util.RsaUtils;
|
||||||
import io.metersphere.system.utils.SessionUtils;
|
import io.metersphere.system.utils.SessionUtils;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
@ -62,7 +62,7 @@ public class LoginController {
|
||||||
@GetMapping(value = "/get-key")
|
@GetMapping(value = "/get-key")
|
||||||
@Operation(summary = "获取公钥")
|
@Operation(summary = "获取公钥")
|
||||||
public ResultHolder getKey() throws Exception {
|
public ResultHolder getKey() throws Exception {
|
||||||
RsaKey rsaKey = RsaUtil.getRsaKey();
|
RsaKey rsaKey = RsaUtils.getRsaKey();
|
||||||
return ResultHolder.success(rsaKey.getPublicKey());
|
return ResultHolder.success(rsaKey.getPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package io.metersphere.system.listener;
|
package io.metersphere.system.listener;
|
||||||
|
|
||||||
|
|
||||||
import io.metersphere.sdk.constants.KafkaPluginTopicType;
|
|
||||||
import io.metersphere.sdk.constants.KafkaTopicConstants;
|
import io.metersphere.sdk.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.system.service.PluginLoadService;
|
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.LogUtils;
|
import io.metersphere.sdk.util.LogUtils;
|
||||||
import io.metersphere.system.dto.PluginNotifiedDTO;
|
import io.metersphere.system.dto.PluginNotifiedDTO;
|
||||||
|
import io.metersphere.system.service.PluginLoadService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
import org.springframework.kafka.annotation.KafkaListener;
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
|
@ -29,10 +28,10 @@ public class PluginListener {
|
||||||
String pluginId = pluginNotifiedDTO.getPluginId();
|
String pluginId = pluginNotifiedDTO.getPluginId();
|
||||||
String fileName = pluginNotifiedDTO.getFileName();
|
String fileName = pluginNotifiedDTO.getFileName();
|
||||||
switch (operate) {
|
switch (operate) {
|
||||||
case KafkaPluginTopicType.ADD:
|
case KafkaTopicConstants.TYPE.ADD:
|
||||||
pluginLoadService.handlePluginAddNotified(pluginId, fileName);
|
pluginLoadService.handlePluginAddNotified(pluginId, fileName);
|
||||||
break;
|
break;
|
||||||
case KafkaPluginTopicType.DELETE:
|
case KafkaTopicConstants.TYPE.DELETE:
|
||||||
pluginLoadService.handlePluginDeleteNotified(pluginId, fileName);
|
pluginLoadService.handlePluginDeleteNotified(pluginId, fileName);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package io.metersphere.system.security;
|
package io.metersphere.system.security;
|
||||||
|
|
||||||
import io.metersphere.sdk.util.CodingUtil;
|
import io.metersphere.sdk.util.CodingUtils;
|
||||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||||
import io.metersphere.system.domain.UserKey;
|
import io.metersphere.system.domain.UserKey;
|
||||||
import io.metersphere.system.service.UserKeyService;
|
import io.metersphere.system.service.UserKeyService;
|
||||||
|
@ -37,7 +37,7 @@ public class ApiKeyHandler {
|
||||||
}
|
}
|
||||||
String signatureDecrypt;
|
String signatureDecrypt;
|
||||||
try {
|
try {
|
||||||
signatureDecrypt = CodingUtil.aesDecrypt(signature, userKey.getSecretKey(), accessKey);
|
signatureDecrypt = CodingUtils.aesDecrypt(signature, userKey.getSecretKey(), accessKey);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new RuntimeException("invalid signature");
|
throw new RuntimeException("invalid signature");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package io.metersphere.system.security;
|
||||||
|
|
||||||
import io.metersphere.sdk.constants.SessionConstants;
|
import io.metersphere.sdk.constants.SessionConstants;
|
||||||
import io.metersphere.sdk.dto.SessionUser;
|
import io.metersphere.sdk.dto.SessionUser;
|
||||||
import io.metersphere.sdk.util.CodingUtil;
|
import io.metersphere.sdk.util.CodingUtils;
|
||||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||||
import io.metersphere.system.utils.SessionUtils;
|
import io.metersphere.system.utils.SessionUtils;
|
||||||
import jakarta.servlet.ServletRequest;
|
import jakarta.servlet.ServletRequest;
|
||||||
|
@ -73,7 +73,7 @@ public class CsrfFilter extends AnonymousFilter {
|
||||||
if (StringUtils.isBlank(csrfToken)) {
|
if (StringUtils.isBlank(csrfToken)) {
|
||||||
throw new RuntimeException("csrf token is empty");
|
throw new RuntimeException("csrf token is empty");
|
||||||
}
|
}
|
||||||
csrfToken = CodingUtil.aesDecrypt(csrfToken, SessionUser.secret, SessionUser.iv);
|
csrfToken = CodingUtils.aesDecrypt(csrfToken, SessionUser.secret, SessionUser.iv);
|
||||||
|
|
||||||
String[] signatureArray = StringUtils.split(StringUtils.trimToNull(csrfToken), "|");
|
String[] signatureArray = StringUtils.split(StringUtils.trimToNull(csrfToken), "|");
|
||||||
if (signatureArray.length != 4) {
|
if (signatureArray.length != 4) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import io.metersphere.system.log.constants.OperationLogType;
|
||||||
import io.metersphere.system.log.service.OperationLogService;
|
import io.metersphere.system.log.service.OperationLogService;
|
||||||
import io.metersphere.system.mapper.BaseProjectMapper;
|
import io.metersphere.system.mapper.BaseProjectMapper;
|
||||||
import io.metersphere.system.mapper.BaseUserMapper;
|
import io.metersphere.system.mapper.BaseUserMapper;
|
||||||
import io.metersphere.sdk.util.CodingUtil;
|
import io.metersphere.sdk.util.CodingUtils;
|
||||||
import io.metersphere.system.utils.SessionUtils;
|
import io.metersphere.system.utils.SessionUtils;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.*;
|
import io.metersphere.system.domain.*;
|
||||||
|
@ -380,7 +380,7 @@ public class BaseUserService {
|
||||||
throw new MSException(Translator.get("password_is_null"));
|
throw new MSException(Translator.get("password_is_null"));
|
||||||
}
|
}
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
example.createCriteria().andIdEqualTo(userId).andPasswordEqualTo(CodingUtil.md5(password));
|
example.createCriteria().andIdEqualTo(userId).andPasswordEqualTo(CodingUtils.md5(password));
|
||||||
return userMapper.countByExample(example) > 0;
|
return userMapper.countByExample(example) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ public class BaseUserService {
|
||||||
if (StringUtils.equals("admin", request.getUsername())) {
|
if (StringUtils.equals("admin", request.getUsername())) {
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
example.createCriteria().andIdEqualTo("admin")
|
example.createCriteria().andIdEqualTo("admin")
|
||||||
.andPasswordEqualTo(CodingUtil.md5("metersphere"));
|
.andPasswordEqualTo(CodingUtils.md5("metersphere"));
|
||||||
return userMapper.countByExample(example) > 0;
|
return userMapper.countByExample(example) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,13 @@ package io.metersphere.system.service;
|
||||||
import io.metersphere.plugin.api.api.AbstractApiProtocolPlugin;
|
import io.metersphere.plugin.api.api.AbstractApiProtocolPlugin;
|
||||||
import io.metersphere.plugin.platform.api.AbstractPlatformPlugin;
|
import io.metersphere.plugin.platform.api.AbstractPlatformPlugin;
|
||||||
import io.metersphere.plugin.sdk.api.MsPlugin;
|
import io.metersphere.plugin.sdk.api.MsPlugin;
|
||||||
import io.metersphere.sdk.constants.KafkaPluginTopicType;
|
|
||||||
import io.metersphere.sdk.constants.KafkaTopicConstants;
|
import io.metersphere.sdk.constants.KafkaTopicConstants;
|
||||||
import io.metersphere.sdk.constants.PluginScenarioType;
|
import io.metersphere.sdk.constants.PluginScenarioType;
|
||||||
import io.metersphere.system.controller.handler.result.CommonResultCode;
|
|
||||||
import io.metersphere.sdk.dto.OptionDTO;
|
import io.metersphere.sdk.dto.OptionDTO;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.utils.ServiceUtils;
|
import io.metersphere.system.controller.handler.result.CommonResultCode;
|
||||||
import io.metersphere.system.domain.Plugin;
|
import io.metersphere.system.domain.Plugin;
|
||||||
import io.metersphere.system.domain.PluginExample;
|
import io.metersphere.system.domain.PluginExample;
|
||||||
import io.metersphere.system.dto.PluginDTO;
|
import io.metersphere.system.dto.PluginDTO;
|
||||||
|
@ -20,6 +18,7 @@ import io.metersphere.system.dto.PluginNotifiedDTO;
|
||||||
import io.metersphere.system.mapper.ExtPluginMapper;
|
import io.metersphere.system.mapper.ExtPluginMapper;
|
||||||
import io.metersphere.system.mapper.PluginMapper;
|
import io.metersphere.system.mapper.PluginMapper;
|
||||||
import io.metersphere.system.request.PluginUpdateRequest;
|
import io.metersphere.system.request.PluginUpdateRequest;
|
||||||
|
import io.metersphere.system.utils.ServiceUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -186,7 +185,7 @@ public class PluginService {
|
||||||
* @param fileName
|
* @param fileName
|
||||||
*/
|
*/
|
||||||
public void notifiedPluginAdd(String pluginId, String fileName) {
|
public void notifiedPluginAdd(String pluginId, String fileName) {
|
||||||
notifiedPluginOperate(pluginId, fileName, KafkaPluginTopicType.ADD);
|
notifiedPluginOperate(pluginId, fileName, KafkaTopicConstants.TYPE.ADD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifiedPluginOperate(String pluginId, String fileName, String operate) {
|
public void notifiedPluginOperate(String pluginId, String fileName, String operate) {
|
||||||
|
@ -203,7 +202,7 @@ public class PluginService {
|
||||||
* @param pluginId
|
* @param pluginId
|
||||||
*/
|
*/
|
||||||
public void notifiedPluginDelete(String pluginId, String fileName) {
|
public void notifiedPluginDelete(String pluginId, String fileName) {
|
||||||
notifiedPluginOperate(pluginId, fileName, KafkaPluginTopicType.DELETE);
|
notifiedPluginOperate(pluginId, fileName, KafkaTopicConstants.TYPE.DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin update(PluginUpdateRequest request) {
|
public Plugin update(PluginUpdateRequest request) {
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class UserService {
|
||||||
user.setCreateTime(createTime);
|
user.setCreateTime(createTime);
|
||||||
user.setUpdateUser(operator);
|
user.setUpdateUser(operator);
|
||||||
user.setUpdateTime(createTime);
|
user.setUpdateTime(createTime);
|
||||||
user.setPassword(CodingUtil.md5(user.getEmail()));
|
user.setPassword(CodingUtils.md5(user.getEmail()));
|
||||||
user.setSource(source);
|
user.setSource(source);
|
||||||
user.setDeleted(false);
|
user.setDeleted(false);
|
||||||
userMapper.insertSelective(user);
|
userMapper.insertSelective(user);
|
||||||
|
@ -334,9 +334,9 @@ public class UserService {
|
||||||
User updateModel = new User();
|
User updateModel = new User();
|
||||||
updateModel.setId(user.getId());
|
updateModel.setId(user.getId());
|
||||||
if (StringUtils.equalsIgnoreCase("admin", user.getId())) {
|
if (StringUtils.equalsIgnoreCase("admin", user.getId())) {
|
||||||
updateModel.setPassword(CodingUtil.md5("metersphere"));
|
updateModel.setPassword(CodingUtils.md5("metersphere"));
|
||||||
} else {
|
} else {
|
||||||
updateModel.setPassword(CodingUtil.md5(user.getEmail()));
|
updateModel.setPassword(CodingUtils.md5(user.getEmail()));
|
||||||
}
|
}
|
||||||
updateModel.setUpdateTime(updateTime);
|
updateModel.setUpdateTime(updateTime);
|
||||||
updateModel.setUpdateUser(operator);
|
updateModel.setUpdateUser(operator);
|
||||||
|
@ -460,7 +460,7 @@ public class UserService {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.setId(UUID.randomUUID().toString());
|
user.setId(UUID.randomUUID().toString());
|
||||||
user.setEmail(userInvite.getEmail());
|
user.setEmail(userInvite.getEmail());
|
||||||
user.setPassword(CodingUtil.md5(RsaUtil.privateDecrypt(request.getPassword(), RsaUtil.getRsaKey().getPrivateKey())));
|
user.setPassword(CodingUtils.md5(RsaUtils.privateDecrypt(request.getPassword(), RsaUtils.getRsaKey().getPrivateKey())));
|
||||||
user.setName(request.getName());
|
user.setName(request.getName());
|
||||||
user.setPhone(request.getPhone());
|
user.setPhone(request.getPhone());
|
||||||
user.setCreateUser(userInvite.getInviteUser());
|
user.setCreateUser(userInvite.getInviteUser());
|
||||||
|
|
|
@ -670,7 +670,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
this.requestPostAndReturn(UserRequestUtils.URL_USER_RESET_PASSWORD, request);
|
this.requestPostAndReturn(UserRequestUtils.URL_USER_RESET_PASSWORD, request);
|
||||||
//检查数据库
|
//检查数据库
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdEqualTo("admin").andPasswordEqualTo(CodingUtil.md5("metersphere"));
|
userExample.createCriteria().andIdEqualTo("admin").andPasswordEqualTo(CodingUtils.md5("metersphere"));
|
||||||
Assertions.assertEquals(1, userMapper.countByExample(userExample));
|
Assertions.assertEquals(1, userMapper.countByExample(userExample));
|
||||||
this.checkLog("admin", OperationLogType.UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD);
|
this.checkLog("admin", OperationLogType.UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD);
|
||||||
}
|
}
|
||||||
|
@ -691,7 +691,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
List<User> userList = userToolService.selectByIdList(Collections.singletonList(userId));
|
List<User> userList = userToolService.selectByIdList(Collections.singletonList(userId));
|
||||||
for (User checkUser : userList) {
|
for (User checkUser : userList) {
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail()));
|
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtils.md5(checkUser.getEmail()));
|
||||||
Assertions.assertEquals(1, userMapper.countByExample(userExample));
|
Assertions.assertEquals(1, userMapper.countByExample(userExample));
|
||||||
this.checkLog(checkUser.getId(), OperationLogType.UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD);
|
this.checkLog(checkUser.getId(), OperationLogType.UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD);
|
||||||
}
|
}
|
||||||
|
@ -715,7 +715,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
List<User> userList = userMapper.selectByExample(example);
|
List<User> userList = userMapper.selectByExample(example);
|
||||||
for (User checkUser : userList) {
|
for (User checkUser : userList) {
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail()));
|
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtils.md5(checkUser.getEmail()));
|
||||||
Assertions.assertEquals(1, userMapper.countByExample(userExample));
|
Assertions.assertEquals(1, userMapper.countByExample(userExample));
|
||||||
this.checkLog(checkUser.getId(), OperationLogType.UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD);
|
this.checkLog(checkUser.getId(), OperationLogType.UPDATE, UserRequestUtils.URL_USER_RESET_PASSWORD);
|
||||||
}
|
}
|
||||||
|
@ -1174,7 +1174,7 @@ public class UserControllerTests extends BaseTest {
|
||||||
UserRegisterRequest request = new UserRegisterRequest();
|
UserRegisterRequest request = new UserRegisterRequest();
|
||||||
request.setInviteId(inviteId);
|
request.setInviteId(inviteId);
|
||||||
request.setName("建国通过邮箱邀请");
|
request.setName("建国通过邮箱邀请");
|
||||||
request.setPassword(RsaUtil.publicEncrypt("Cao..12138", RsaUtil.getRsaKey().getPublicKey()));
|
request.setPassword(RsaUtils.publicEncrypt("Cao..12138", RsaUtils.getRsaKey().getPublicKey()));
|
||||||
MvcResult mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_INVITE_REGISTER, request);
|
MvcResult mvcResult = userRequestUtils.responsePost(UserRequestUtils.URL_INVITE_REGISTER, request);
|
||||||
String resultHolderStr = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
String resultHolderStr = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
ResultHolder resultHolder = JSON.parseObject(resultHolderStr, ResultHolder.class);
|
ResultHolder resultHolder = JSON.parseObject(resultHolderStr, ResultHolder.class);
|
||||||
|
|
Loading…
Reference in New Issue