diff --git a/src/main/java/com/dispose/ability/DisposeAbility.java b/src/main/java/com/dispose/ability/DisposeAbility.java index f61bef76..2643fbe2 100644 --- a/src/main/java/com/dispose/ability/DisposeAbility.java +++ b/src/main/java/com/dispose/ability/DisposeAbility.java @@ -17,7 +17,6 @@ public interface DisposeAbility { /** * Init device env. - * * @param urlPath the url path * @param username the username * @param password the password @@ -34,10 +33,10 @@ public interface DisposeAbility { * @param duration the duration * @return the mul return type */ - MulReturnType runDispose(String ip, DisposeCapacityType capType, - @Nullable NetflowDirection nfDirection, - @Nullable Integer attackType, - @Nullable Long duration); + MulReturnType runDispose(String ip, DisposeCapacityType capType, + @Nullable NetflowDirection nfDirection, + @Nullable Integer attackType, + @Nullable Long duration); /** * Stop dispose mul return type. @@ -52,7 +51,7 @@ public interface DisposeAbility { MulReturnType stopDispose(String ip, DisposeCapacityType capType, @Nullable NetflowDirection nfDirection, @Nullable Integer attackType, - @Nullable Long taskId); + @Nullable String taskId); /** * Gets ability device fireware. diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index c628deb7..19f8da4c 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -55,7 +55,6 @@ public class DpTechAbilityImpl implements DisposeAbility { /** * Init device env. - * * @param urlPath the url path * @param username the username * @param password the password @@ -105,10 +104,10 @@ public class DpTechAbilityImpl implements DisposeAbility { * @return the mul return type */ @Override - public MulReturnType runDispose(String ip, DisposeCapacityType capType, - NetflowDirection nfDirection, - Integer attackType, - Long duration) { + public MulReturnType runDispose(String ip, DisposeCapacityType capType, + NetflowDirection nfDirection, + Integer attackType, + Long duration) { ErrorCode err = ErrorCode.ERR_OK; try { @@ -156,7 +155,7 @@ public class DpTechAbilityImpl implements DisposeAbility { DisposeCapacityType capType, NetflowDirection nfDirection, Integer attackType, - Long taskId) { + String taskId) { ErrorCode err = ErrorCode.ERR_OK; try { @@ -216,17 +215,17 @@ public class DpTechAbilityImpl implements DisposeAbility { public MulReturnType getAbilityDeviceFireware() { return new MulReturnType<>(ErrorCode.ERR_OK, DeviceFirewareInfo.builder() - .vendor("DpTech") - .model("UMC") - .firmware("Unknown") - .os("Windows Server") - .kernel("Windows") - .arch("x86_64") - .version("5.7.31") - .memory(-1) - .freeMemory(-1) - .cpuUsed(-1) - .build()); + .vendor("DpTech") + .model("UMC") + .firmware("Unknown") + .os("Windows Server") + .kernel("Windows") + .arch("x86_64") + .version("5.7.31") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build()); } /** diff --git a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java index 082c099b..1af110db 100644 --- a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java @@ -8,7 +8,7 @@ import com.dispose.pojo.po.MulReturnType; import com.dispose.pojo.vo.DeviceFirewareInfo; import com.haohan.dispose.common.HaoHanStartCleanResp; import com.haohan.dispose.common.HaoHanStopCleanResp; -import com.haohan.dispose.protocol.RestfulInterface; +import com.haohan.dispose.protocol.HaoHanInterface; import inet.ipaddr.IPAddress; import inet.ipaddr.IPAddressString; import lombok.extern.slf4j.Slf4j; @@ -32,7 +32,7 @@ public class HaoHanAbilityImpl implements DisposeAbility { /** * The Restful interface. */ - private final RestfulInterface restfulInterface = new RestfulInterface(); + private final HaoHanInterface restfulInterface = new HaoHanInterface(); /** * The Url root path. */ @@ -61,10 +61,10 @@ public class HaoHanAbilityImpl implements DisposeAbility { * @return the mul return type */ @Override - public MulReturnType runDispose(String ip, DisposeCapacityType capType, - @Nullable NetflowDirection nfDirection, - @Nullable Integer attackType, - @Nullable Long duration) { + public MulReturnType runDispose(String ip, DisposeCapacityType capType, + @Nullable NetflowDirection nfDirection, + @Nullable Integer attackType, + @Nullable Long duration) { try { log.info("++++Begging Haohan Start Cleanup Task: {}", ip); @@ -93,7 +93,7 @@ public class HaoHanAbilityImpl implements DisposeAbility { } log.debug("----Finish Haohan Start Cleanup Task: {}", ip); - return new MulReturnType<>(ErrorCode.ERR_OK, (long) resp.getCleanTaskId()); + return new MulReturnType<>(ErrorCode.ERR_OK, String.valueOf(resp.getCleanTaskId())); } catch (Exception ex) { log.error("----Exception Haohan Start Cleanup Task: {}, {}, {}", ip, nfDirection, duration); return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null); @@ -114,7 +114,7 @@ public class HaoHanAbilityImpl implements DisposeAbility { public MulReturnType stopDispose(String ip, DisposeCapacityType capType, @Nullable NetflowDirection nfDirection, @Nullable Integer attackType, - @Nullable Long taskId) { + @Nullable String taskId) { try { log.debug("++++Begging Haohan Stop Cleanup Task: {}", taskId); @@ -127,7 +127,8 @@ public class HaoHanAbilityImpl implements DisposeAbility { return new MulReturnType<>(ErrorCode.ERR_PARAMS, null); } - HaoHanStopCleanResp resp = restfulInterface.stopClean(this.urlRootPath, taskId.intValue(), + HaoHanStopCleanResp resp = restfulInterface.stopClean(this.urlRootPath, + Integer.parseInt(taskId), DISPOSE_PLATFORM_NAME); if (resp == null) { @@ -169,17 +170,17 @@ public class HaoHanAbilityImpl implements DisposeAbility { public MulReturnType getAbilityDeviceFireware() { return new MulReturnType<>(ErrorCode.ERR_OK, DeviceFirewareInfo.builder() - .vendor("HaoHan") - .model("Unknown") - .firmware("Unknown") - .os("Linux Server") - .kernel("Linux") - .arch("x86_64") - .version("Unknown") - .memory(-1) - .freeMemory(-1) - .cpuUsed(-1) - .build()); + .vendor("HaoHan") + .model("Unknown") + .firmware("Unknown") + .os("Linux Server") + .kernel("Linux") + .arch("x86_64") + .version("Unknown") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build()); } /** diff --git a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java index 3835aee5..564d689d 100644 --- a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java @@ -22,7 +22,6 @@ public class VirtualAbilityImpl implements DisposeAbility { /** * Init device env. - * * @param urlPath the url path * @param username the username * @param password the password @@ -47,9 +46,9 @@ public class VirtualAbilityImpl implements DisposeAbility { * @return the mul return type */ @Override - public MulReturnType runDispose(String ip, DisposeCapacityType capType, - @Nullable NetflowDirection nfDirection, - @Nullable Integer attackType, @Nullable Long duration) { + public MulReturnType runDispose(String ip, DisposeCapacityType capType, + @Nullable NetflowDirection nfDirection, + @Nullable Integer attackType, @Nullable Long duration) { return new MulReturnType<>(ErrorCode.ERR_OK, null); } @@ -66,7 +65,7 @@ public class VirtualAbilityImpl implements DisposeAbility { @Override public MulReturnType stopDispose(String ip, DisposeCapacityType capType, @Nullable NetflowDirection nfDirection, - @Nullable Integer attackType, @Nullable Long taskId) { + @Nullable Integer attackType, @Nullable String taskId) { return new MulReturnType<>(ErrorCode.ERR_OK, null); } diff --git a/src/main/java/com/dispose/ability/impl/YiYangAbilityImpl.java b/src/main/java/com/dispose/ability/impl/YiYangAbilityImpl.java new file mode 100644 index 00000000..1e61715c --- /dev/null +++ b/src/main/java/com/dispose/ability/impl/YiYangAbilityImpl.java @@ -0,0 +1,199 @@ +package com.dispose.ability.impl; + +import com.dispose.ability.DisposeAbility; +import com.dispose.common.DisposeCapacityType; +import com.dispose.common.ErrorCode; +import com.dispose.common.NetflowDirection; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; +import com.dispose.yiyang.dispose.common.YiYangLoginRsp; +import com.dispose.yiyang.dispose.protocol.YiYangInterface; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +import javax.annotation.Nullable; + +/** + * The type Yi yang ability. + * + * @author + */ +@Slf4j +public class YiYangAbilityImpl implements DisposeAbility { + + /** + * The Restful interface. + */ + private final YiYangInterface restfulInterface = new YiYangInterface(); + + /** + * The Url root path. + */ + @Getter + @Setter + private String urlRootPath; + + /** + * The Username. + */ + @Getter + @Setter + private String username; + + /** + * The Password. + */ + @Getter + @Setter + private String password; + + /** + * The Token. + */ + private String token; + + /** + * Init device env. + * + * @param urlPath the url path + * @param username the username + * @param password the password + */ + @Override + public void initDeviceEnv(String urlPath, String username, String password) { + this.urlRootPath = urlPath; + this.username = username; + this.password = password; + restfulInterface.setParams(1, 0); + + upgradeToken(); + } + + /** + * Run dispose mul return type. + * + * @param ip the ip + * @param capType the cap type + * @param nfDirection the nf direction + * @param attackType the attack type + * @param duration the duration + * @return the mul return type + */ + @Override + public MulReturnType runDispose(String ip, DisposeCapacityType capType, + @Nullable NetflowDirection nfDirection, + @Nullable Integer attackType, @Nullable Long duration) { + return null; + } + + /** + * Stop dispose mul return type. + * + * @param ip the ip + * @param capType the cap type + * @param nfDirection the nf direction + * @param attackType the attack type + * @param taskId the task id + * @return the mul return type + */ + @Override + public MulReturnType stopDispose(String ip, DisposeCapacityType capType, + @Nullable NetflowDirection nfDirection, + @Nullable Integer attackType, @Nullable String taskId) { + return null; + } + + /** + * Gets ability device fireware. + * + * @return the ability device fireware + */ + @Override + public MulReturnType getAbilityDeviceFireware() { + return new MulReturnType<>(ErrorCode.ERR_OK, + DeviceFirewareInfo.builder() + .vendor("YiYang") + .model("Unknown") + .firmware("Unknown") + .os("Linux Server") + .kernel("Linux") + .arch("x86_64") + .version("Unknown") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build()); + } + + /** + * To device attack type long. + * + * @param ddosAttackTypeMask the ddos attack type mask + * @return the long + */ + @Override + public Long toDeviceAttackType(Long ddosAttackTypeMask) { + return ddosAttackTypeMask; + } + + /** + * Gets device link status. + * + * @return the device link status + */ + @Override + public boolean getDeviceLinkStatus() { + try { + if (token == null || token.length() == 0) { + return false; + } + + ErrorCode err = restfulInterface.getLinkStatus(urlRootPath, token); + + if (err == ErrorCode.ERR_LOGOUT) { + err = restfulInterface.getLinkStatus(urlRootPath, token); + } + + return err == ErrorCode.ERR_OK; + } catch (Exception ex) { + log.error(ex.getMessage()); + } + + return false; + } + + /** + * Gets dispose device protect object. + */ + @Override + public void getDisposeDeviceProtectObject() { + + } + + /** + * Is carry protect ip boolean. + * + * @param ipAddr the ip addr + * @return the boolean + */ + @Override + public boolean isCarryProtectIp(String ipAddr) { + return true; + } + + /** + * Upgrade token. + */ + private void upgradeToken() { + try { + ProtocolRespDTO logInfo = restfulInterface.login(urlRootPath, username, password); + + if (logInfo != null && logInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) { + this.token = logInfo.getMsgContent().getToken(); + } + } catch (Exception ignored) { + } + } +} diff --git a/src/main/java/com/dispose/common/DisposeDeviceType.java b/src/main/java/com/dispose/common/DisposeDeviceType.java index 6015a241..0cb8d943 100644 --- a/src/main/java/com/dispose/common/DisposeDeviceType.java +++ b/src/main/java/com/dispose/common/DisposeDeviceType.java @@ -7,31 +7,48 @@ package com.dispose.common; */ public enum DisposeDeviceType implements BaseEnum { /** - * Dptech umc dispose device type. + * The Dptech umc. */ DPTECH_UMC(0, "迪普UMC管理平台"), /** - * Haohan platform dispose device type. + * The Haohan platform. */ HAOHAN_PLATFORM(1, "浩瀚处置设备"), /** - * Virtual dispose dispose device type. + * Yiyang platform dispose device type. + */ + YIYANG_PLATFORM(2, "亿阳处置设备"), + + /** + * The Virtual dispose. */ VIRTUAL_DISPOSE(999, "虚拟处置设备"); + /** + * The Code. + */ private final int code; + /** + * The Readme. + */ private final String readme; + /** + * Instantiates a new Dispose device type. + * + * @param code the code + * @param readme the readme + */ DisposeDeviceType(int code, String readme) { this.code = code; this.readme = readme; } /** - * Gets code. + * Gets value. * - * @return the code + * @return the value */ @Override public Integer getValue() { @@ -39,9 +56,9 @@ public enum DisposeDeviceType implements BaseEnum { } /** - * Gets readme. + * Gets description. * - * @return the readme + * @return the description */ @Override public String getDescription() { diff --git a/src/main/java/com/dispose/common/ErrorCode.java b/src/main/java/com/dispose/common/ErrorCode.java index d5484b64..d50a0e28 100644 --- a/src/main/java/com/dispose/common/ErrorCode.java +++ b/src/main/java/com/dispose/common/ErrorCode.java @@ -272,8 +272,9 @@ public enum ErrorCode { case ERR_INPUTMISS: return HttpServletResponse.SC_BAD_REQUEST; case ERR_UNSUPPORT: - case ERR_UNKNOWNINTERFACE: return HttpServletResponse.SC_METHOD_NOT_ALLOWED; + case ERR_UNKNOWNINTERFACE: + return HttpServletResponse.SC_NOT_FOUND; default: return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } diff --git a/src/main/java/com/dispose/manager/DeviceTaskManager.java b/src/main/java/com/dispose/manager/DeviceTaskManager.java index 7b7d29ca..b35a6ab8 100644 --- a/src/main/java/com/dispose/manager/DeviceTaskManager.java +++ b/src/main/java/com/dispose/manager/DeviceTaskManager.java @@ -117,7 +117,7 @@ public interface DeviceTaskManager { * @param externId the extern id * @return the task extern id */ - boolean setTaskExternId(Long id, Long externId); + boolean setTaskExternId(Long id, String externId); /** * Gets task by id. diff --git a/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java b/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java index 9d1b7308..a7dbcd1d 100644 --- a/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DeviceTaskManagerImpl.java @@ -269,7 +269,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { * @return the task extern id */ @Override - public boolean setTaskExternId(Long id, Long externId) { + public boolean setTaskExternId(Long id, String externId) { return deviceTaskMapper.changeExternId(id, externId) == 1; } diff --git a/src/main/java/com/dispose/mapper/DeviceTaskMapper.java b/src/main/java/com/dispose/mapper/DeviceTaskMapper.java index 624c5500..089cc0ad 100644 --- a/src/main/java/com/dispose/mapper/DeviceTaskMapper.java +++ b/src/main/java/com/dispose/mapper/DeviceTaskMapper.java @@ -143,5 +143,5 @@ public interface DeviceTaskMapper { * @return the int */ int changeExternId(@Param("id") Long id, - @Param("externId") Long externId); + @Param("externId") String externId); } diff --git a/src/main/java/com/dispose/pojo/entity/DeviceTask.java b/src/main/java/com/dispose/pojo/entity/DeviceTask.java index d01aaba2..b81120a7 100644 --- a/src/main/java/com/dispose/pojo/entity/DeviceTask.java +++ b/src/main/java/com/dispose/pojo/entity/DeviceTask.java @@ -78,7 +78,7 @@ public class DeviceTask implements Serializable { /** * The Extern id. */ - private Long externId; + private String externId; /** * The Err retry. */ diff --git a/src/main/java/com/dispose/restful/RestfulInterface.java b/src/main/java/com/dispose/restful/RestfulInterface.java new file mode 100644 index 00000000..685b3b75 --- /dev/null +++ b/src/main/java/com/dispose/restful/RestfulInterface.java @@ -0,0 +1,153 @@ +package com.dispose.restful; + +import cn.hutool.http.Header; +import cn.hutool.http.HttpRequest; +import com.dispose.common.ConstValue; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMethod; +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; + +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; + +/** + * The type Restful interface. + * + * @author + */ +@Slf4j +public class RestfulInterface { + /** + * The constant OBJECT_MAPPER. + */ + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + /** + * Post json string. + * + * @param url the url + * @param header the header + * @param body the body + * @return the string + */ + private static String postJson(String url, Map header, String body) { + return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body) + .execute().body(); + } + + /** + * Gets json. + * + * @param url the url + * @param header the header + * @return the json + */ + private static String getJson(String url, Map header) { + return HttpRequest.get(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header) + .execute().body(); + } + + /** + * Protocol run t. + * + * @param the type parameter + * @param the type parameter + * @param url the url + * @param obj the obj + * @param outType the out type + * @return the t + */ + public static T protocolRun(String url, E obj, Class outType) { + try { + Map httpHeadMap = new HashMap<>(2); + httpHeadMap.put(String.valueOf(Header.CONNECTION), "keep-alive"); + httpHeadMap.put(String.valueOf(Header.ACCEPT), "*/*"); + + String svrResp = postJson(url, httpHeadMap, OBJECT_MAPPER.writeValueAsString(obj)); + + if (svrResp == null) { + log.debug("Server return null: {}", url); + return null; + } + + return OBJECT_MAPPER.readValue(svrResp, outType); + } catch (JsonProcessingException e) { + log.debug("System exception: ", e); + return null; + } + } + + /** + * Base pro run protocol resp dto. + * + * @param the type parameter + * @param the type parameter + * @param url the url + * @param token the token + * @param obj the obj + * @param subClass the sub class + * @param reqType the req type + * @return the protocol resp dto + */ + public static ProtocolRespDTO baseProRun(String url, String token, E obj, Class subClass, + RequestMethod reqType) { + try { + String svrResp = null; + + Map httpHeadMap = new HashMap<>(2); + httpHeadMap.put(String.valueOf(Header.CONNECTION), "keep-alive"); + httpHeadMap.put(String.valueOf(Header.ACCEPT), "*/*"); + + if (token != null && token.length() > 0) { + httpHeadMap.put(String.valueOf(Header.AUTHORIZATION), ConstValue.STRING_HTTP_AUTH_HEAD + token); + } + + switch (reqType) { + case GET: + svrResp = getJson(url, httpHeadMap); + break; + case POST: + svrResp = postJson(url, httpHeadMap, OBJECT_MAPPER.writeValueAsString(obj)); + break; + default: + log.error("Unknown method: {}", reqType); + break; + } + + if (svrResp == null) { + log.debug("Server return null: {}", url); + return null; + } + + return OBJECT_MAPPER.readValue(svrResp, + new TypeReference>() { + @Override + public Type getType() { + return createRespType(subClass); + } + }); + } catch (JsonProcessingException e) { + log.debug("System exception: ", e); + return null; + } + } + + /** + * Create resp type type. + * + * @param the type parameter + * @param c the c + * @return the type + */ + private static Type createRespType(Class c) { + Type[] types = new Type[1]; + types[0] = c; + return ParameterizedTypeImpl.make(ProtocolRespDTO.class, types, + ProtocolRespDTO.class.getDeclaringClass()); + } +} diff --git a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java index 77178085..102071b8 100644 --- a/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DeviceTaskManagerServiceImpl.java @@ -59,7 +59,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { * @param disposeTask the dispose task */ private void virtualDeviceTaskRun(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) { - MulReturnType ret; + MulReturnType ret; // 设置任务状态为启动中 deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); @@ -119,7 +119,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { * @param disposeTask the dispose task */ private void haoHanDeviceTaskRun(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) { - MulReturnType ret; + MulReturnType ret; // 重试错误次数过多 if (deviceTask.getErrRetry() >= DisposeConfigValue.CALL_ERROR_RETRY_TIMES) { @@ -202,7 +202,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { * @param disposeTask the dispose task */ private void dpTechDeviceTaskRun(AbilityInfo ai, DeviceTask deviceTask, DisposeTask disposeTask) { - MulReturnType ret; + MulReturnType ret; // 设置任务状态为启动中 deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), DisposeTaskStatus.TASK_STARTING); @@ -568,12 +568,12 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { @Scheduled(fixedDelay = 1000) public void scheduleRunnerThread() { // 处理处置任务数据 - //disposeTaskManagerSchedule(); + disposeTaskManagerSchedule(); // 处置设备启动任务 - //deviceTaskRunnerSchedule(); + deviceTaskRunnerSchedule(); // 处置设备停止任务 - //deviceTaskStopSchedule(); + deviceTaskStopSchedule(); } } diff --git a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java index bbef93cf..844a2147 100644 --- a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java @@ -4,6 +4,7 @@ import com.dispose.ability.DisposeAbility; import com.dispose.ability.impl.DpTechAbilityImpl; import com.dispose.ability.impl.HaoHanAbilityImpl; import com.dispose.ability.impl.VirtualAbilityImpl; +import com.dispose.ability.impl.YiYangAbilityImpl; import com.dispose.common.DisposeCapacityType; import com.dispose.common.ErrorCode; import com.dispose.common.HttpType; @@ -111,6 +112,9 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ case HAOHAN_PLATFORM: db = new HaoHanAbilityImpl(); break; + case YIYANG_PLATFORM: + db = new YiYangAbilityImpl(); + break; case VIRTUAL_DISPOSE: db = new VirtualAbilityImpl(); break; diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangBaseResp.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangBaseResp.java new file mode 100644 index 00000000..8fc6d7e1 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangBaseResp.java @@ -0,0 +1,24 @@ +package com.dispose.yiyang.dispose.common; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang base resp status. + * + * @author + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class YiYangBaseResp { + /** + * The Status. + */ + private Integer status; + /** + * The Message. + */ + private String message; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginReq.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginReq.java new file mode 100644 index 00000000..c5865ae6 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginReq.java @@ -0,0 +1,26 @@ +package com.dispose.yiyang.dispose.common; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang login req. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class YiYangLoginReq { + /** + * The User name. + */ + private String userName; + /** + * The Password. + */ + private String password; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginRsp.java b/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginRsp.java new file mode 100644 index 00000000..ca6861d8 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/common/YiYangLoginRsp.java @@ -0,0 +1,42 @@ +package com.dispose.yiyang.dispose.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * The type Yi yang login rsp. + * + * @author + */ +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"}) +public class YiYangLoginRsp extends YiYangBaseResp { + /** + * The User name. + */ + private String userName; + + /** + * The Token. + */ + private String token; + + /** + * The Log time. + */ + private Long logTime; + /** + * The Expire time. + */ + private Long expireTime; +} diff --git a/src/main/java/com/dispose/yiyang/dispose/protocol/YiYangInterface.java b/src/main/java/com/dispose/yiyang/dispose/protocol/YiYangInterface.java new file mode 100644 index 00000000..403901b6 --- /dev/null +++ b/src/main/java/com/dispose/yiyang/dispose/protocol/YiYangInterface.java @@ -0,0 +1,91 @@ +package com.dispose.yiyang.dispose.protocol; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.dto.protocol.base.BaseProtocolDTO; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.restful.RestfulInterface; +import com.dispose.yiyang.dispose.common.YiYangBaseResp; +import com.dispose.yiyang.dispose.common.YiYangLoginReq; +import com.dispose.yiyang.dispose.common.YiYangLoginRsp; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletResponse; + +/** + * The type Yi yang interface. + * + * @author + */ +public class YiYangInterface { + /** + * The Ver. + */ + private int ver; + /** + * The Crypto type. + */ + private int cryptoType; + + /** + * Sets params. + * + * @param ver the ver + * @param cryptoType the crypto type + */ + public void setParams(int ver, int cryptoType) { + this.ver = ver; + this.cryptoType = cryptoType; + } + + /** + * Login protocol resp dto. + * + * @param baseUrlPath the base url path + * @param username the username + * @param password the password + * @return the protocol resp dto + */ + public ProtocolRespDTO login(String baseUrlPath, String username, String password) { + + BaseProtocolDTO reqInfo = new BaseProtocolDTO<>(); + + reqInfo.setMsgContent(YiYangLoginReq.builder() + .userName(username) + .password(password) + .build()); + + reqInfo.setCryptoType(this.cryptoType); + reqInfo.setVer(this.ver); + reqInfo.setTimeStamp(System.currentTimeMillis()); + + return RestfulInterface.baseProRun(baseUrlPath + "dispose_device/auth/login", + null, + reqInfo, + YiYangLoginRsp.class, + RequestMethod.POST); + } + + /** + * Gets link status. + * + * @param baseUrlPath the base url path + * @param token the token + * @return the link status + */ + public ErrorCode getLinkStatus(String baseUrlPath, String token) { + ProtocolRespDTO rspInfo = RestfulInterface.baseProRun(baseUrlPath + "dispose_device/information/linkstatus", + token, + null, + YiYangBaseResp.class, + RequestMethod.GET); + if(rspInfo != null && rspInfo.getMsgContent() != null) { + if(rspInfo.getCode() == HttpServletResponse.SC_UNAUTHORIZED) { + return ErrorCode.ERR_LOGOUT; + } else if(rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) { + return ErrorCode.ERR_OK; + } + } + + return ErrorCode.ERR_UNKNOWNCMD; + } +} diff --git a/src/main/java/com/haohan/dispose/protocol/RestfulInterface.java b/src/main/java/com/haohan/dispose/protocol/HaoHanInterface.java similarity index 66% rename from src/main/java/com/haohan/dispose/protocol/RestfulInterface.java rename to src/main/java/com/haohan/dispose/protocol/HaoHanInterface.java index c78a731a..d452b653 100644 --- a/src/main/java/com/haohan/dispose/protocol/RestfulInterface.java +++ b/src/main/java/com/haohan/dispose/protocol/HaoHanInterface.java @@ -1,10 +1,7 @@ package com.haohan.dispose.protocol; -import cn.hutool.http.Header; -import cn.hutool.http.HttpRequest; import com.dispose.common.ErrorCode; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.dispose.restful.RestfulInterface; import com.haohan.dispose.common.HaoHanGetCleanTaskNetflowInfoReq; import com.haohan.dispose.common.HaoHanGetCleanTaskNetflowInfoResp; import com.haohan.dispose.common.HaoHanGetCleanTaskStatusReq; @@ -18,67 +15,17 @@ import com.haohan.dispose.common.HaoHanStopCleanResp; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * The type Restful interface. + * The type Hao han interface. * * @author */ @Slf4j -public class RestfulInterface { - /** - * The constant OBJECT_MAPPER. - */ - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - /** - * Post json string. - * - * @param url the url - * @param header the header - * @param body the body - * @return the string - */ - private static String postJson(String url, Map header, String body) { - return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body) - .execute().body(); - } - - /** - * Protocol run t. - * - * @param the type parameter - * @param the type parameter - * @param url the url - * @param obj the obj - * @param outType the out type - * @return the t - */ - private T protocolRun(String url, E obj, Class outType) { - try { - Map httpHeadMap = new HashMap<>(2); - httpHeadMap.put(String.valueOf(Header.CONNECTION), "keep-alive"); - httpHeadMap.put(String.valueOf(Header.ACCEPT), "*/*"); - - String svrResp = postJson(url, httpHeadMap, OBJECT_MAPPER.writeValueAsString(obj)); - - if (svrResp == null) { - log.debug("Server return null: {}", url); - return null; - } - - return OBJECT_MAPPER.readValue(svrResp, outType); - } catch (JsonProcessingException e) { - log.debug("System exception: ", e); - return null; - } - } - +public class HaoHanInterface { /** * Gets clean task status. * @@ -87,9 +34,9 @@ public class RestfulInterface { * @return the clean task status */ public HaoHanGetCleanTaskStatusResp getCleanTaskStatus(String baseUrlPath, Integer taskId) { - return protocolRun(baseUrlPath + "/getCleanTaskState", - HaoHanGetCleanTaskStatusReq.builder().cleanTaskId(taskId).build(), - HaoHanGetCleanTaskStatusResp.class); + return RestfulInterface.protocolRun(baseUrlPath + "/getCleanTaskState", + HaoHanGetCleanTaskStatusReq.builder().cleanTaskId(taskId).build(), + HaoHanGetCleanTaskStatusResp.class); } /** @@ -102,7 +49,7 @@ public class RestfulInterface { * @return the hao han start clean resp */ public HaoHanStartCleanResp startClean(String baseUrlPath, String ipAddr, int times, String readme) { - HaoHanStartCleanResp svrResp = protocolRun(baseUrlPath + "/sendTow", + HaoHanStartCleanResp svrResp = RestfulInterface.protocolRun(baseUrlPath + "/sendTow", new HaoHanStartCleanReq(ipAddr, times, readme), HaoHanStartCleanResp.class); @@ -158,7 +105,7 @@ public class RestfulInterface { * @return the hao han stop clean resp */ public HaoHanStopCleanResp stopClean(String baseUrlPath, Integer taskId, String readme) { - return protocolRun(baseUrlPath + "/delTow", + return RestfulInterface.protocolRun(baseUrlPath + "/delTow", new HaoHanStopCleanReq(taskId, readme), HaoHanStopCleanResp.class); } @@ -171,7 +118,7 @@ public class RestfulInterface { * @return the cleaning netflow */ public HaoHanGetCleaningNetflowInfoResp getCleaningNetflow(String baseUrlPath, String readme) { - return protocolRun(baseUrlPath + "/allIpFlow", + return RestfulInterface.protocolRun(baseUrlPath + "/allIpFlow", new HaoHanGetCleaningNetflowInfoReq(readme), HaoHanGetCleaningNetflowInfoResp.class); } @@ -184,7 +131,7 @@ public class RestfulInterface { * @return the clean task netflow */ public HaoHanGetCleanTaskNetflowInfoResp getCleanTaskNetflow(String baseUrlPath, Integer taskId) { - return protocolRun(baseUrlPath + "/cleanTaskFlow", + return RestfulInterface.protocolRun(baseUrlPath + "/cleanTaskFlow", new HaoHanGetCleanTaskNetflowInfoReq(taskId), HaoHanGetCleanTaskNetflowInfoResp.class ); diff --git a/src/main/resources/db/schema.sql b/src/main/resources/db/schema.sql index 5eb90434..cf9fb491 100644 --- a/src/main/resources/db/schema.sql +++ b/src/main/resources/db/schema.sql @@ -21,109 +21,134 @@ SET FOREIGN_KEY_CHECKS = 0; -- Table structure for device_task -- ---------------------------- DROP TABLE IF EXISTS `device_task`; -CREATE TABLE `device_task` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符', - `taskId` int(11) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符', - `deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符', - `beginTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务开始时间', - `endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间', - `taskAttackType` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '需要处置的攻击类型', - `execAttackTypeIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Input)', - `attackTypeStatusIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', - `execAttackTypeOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Output)', - `attackTypeStatusOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', - `externId` int(11) NULL DEFAULT NULL COMMENT '扩展任务ID', - `errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数', - `status` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '任务状态', - PRIMARY KEY (`id`) USING BTREE, - INDEX `task_info_ibfk_1`(`taskId`) USING BTREE, - INDEX `task_info_ibfk_2`(`deviceId`) USING BTREE, - CONSTRAINT `device_task_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `device_task_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `device_task` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符', + `taskId` int(11) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符', + `deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符', + `beginTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务开始时间', + `endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间', + `taskAttackType` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '需要处置的攻击类型', + `execAttackTypeIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Input)', + `attackTypeStatusIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', + `execAttackTypeOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Output)', + `attackTypeStatusOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', + `externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID', + `errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数', + `status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态', + PRIMARY KEY (`id`) USING BTREE, + INDEX `task_info_ibfk_1` (`taskId`) USING BTREE, + INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE, + CONSTRAINT `device_task_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `device_task_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for dispose_capacity -- ---------------------------- DROP TABLE IF EXISTS `dispose_capacity`; -CREATE TABLE `dispose_capacity` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备处置能力唯一标识符', - `deviceId` int(11) UNSIGNED NOT NULL COMMENT '设备ID', - `capacityType` int(8) NOT NULL COMMENT '处置能力:\r\n0:清洗\r\n1:高防 \r\n2:路由黑洞 \r\n3:检测\r\n4:WAF封堵\r\n', - `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', - `ipType` int(8) NOT NULL DEFAULT 3 COMMENT 'IP 地址类型:\r\n1 << 0:支持IPV4\r\n1 << 1:支持IPV6', - `protectIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '该处置能力能够处置的IP', - `reserveNetflow` int(11) NULL DEFAULT NULL COMMENT '清洗能力储备流量值,单位(G)', - PRIMARY KEY (`id`) USING BTREE, - INDEX `id`(`deviceId`) USING BTREE, - CONSTRAINT `dispose_capacity_ibfk_1` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `dispose_capacity` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备处置能力唯一标识符', + `deviceId` int(11) UNSIGNED NOT NULL COMMENT '设备ID', + `capacityType` int(8) NOT NULL COMMENT '处置能力:\r\n0:清洗\r\n1:高防 \r\n2:路由黑洞 \r\n3:检测\r\n4:WAF封堵\r\n', + `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', + `ipType` int(8) NOT NULL DEFAULT 3 COMMENT 'IP 地址类型:\r\n1 << 0:支持IPV4\r\n1 << 1:支持IPV6', + `protectIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '该处置能力能够处置的IP', + `reserveNetflow` int(11) NULL DEFAULT NULL COMMENT '清洗能力储备流量值,单位(G)', + PRIMARY KEY (`id`) USING BTREE, + INDEX `id` (`deviceId`) USING BTREE, + CONSTRAINT `dispose_capacity_ibfk_1` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for dispose_device -- ---------------------------- DROP TABLE IF EXISTS `dispose_device`; -CREATE TABLE `dispose_device` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符', - `ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备IP地址, IPv4/IPv6', - `ipPort` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '端口', - `deviceType` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备', - `areaCode` int(11) NOT NULL COMMENT '设备物理位置区域码', - `deviceName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称', - `manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商', - `model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号', - `version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本', - `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名', - `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码', - `urlPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL路径', - `urlType` int(11) NOT NULL DEFAULT 0 COMMENT 'URL类型: 0: HTTP, 1: HTTPS', - `readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注', - `status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常,1:锁定,2:禁用, 3:删除', - PRIMARY KEY (`id`) USING BTREE, - INDEX `ipAddr`(`ipAddr`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `dispose_device` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符', + `ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备IP地址, IPv4/IPv6', + `ipPort` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '端口', + `deviceType` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备', + `areaCode` int(11) NOT NULL COMMENT '设备物理位置区域码', + `deviceName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称', + `manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商', + `model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号', + `version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本', + `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名', + `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码', + `urlPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL路径', + `urlType` int(11) NOT NULL DEFAULT 0 COMMENT 'URL类型: 0: HTTP, 1: HTTPS', + `readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注', + `status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常,1:锁定,2:禁用, 3:删除', + PRIMARY KEY (`id`) USING BTREE, + INDEX `ipAddr` (`ipAddr`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; -- ---------------------------- -- Table structure for dispose_task -- ---------------------------- DROP TABLE IF EXISTS `dispose_task`; -CREATE TABLE `dispose_task` ( - `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符', - `deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符', - `accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符', - `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测', - `disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象', - `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', - `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '开始时间', - `planEndTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '计划结束时间', - `endTime` timestamp(0) NULL DEFAULT '1970-01-02 00:00:00' COMMENT '实际结束时间', - `flowDirection` int(11) NOT NULL DEFAULT 2 COMMENT '流量方向, 0:流入;1:流出;2:双向', - `attackType` bigint(20) UNSIGNED NOT NULL DEFAULT 18446744073709551615 COMMENT '攻击类型,默认0, 全部攻击', - `flowBandWidth` int(10) UNSIGNED NULL DEFAULT 1024 COMMENT '攻击流量占用带宽(MB)', - `currentStatus` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:停止。1:启动', - PRIMARY KEY (`id`) USING BTREE, - INDEX `dispose_task_device_capacity_id_fk`(`disposeCapacity`) USING BTREE, - INDEX `dispose_task_user_account_id_fk`(`accountId`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC; +CREATE TABLE `dispose_task` +( + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符', + `deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符', + `accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符', + `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测', + `disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象', + `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', + `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '开始时间', + `planEndTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '计划结束时间', + `endTime` timestamp(0) NULL DEFAULT '1970-01-02 00:00:00' COMMENT '实际结束时间', + `flowDirection` int(11) NOT NULL DEFAULT 2 COMMENT '流量方向, 0:流入;1:流出;2:双向', + `attackType` bigint(20) UNSIGNED NOT NULL DEFAULT 18446744073709551615 COMMENT '攻击类型,默认0, 全部攻击', + `flowBandWidth` int(10) UNSIGNED NULL DEFAULT 1024 COMMENT '攻击流量占用带宽(MB)', + `currentStatus` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:停止。1:启动', + PRIMARY KEY (`id`) USING BTREE, + INDEX `dispose_task_device_capacity_id_fk` (`disposeCapacity`) USING BTREE, + INDEX `dispose_task_user_account_id_fk` (`accountId`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Table structure for user_account -- ---------------------------- DROP TABLE IF EXISTS `user_account`; -CREATE TABLE `user_account` ( - `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '账户唯一编号', - `username` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名', - `password` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码', - `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间', - `operators` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '操作员', - `lastLoginTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '最后一次成功登录时间', - `token` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户token', - `lastAccess` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '最后一次访问时间戳', - `lockTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '账户锁定时间', - `pwdErrTimes` int(10) NOT NULL DEFAULT 0 COMMENT '密码错误次数', - `status` int(11) NULL DEFAULT 0 COMMENT '账户状态', - PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `USERNAME`(`username`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `user_account` +( + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '账户唯一编号', + `username` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名', + `password` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码', + `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间', + `operators` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '操作员', + `lastLoginTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '最后一次成功登录时间', + `token` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户token', + `lastAccess` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '最后一次访问时间戳', + `lockTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '账户锁定时间', + `pwdErrTimes` int(10) NOT NULL DEFAULT 0 COMMENT '密码错误次数', + `status` int(11) NULL DEFAULT 0 COMMENT '账户状态', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `USERNAME` (`username`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/main/resources/test_db/unit_test.sql b/src/main/resources/test_db/unit_test.sql index 623e9489..cd96c29a 100644 --- a/src/main/resources/test_db/unit_test.sql +++ b/src/main/resources/test_db/unit_test.sql @@ -21,26 +21,31 @@ SET FOREIGN_KEY_CHECKS = 0; -- Table structure for device_task -- ---------------------------- DROP TABLE IF EXISTS `device_task`; -CREATE TABLE `device_task` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符', - `taskId` int(11) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符', - `deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符', - `beginTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务开始时间', - `endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间', - `taskAttackType` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '需要处置的攻击类型', - `execAttackTypeIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Input)', - `attackTypeStatusIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', - `execAttackTypeOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Output)', - `attackTypeStatusOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', - `externId` int(11) NULL DEFAULT NULL COMMENT '扩展任务ID', - `errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数', - `status` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '任务状态', - PRIMARY KEY (`id`) USING BTREE, - INDEX `task_info_ibfk_1`(`taskId`) USING BTREE, - INDEX `task_info_ibfk_2`(`deviceId`) USING BTREE, - CONSTRAINT `device_task_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `device_task_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `device_task` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '任务信息唯一标识符', + `taskId` int(11) UNSIGNED NOT NULL COMMENT '处置任务唯一标识符', + `deviceId` int(10) UNSIGNED NOT NULL COMMENT '处置设备唯一标识符', + `beginTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务开始时间', + `endTime` timestamp(0) NULL DEFAULT NULL COMMENT '任务结束时间', + `taskAttackType` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '需要处置的攻击类型', + `execAttackTypeIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Input)', + `attackTypeStatusIn` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', + `execAttackTypeOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '已经执行处置的攻击类型(Output)', + `attackTypeStatusOut` bigint(255) UNSIGNED NOT NULL DEFAULT 0 COMMENT '执行的攻击类型状态(Input)', + `externId` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '扩展任务ID', + `errRetry` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '调用失败重试次数', + `status` int(10) NOT NULL DEFAULT 0 COMMENT '任务状态', + PRIMARY KEY (`id`) USING BTREE, + INDEX `task_info_ibfk_1` (`taskId`) USING BTREE, + INDEX `task_info_ibfk_2` (`deviceId`) USING BTREE, + CONSTRAINT `device_task_ibfk_1` FOREIGN KEY (`taskId`) REFERENCES `dispose_task` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `device_task_ibfk_2` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of device_task @@ -50,115 +55,157 @@ CREATE TABLE `device_task` ( -- Table structure for dispose_capacity -- ---------------------------- DROP TABLE IF EXISTS `dispose_capacity`; -CREATE TABLE `dispose_capacity` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备处置能力唯一标识符', - `deviceId` int(11) UNSIGNED NOT NULL COMMENT '设备ID', - `capacityType` int(8) NOT NULL COMMENT '处置能力:\r\n0:清洗\r\n1:高防 \r\n2:路由黑洞 \r\n3:检测\r\n4:WAF封堵\r\n', - `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', - `ipType` int(8) NOT NULL DEFAULT 3 COMMENT 'IP 地址类型:\r\n1 << 0:支持IPV4\r\n1 << 1:支持IPV6', - `protectIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '该处置能力能够处置的IP', - `reserveNetflow` int(11) NULL DEFAULT NULL COMMENT '清洗能力储备流量值,单位(G)', - PRIMARY KEY (`id`) USING BTREE, - INDEX `id`(`deviceId`) USING BTREE, - CONSTRAINT `dispose_capacity_ibfk_1` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `dispose_capacity` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备处置能力唯一标识符', + `deviceId` int(11) UNSIGNED NOT NULL COMMENT '设备ID', + `capacityType` int(8) NOT NULL COMMENT '处置能力:\r\n0:清洗\r\n1:高防 \r\n2:路由黑洞 \r\n3:检测\r\n4:WAF封堵\r\n', + `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', + `ipType` int(8) NOT NULL DEFAULT 3 COMMENT 'IP 地址类型:\r\n1 << 0:支持IPV4\r\n1 << 1:支持IPV6', + `protectIp` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '该处置能力能够处置的IP', + `reserveNetflow` int(11) NULL DEFAULT NULL COMMENT '清洗能力储备流量值,单位(G)', + PRIMARY KEY (`id`) USING BTREE, + INDEX `id` (`deviceId`) USING BTREE, + CONSTRAINT `dispose_capacity_ibfk_1` FOREIGN KEY (`deviceId`) REFERENCES `dispose_device` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of dispose_capacity -- ---------------------------- -INSERT INTO `dispose_capacity` VALUES (1, 1, 0, 1, 3, '0.0.0.0', 10); -INSERT INTO `dispose_capacity` VALUES (2, 1, 1, 7, 3, '', NULL); -INSERT INTO `dispose_capacity` VALUES (3, 1, 2, 7, 3, '0.0.0.0', NULL); -INSERT INTO `dispose_capacity` VALUES (4, 1, 3, 1, 3, '0.0.0.0', NULL); +INSERT INTO `dispose_capacity` +VALUES (1, 1, 0, 1, 3, '0.0.0.0', 10); +INSERT INTO `dispose_capacity` +VALUES (2, 1, 1, 7, 3, '', NULL); +INSERT INTO `dispose_capacity` +VALUES (3, 1, 2, 7, 3, '0.0.0.0', NULL); +INSERT INTO `dispose_capacity` +VALUES (4, 1, 3, 1, 3, '0.0.0.0', NULL); -INSERT INTO `dispose_capacity` VALUES (5, 2, 0, 1, 3, '0.0.0.0', 10); -INSERT INTO `dispose_capacity` VALUES (6, 3, 0, 1, 3, '0.0.0.0', 10); -INSERT INTO `dispose_capacity` VALUES (7, 4, 0, 1, 3, '0.0.0.0', 10); +INSERT INTO `dispose_capacity` +VALUES (5, 2, 0, 1, 3, '0.0.0.0', 10); +INSERT INTO `dispose_capacity` +VALUES (6, 3, 0, 1, 3, '0.0.0.0', 10); +INSERT INTO `dispose_capacity` +VALUES (7, 4, 0, 1, 3, '0.0.0.0', 10); -- ---------------------------- -- Table structure for dispose_device -- ---------------------------- DROP TABLE IF EXISTS `dispose_device`; -CREATE TABLE `dispose_device` ( - `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符', - `ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备IP地址, IPv4/IPv6', - `ipPort` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '端口', - `deviceType` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备', - `areaCode` int(11) NOT NULL COMMENT '设备物理位置区域码', - `deviceName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称', - `manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商', - `model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号', - `version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本', - `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名', - `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码', - `urlPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL路径', - `urlType` int(11) NOT NULL DEFAULT 0 COMMENT 'URL类型: 0: HTTP, 1: HTTPS', - `readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注', - `status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常,1:锁定,2:禁用, 3:删除', - PRIMARY KEY (`id`) USING BTREE, - INDEX `ipAddr`(`ipAddr`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `dispose_device` +( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '设备唯一标识符', + `ipAddr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备IP地址, IPv4/IPv6', + `ipPort` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '端口', + `deviceType` int(11) NOT NULL DEFAULT 0 COMMENT '能力节点类型,0:迪普UMC平台,1:浩瀚设备', + `areaCode` int(11) NOT NULL COMMENT '设备物理位置区域码', + `deviceName` varchar(256) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备名称', + `manufacturer` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '生产厂商', + `model` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '型号', + `version` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '软件版本', + `userName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理用户名', + `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '系统管理密码', + `urlPath` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'URL路径', + `urlType` int(11) NOT NULL DEFAULT 0 COMMENT 'URL类型: 0: HTTP, 1: HTTPS', + `readme` varchar(1024) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '备注', + `status` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:正常,1:锁定,2:禁用, 3:删除', + PRIMARY KEY (`id`) USING BTREE, + INDEX `ipAddr` (`ipAddr`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of dispose_device -- ---------------------------- -INSERT INTO `dispose_device` VALUES (1, '127.0.0.1', '', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '1', '', '', 0, '持续集成单元测试用虚拟设备', 0); -INSERT INTO `dispose_device` VALUES (2, '127.0.0.1', '1000', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '1', '', '', 0, '持续集成单元测试用虚拟设备', 0); -INSERT INTO `dispose_device` VALUES (3, '127.0.0.1', '1001', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '0', '', '', 0, '持续集成单元测试用虚拟设备', 0); -INSERT INTO `dispose_device` VALUES (4, '127.0.0.1', '1002', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '0', '', '', 0, '持续集成单元测试用虚拟设备', 0); +INSERT INTO `dispose_device` +VALUES (1, '127.0.0.1', '', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '1', '', '', 0, + '持续集成单元测试用虚拟设备', 0); +INSERT INTO `dispose_device` +VALUES (2, '127.0.0.1', '1000', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '1', '', '', 0, + '持续集成单元测试用虚拟设备', 0); +INSERT INTO `dispose_device` +VALUES (3, '127.0.0.1', '1001', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '0', '', '', 0, + '持续集成单元测试用虚拟设备', 0); +INSERT INTO `dispose_device` +VALUES (4, '127.0.0.1', '1002', 999, 0, '虚拟处置设备', 'Virtual Dispose Device', 'CMCC', 'V0.0.1', '0', '', '', 0, + '持续集成单元测试用虚拟设备', 0); -- ---------------------------- -- Table structure for dispose_task -- ---------------------------- DROP TABLE IF EXISTS `dispose_task`; -CREATE TABLE `dispose_task` ( - `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符', - `deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符', - `accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符', - `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测', - `disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象', - `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', - `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '开始时间', - `planEndTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '计划结束时间', - `endTime` timestamp(0) NULL DEFAULT '1970-01-02 00:00:00' COMMENT '实际结束时间', - `flowDirection` int(11) NOT NULL DEFAULT 2 COMMENT '流量方向, 0:流入;1:流出;2:双向', - `attackType` bigint(20) UNSIGNED NOT NULL DEFAULT 18446744073709551615 COMMENT '攻击类型,默认0, 全部攻击', - `flowBandWidth` int(10) UNSIGNED NULL DEFAULT 1024 COMMENT '攻击流量占用带宽(MB)', - `currentStatus` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:停止。1:启动', - PRIMARY KEY (`id`) USING BTREE, - INDEX `dispose_task_device_capacity_id_fk`(`disposeCapacity`) USING BTREE, - INDEX `dispose_task_user_account_id_fk`(`accountId`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC; +CREATE TABLE `dispose_task` +( + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '处置任务唯一标识符', + `deviceId` int(10) NOT NULL COMMENT '处置设备唯一标识符', + `accountId` int(10) UNSIGNED NOT NULL COMMENT '用户唯一标识符', + `disposeCapacity` int(11) NOT NULL COMMENT '处置能力类型:0:清洗 1:高防 2:黑洞 3:检测', + `disposeObject` varchar(4096) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '处置对象', + `objectType` int(8) NOT NULL COMMENT '处置对象类型:\r\n0:IP\r\n1:域名 \r\n2:URL', + `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '开始时间', + `planEndTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '计划结束时间', + `endTime` timestamp(0) NULL DEFAULT '1970-01-02 00:00:00' COMMENT '实际结束时间', + `flowDirection` int(11) NOT NULL DEFAULT 2 COMMENT '流量方向, 0:流入;1:流出;2:双向', + `attackType` bigint(20) UNSIGNED NOT NULL DEFAULT 18446744073709551615 COMMENT '攻击类型,默认0, 全部攻击', + `flowBandWidth` int(10) UNSIGNED NULL DEFAULT 1024 COMMENT '攻击流量占用带宽(MB)', + `currentStatus` int(11) NOT NULL DEFAULT 0 COMMENT '状态,0:停止。1:启动', + PRIMARY KEY (`id`) USING BTREE, + INDEX `dispose_task_device_capacity_id_fk` (`disposeCapacity`) USING BTREE, + INDEX `dispose_task_user_account_id_fk` (`accountId`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of dispose_task -- ---------------------------- -INSERT INTO `dispose_task` VALUES (1, -1, 1, 0, '192.168.10.1', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, 1024, 0); -INSERT INTO `dispose_task` VALUES (2, -1, 1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, 1024, 0); +INSERT INTO `dispose_task` +VALUES (1, -1, 1, 0, '192.168.10.1', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, + 1024, 0); +INSERT INTO `dispose_task` +VALUES (2, -1, 1, 0, '192.168.10.2', 1, CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, + 1024, 0); -- ---------------------------- -- Table structure for user_account -- ---------------------------- DROP TABLE IF EXISTS `user_account`; -CREATE TABLE `user_account` ( - `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '账户唯一编号', - `username` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名', - `password` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码', - `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间', - `operators` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '操作员', - `lastLoginTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '最后一次成功登录时间', - `token` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户token', - `lastAccess` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '最后一次访问时间戳', - `lockTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '账户锁定时间', - `pwdErrTimes` int(10) NOT NULL DEFAULT 0 COMMENT '密码错误次数', - `status` int(11) NULL DEFAULT 0 COMMENT '账户状态', - PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `USERNAME`(`username`) USING BTREE -) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; +CREATE TABLE `user_account` +( + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '账户唯一编号', + `username` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名', + `password` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码', + `createTime` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间', + `operators` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '操作员', + `lastLoginTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '最后一次成功登录时间', + `token` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户token', + `lastAccess` timestamp(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '最后一次访问时间戳', + `lockTime` timestamp(0) NOT NULL DEFAULT '1970-01-02 00:00:00' COMMENT '账户锁定时间', + `pwdErrTimes` int(10) NOT NULL DEFAULT 0 COMMENT '密码错误次数', + `status` int(11) NULL DEFAULT 0 COMMENT '账户状态', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `USERNAME` (`username`) USING BTREE +) ENGINE = InnoDB + AUTO_INCREMENT = 1 + CHARACTER SET = utf8 + COLLATE = utf8_general_ci + ROW_FORMAT = Dynamic; -- ---------------------------- -- Records of user_account -- ---------------------------- -INSERT INTO `user_account` VALUES (1, 'admin', 'c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58', '1970-01-02 00:00:00', '', '2020-09-11 00:34:16', 'c02094875da6d6b60a5ac7f056d40066a85005569bf7ce8ff03a50963651f931', '2020-09-11 00:34:16', '1970-01-02 00:00:00', 0, 0); +INSERT INTO `user_account` +VALUES (1, 'admin', 'c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58', '1970-01-02 00:00:00', '', + '2020-09-11 00:34:16', 'c02094875da6d6b60a5ac7f056d40066a85005569bf7ce8ff03a50963651f931', + '2020-09-11 00:34:16', '1970-01-02 00:00:00', 0, 0); SET FOREIGN_KEY_CHECKS = 1; diff --git a/src/test/java/com/dispose/test/dev/debug/demo.java b/src/test/java/com/dispose/test/dev/debug/demo.java index a05b74d5..ca2d7f18 100644 --- a/src/test/java/com/dispose/test/dev/debug/demo.java +++ b/src/test/java/com/dispose/test/dev/debug/demo.java @@ -562,4 +562,8 @@ public class demo { log.info("Src: {}", plainText); log.info("AES256: {}", new String(encode)); } + + @Test + public void codeDebug() { + } } diff --git a/src/test/java/com/dispose/test/dev/mapper/DeviceTaskMapperTest.java b/src/test/java/com/dispose/test/dev/mapper/DeviceTaskMapperTest.java index 558a8837..1e9501a8 100644 --- a/src/test/java/com/dispose/test/dev/mapper/DeviceTaskMapperTest.java +++ b/src/test/java/com/dispose/test/dev/mapper/DeviceTaskMapperTest.java @@ -262,7 +262,7 @@ public class DeviceTaskMapperTest extends InitTestEnvironment { // change extern id. for (long i = 223L; i <= 230L; i++) { - int result = deviceTaskMapper.changeExternId(deviceTask.getId(), i); + int result = deviceTaskMapper.changeExternId(deviceTask.getId(), String.valueOf(i)); Assert.assertEquals(result, 1); Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExternId())); } diff --git a/src/test/java/com/dispose/test/qa/DemoTest2.java b/src/test/java/com/dispose/test/qa/DemoTest2.java deleted file mode 100644 index d57f4421..00000000 --- a/src/test/java/com/dispose/test/qa/DemoTest2.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.dispose.test.qa; - -import lombok.extern.slf4j.Slf4j; -import org.junit.Test; -import org.wildfly.common.Assert; - -@Slf4j -public class DemoTest2 { - @Test - public void t1_demo() { - log.error("++++++++++++++++++++++com.dispose.test.qa.DemoTest2.t1_demo"); - Assert.assertFalse(false); - } -} diff --git a/src/test/java/com/dispose/test/qa/impl/DemoTest.java b/src/test/java/com/dispose/test/qa/impl/DemoTest.java deleted file mode 100644 index 56eff0d9..00000000 --- a/src/test/java/com/dispose/test/qa/impl/DemoTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.dispose.test.qa.impl; - -import lombok.extern.slf4j.Slf4j; -import org.junit.Test; -import org.wildfly.common.Assert; - -@Slf4j -public class DemoTest { - @Test - public void t1_demo() { - log.error("++++++++++++++++++++++com.dispose.test.qa.DemoTest.t1_demo"); - Assert.assertTrue(true); - } -}