OCT
REM: 1. 删除无用的Utils等源框架通用代码 2. 增加处置任务管理 3. 增加处置任务缓存管理 4. 增加通过处置IP获取处置设备功能 5. 增加部分单元测试功能 6. 修正部分CheckStyle警告项 7. 补充JavaDoc文档 8. 重新格式化代码 9. 删除获取应用程序git版本功能以及相关接口 10. 移除pom.xml配置文件重复依赖项
This commit is contained in:
parent
84c7539c69
commit
197a61c509
11
pom.xml
11
pom.xml
|
@ -120,10 +120,6 @@
|
|||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
|
@ -208,6 +204,11 @@
|
|||
<artifactId>cxf-rt-ws-security</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.seancfoley</groupId>
|
||||
<artifactId>ipaddress</artifactId>
|
||||
<version>5.2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -282,7 +283,7 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
<skip>${maven.test.skip}</skip>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Period;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* 日期常用工具方法
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月4日
|
||||
*/
|
||||
public class DateUtil {
|
||||
|
||||
public final static String YYYYMMWITHSYMBOL = "yyyy-MM";
|
||||
|
||||
public final static String YYYYMMDDWITHSYMBOL = "yyyy-MM-dd";
|
||||
|
||||
public final static String MMDD = "MM-dd";
|
||||
|
||||
public final static String MMDDHHMMSS = "MMddhhmmss";
|
||||
|
||||
public final static String YYYYMMDDHHMMSSSSS = "yyyyMMddHHmmssSSS";
|
||||
|
||||
public final static String YYYYMMDDHHMMSSWITHSYMBOL = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public final static String YYYYMMDDHHMMSSSSSWITHSYMBOL = "yyyy-MM-dd HH:mm:ss:SSS";
|
||||
|
||||
public final static String YYYYMMDDHHMMWITHSYMBOL = "yyyy-MM-dd HH:mm";
|
||||
|
||||
public final static String MMDDYYYYHHMMSSWITHSYMBOL = "MM/dd/yyyy hh:mm:ss a";
|
||||
|
||||
private static final Calendar calendar = Calendar.getInstance();
|
||||
|
||||
/**
|
||||
* @param strTime
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
public static Date s2d(String strTime, String pattern) {
|
||||
DateTime d = DateTimeFormat.forPattern(pattern).parseDateTime(strTime);
|
||||
return d.toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param date
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
public static String d2s(Date date, String pattern) {
|
||||
DateTime time = new DateTime(date);
|
||||
return time.toString(pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static Date getCurrentTime() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static Date getCurrentDate() {
|
||||
calendar.setTime(getCurrentTime());
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param date
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static Date addXDay(Date date, int x) {
|
||||
return new DateTime(date).plus(Period.days(x)).toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param date
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static Date addXMonth(Date date, int x) {
|
||||
return new DateTime(date).plus(Period.months(x)).toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param date
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static Date addXHour(Date date, int x) {
|
||||
return new DateTime(date).plus(Period.hours(x)).toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param date
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static Date addXMin(Date date, int x) {
|
||||
return new DateTime(date).plus(Period.minutes(x)).toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param date
|
||||
* @param x
|
||||
* @return
|
||||
*/
|
||||
public static Date addXSeconds(Date date, int x) {
|
||||
return new DateTime(date).plus(Period.seconds(x)).toDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param now
|
||||
* @param old
|
||||
* @param interval
|
||||
* @return
|
||||
*/
|
||||
public static boolean isExpire(Date now, Date old, int interval) {
|
||||
return addXSeconds(old, interval).before(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param begin
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
public static long getSecondsInterval(Date begin, Date end) {
|
||||
return (end.getTime() - begin.getTime()) / 1000;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,9 +21,21 @@ public enum DeviceCapacity {
|
|||
*/
|
||||
DETECIVE(3, "检测能力");
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
private final String readme;
|
||||
|
||||
/**
|
||||
* Instantiates a new Device capacity.
|
||||
*
|
||||
* @param code the code
|
||||
* @param readme the readme
|
||||
*/
|
||||
DeviceCapacity(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
|
|
|
@ -14,13 +14,25 @@ public enum DisposeDeviceType {
|
|||
HAOHAN_PLATFORM(1, "浩瀚处置设备"),
|
||||
|
||||
/**
|
||||
* Virtual dispose dispose device type.
|
||||
* 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;
|
||||
|
|
|
@ -1,15 +1,45 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Dispose task status.
|
||||
*/
|
||||
public enum DisposeTaskStatus {
|
||||
/**
|
||||
* Task new dispose task status.
|
||||
*/
|
||||
TASK_NEW(0, "新建"),
|
||||
/**
|
||||
* Task running dispose task status.
|
||||
*/
|
||||
TASK_RUNNING(1, "运行中"),
|
||||
/**
|
||||
* Task stop dispose task status.
|
||||
*/
|
||||
TASK_STOP(2, "停止"),
|
||||
/**
|
||||
* Task finish dispose task status.
|
||||
*/
|
||||
TASK_FINISH(3, "结束"),
|
||||
/**
|
||||
* Task delete dispose task status.
|
||||
*/
|
||||
TASK_DELETE(4, "删除");
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
private final String readme;
|
||||
|
||||
/**
|
||||
* Instantiates a new Dispose task status.
|
||||
*
|
||||
* @param code the code
|
||||
* @param readme the readme
|
||||
*/
|
||||
DisposeTaskStatus(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Dp tech attack type.
|
||||
*/
|
||||
public enum DpTechAttackType {
|
||||
/**
|
||||
* The Tcp syn flood.
|
||||
*/
|
||||
TCP_SYN_FLOOD(1,"TCP SYN Flood"),
|
||||
/**
|
||||
* The Udp flood.
|
||||
*/
|
||||
UDP_FLOOD(2,"UDP Flood"),
|
||||
/**
|
||||
* The Icmp flood.
|
||||
*/
|
||||
ICMP_FLOOD(3,"ICMP Flood"),
|
||||
/**
|
||||
* The Tcp syn ack flood.
|
||||
*/
|
||||
TCP_SYN_ACK_FLOOD(6,"TCP SYN-ACK Flood"),
|
||||
/**
|
||||
* The Tcp fin flood.
|
||||
*/
|
||||
TCP_FIN_FLOOD(7,"TCP FIN Flood"),
|
||||
/**
|
||||
* The Ip fragment flood.
|
||||
*/
|
||||
IP_FRAGMENT_FLOOD(8,"IP Fragment Flood"),
|
||||
/**
|
||||
* The Tcp ack flood.
|
||||
*/
|
||||
TCP_ACK_FLOOD(13,"TCP ACK Flood"),
|
||||
/**
|
||||
* The Cc flood.
|
||||
*/
|
||||
CC_FLOOD(15,"CC Flood"),
|
||||
/**
|
||||
* The Http flood.
|
||||
*/
|
||||
HTTP_FLOOD(14,"HTTP Flood"),
|
||||
/**
|
||||
* The Dns query flood.
|
||||
*/
|
||||
DNS_QUERY_FLOOD(16,"DNS Query Flood"),
|
||||
/**
|
||||
* The Dns reply flood.
|
||||
*/
|
||||
DNS_REPLY_FLOOD(33,"DNS Reply Flood"),
|
||||
/**
|
||||
* The Host total traffic.
|
||||
*/
|
||||
HOST_TOTAL_TRAFFIC(31,"Host Total Traffic");
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
private final String readme;
|
||||
|
||||
/**
|
||||
* Instantiates a new Dp tech attack type.
|
||||
*
|
||||
* @param code the code
|
||||
* @param readme the readme
|
||||
*/
|
||||
DpTechAttackType(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets readme.
|
||||
*
|
||||
* @return the readme
|
||||
*/
|
||||
public String getReadme() {
|
||||
return this.readme;
|
||||
}
|
||||
}
|
|
@ -5,110 +5,136 @@ package com.dispose.common;
|
|||
*/
|
||||
public enum ErrorCode {
|
||||
/**
|
||||
* Err ok error code.
|
||||
* The Err ok.
|
||||
*/
|
||||
ERR_OK(0, "成功"),
|
||||
/**
|
||||
* Err password error code.
|
||||
* The Err password.
|
||||
*/
|
||||
ERR_PASSWORD(1, "密码错误"),
|
||||
/**
|
||||
* Err usernotfound error code.
|
||||
* The Err usernotfound.
|
||||
*/
|
||||
ERR_USERNOTFOUND(2, "用户不存在"),
|
||||
/**
|
||||
* Err passwordmore error code.
|
||||
* The Err passwordmore.
|
||||
*/
|
||||
ERR_PASSWORDMORE(3, "连续密码错误达上限,再次输入错误将锁定用户"),
|
||||
/**
|
||||
* Err userlock error code.
|
||||
* The Err userlock.
|
||||
*/
|
||||
ERR_USERLOCK(4, "密码错误达上限,用户被锁定"),
|
||||
/**
|
||||
* Err account error code.
|
||||
* The Err account.
|
||||
*/
|
||||
ERR_ACCOUNT(5, "用户账户异常"),
|
||||
/**
|
||||
* Err userexist error code.
|
||||
* The Err userexist.
|
||||
*/
|
||||
ERR_USEREXIST(6, "该用户已经存在"),
|
||||
/**
|
||||
* Err passwordsimple error code.
|
||||
* The Err passwordsimple.
|
||||
*/
|
||||
ERR_PASSWORDSIMPLE(7, "用户密码强度不符合要求"),
|
||||
/**
|
||||
* Err inputformat error code.
|
||||
* The Err inputformat.
|
||||
*/
|
||||
ERR_INPUTFORMAT(8, "输入信息格式有误"),
|
||||
/**
|
||||
* Err inputmiss error code.
|
||||
* The Err inputmiss.
|
||||
*/
|
||||
ERR_INPUTMISS(9, "缺少必要输入信息"),
|
||||
/**
|
||||
* Err permission error code.
|
||||
* The Err permission.
|
||||
*/
|
||||
ERR_PERMISSION(10, "操作员权限不足"),
|
||||
/**
|
||||
* Err reqtimeout error code.
|
||||
* The Err reqtimeout.
|
||||
*/
|
||||
ERR_REQTIMEOUT(11, "请求超时"),
|
||||
/**
|
||||
* Err params error code.
|
||||
* The Err params.
|
||||
*/
|
||||
ERR_PARAMS(12, "参数错误"),
|
||||
/**
|
||||
* Err systemexception error code.
|
||||
* The Err systemexception.
|
||||
*/
|
||||
ERR_SYSTEMEXCEPTION(13, "系统异常"),
|
||||
/**
|
||||
* Err unknowncmd error code.
|
||||
* The Err unknowncmd.
|
||||
*/
|
||||
ERR_UNKNOWNCMD(14, "未知命令"),
|
||||
/**
|
||||
* Err logout error code.
|
||||
* The Err logout.
|
||||
*/
|
||||
ERR_LOGOUT(15, "用户未登录"),
|
||||
/**
|
||||
* Err tokentimeout error code.
|
||||
* The Err tokentimeout.
|
||||
*/
|
||||
ERR_TOKENTIMEOUT(16, "Token超时"),
|
||||
/**
|
||||
* Err tokennotfound error code.
|
||||
* The Err tokennotfound.
|
||||
*/
|
||||
ERR_TOKENNOTFOUND(17, "非法Token"),
|
||||
/**
|
||||
* Err missauthhead error code.
|
||||
* The Err missauthhead.
|
||||
*/
|
||||
ERR_MISSAUTHHEAD(18, "Http 请求缺少认证头部"),
|
||||
/**
|
||||
* Err nosuchdevice error code.
|
||||
* The Err nosuchdevice.
|
||||
*/
|
||||
ERR_NOSUCHDEVICE(19, "没有这个设备"),
|
||||
/**
|
||||
* Err deviceexists error code.
|
||||
* The Err deviceexists.
|
||||
*/
|
||||
ERR_DEVICEEXISTS(20, "设备已经存在"),
|
||||
/**
|
||||
* Err paramexception error code.
|
||||
* The Err paramexception.
|
||||
*/
|
||||
ERR_PARAMEXCEPTION(21, "参数异常"),
|
||||
/**
|
||||
* Err version error code.
|
||||
* The Err version.
|
||||
*/
|
||||
ERR_VERSION(23, "协议版本不兼容,请升级系统"),
|
||||
/**
|
||||
* Err nosuchtype error code.
|
||||
* The Err nosuchtype.
|
||||
*/
|
||||
ERR_NOSUCHTYPE(24, "没有这个类型的处置设备"),
|
||||
/**
|
||||
* Err removemore error code.
|
||||
* The Err removemore.
|
||||
*/
|
||||
ERR_REMOVEMORE(25, "禁止同时删除多个设备"),
|
||||
|
||||
/**
|
||||
* The Err taskrunning.
|
||||
*/
|
||||
ERR_TASKRUNNING(26, "同类任务正在运行"),
|
||||
|
||||
/**
|
||||
* Err nosupport error code.
|
||||
*/
|
||||
ERR_UNSUPPORT(27, "不支持的操作"),
|
||||
|
||||
ERR_INTERRUPT(28, "操作中断"),
|
||||
|
||||
ERR_CALLDEVICE(29, "调用设备失败"),
|
||||
;
|
||||
|
||||
/**
|
||||
* The Errno.
|
||||
*/
|
||||
private final int errno;
|
||||
/**
|
||||
* The Err msg.
|
||||
*/
|
||||
private final String errMsg;
|
||||
|
||||
/**
|
||||
* Instantiates a new Error code.
|
||||
*
|
||||
* @param err the err
|
||||
* @param msg the msg
|
||||
*/
|
||||
ErrorCode(int err, String msg) {
|
||||
this.errno = err;
|
||||
this.errMsg = msg;
|
||||
|
|
|
@ -1,13 +1,37 @@
|
|||
package com.dispose.common;
|
||||
|
||||
/**
|
||||
* The enum Flow direction.
|
||||
*/
|
||||
public enum FlowDirection {
|
||||
/**
|
||||
* Direction input flow direction.
|
||||
*/
|
||||
DIRECTION_INPUT(0, "流入"),
|
||||
/**
|
||||
* Direction output flow direction.
|
||||
*/
|
||||
DIRECTION_OUTPUT(1, "流出"),
|
||||
/**
|
||||
* Direction twoway flow direction.
|
||||
*/
|
||||
DIRECTION_TWOWAY(2, "双向");
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final int code;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
private final String readme;
|
||||
|
||||
/**
|
||||
* Instantiates a new Flow direction.
|
||||
*
|
||||
* @param code the code
|
||||
* @param readme the readme
|
||||
*/
|
||||
FlowDirection(int code, String readme) {
|
||||
this.code = code;
|
||||
this.readme = readme;
|
||||
|
|
|
@ -12,7 +12,7 @@ public class GlobalVar {
|
|||
/**
|
||||
* The constant SOAP_RECEIVE_TIMEOUT.
|
||||
*/
|
||||
public static final int SOAP_RECEIVE_TIMEOUT = 1000;
|
||||
public static final int SOAP_RECEIVE_TIMEOUT = 3000;
|
||||
/**
|
||||
* The constant MAX_THREAT_INFO_VERSION.
|
||||
*/
|
||||
|
|
|
@ -5,16 +5,17 @@ import cn.hutool.http.HttpRequest;
|
|||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: chiwei
|
||||
* @date: 2020年4月7日 下午2:05:50
|
||||
* The type Http.
|
||||
*/
|
||||
public class Http {
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* @param header
|
||||
* @param body
|
||||
* @return
|
||||
* Post json string.
|
||||
*
|
||||
* @param url the url
|
||||
* @param header the header
|
||||
* @param body the body
|
||||
* @return the string
|
||||
*/
|
||||
public static String postJson(String url, Map<String, String> header, String body) {
|
||||
return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
|
||||
|
@ -22,10 +23,12 @@ public class Http {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* @param header
|
||||
* @param body
|
||||
* @return
|
||||
* Post form string.
|
||||
*
|
||||
* @param url the url
|
||||
* @param header the header
|
||||
* @param body the body
|
||||
* @return the string
|
||||
*/
|
||||
public static String postForm(String url, Map<String, String> header, Map<String, Object> body) {
|
||||
//header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded")
|
||||
|
@ -34,9 +37,11 @@ public class Http {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* @param header
|
||||
* @return
|
||||
* Get string.
|
||||
*
|
||||
* @param url the url
|
||||
* @param header the header
|
||||
* @return the string
|
||||
*/
|
||||
public static String get(String url, Map<String, String> header) {
|
||||
return HttpRequest.get(url).addHeaders(header).execute().body();
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import inet.ipaddr.IPAddress;
|
||||
import inet.ipaddr.IPAddressSeqRange;
|
||||
import inet.ipaddr.IPAddressString;
|
||||
|
||||
/**
|
||||
* The enum Ip addr type.
|
||||
*/
|
||||
|
@ -26,4 +31,30 @@ public enum IPAddrType {
|
|||
return IPV4_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean ipInRange(String startIp, String endIp, String ipAddr) throws AddressStringException {
|
||||
IPAddress lower = new IPAddressString(startIp).toAddress();
|
||||
IPAddress upper = new IPAddressString(endIp).toAddress();
|
||||
IPAddress addr = new IPAddressString(ipAddr).toAddress();
|
||||
|
||||
IPAddressSeqRange range = lower.toSequentialRange(upper);
|
||||
|
||||
return range.contains(addr);
|
||||
}
|
||||
|
||||
public static boolean ipInRange(String rangeIp, String ipAddr) throws AddressStringException {
|
||||
String[] ipList = rangeIp.split("-");
|
||||
|
||||
if(ipList.length != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IPAddress lower = new IPAddressString(ipList[0]).toAddress();
|
||||
IPAddress upper = new IPAddressString(ipList[1]).toAddress();
|
||||
IPAddress addr = new IPAddressString(ipAddr).toAddress();
|
||||
|
||||
IPAddressSeqRange range = lower.toSequentialRange(upper);
|
||||
|
||||
return range.contains(addr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,286 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import org.apache.oro.text.regex.MalformedPatternException;
|
||||
import org.apache.oro.text.regex.Pattern;
|
||||
import org.apache.oro.text.regex.PatternCompiler;
|
||||
import org.apache.oro.text.regex.PatternMatcher;
|
||||
import org.apache.oro.text.regex.PatternMatcherInput;
|
||||
import org.apache.oro.text.regex.Perl5Compiler;
|
||||
import org.apache.oro.text.regex.Perl5Matcher;
|
||||
|
||||
/**
|
||||
* 常用正则工具
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月4日
|
||||
*/
|
||||
public class PatternUtil {
|
||||
|
||||
private static final PatternCompiler compiler = new Perl5Compiler();
|
||||
private static Pattern urlPattern = null;
|
||||
private static Pattern ipv6UrlPattern = null;
|
||||
private static Pattern noProtocolPattern = null;
|
||||
private static Pattern ipv6NoProtocolPattern = null;
|
||||
private static Pattern internalIpPattern = null;
|
||||
private static Pattern ipPattern = null;
|
||||
private static Pattern portPattern = null;
|
||||
private static Pattern ipPortPattern = null;
|
||||
private static Pattern internalIpPortPattern = null;
|
||||
private static Pattern inputPwdPattern = null;
|
||||
private static Pattern usernamePattern = null;
|
||||
private static Pattern msisdnPattern = null;
|
||||
private static Pattern domainPattern = null;
|
||||
private static Pattern emailPattern = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
// [a-zA-Z0-9][-a-zA-Z0-9]{0,62}(.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+.?
|
||||
// 域名
|
||||
domainPattern = compiler
|
||||
.compile("^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$");
|
||||
// http https url
|
||||
// (http|https)://[A-Za-z0-9_.#:/?&]+$
|
||||
// (https|http)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]
|
||||
// (https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]
|
||||
// https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)
|
||||
// 不支持IP地址
|
||||
// ^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]
|
||||
// ^(https|http)://([A-Za-z0-9]{1,}[-A-Za-z0-9+&@#/%?=~_|!:,.]{1,}[A-Za-z0-9]{1,})
|
||||
// https?:\/\/[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$ 有协议的
|
||||
urlPattern = compiler
|
||||
.compile("https?:\\/\\/[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]!%\\$&'\\(\\)\\*\\+,;=.]+$");
|
||||
// http url
|
||||
ipv6UrlPattern = compiler
|
||||
.compile("https?:\\/\\/\\[([A-Za-z0-9.:]+)\\][\\w\\-\\._~:/?#[\\]!%\\$&'\\(\\)\\*\\+,;=.]*$");
|
||||
|
||||
// [-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)
|
||||
// ^[A-Za-z0-9]{1,}[-A-Za-z0-9+&@#/%?=~_|!:,.]{1,}^.*?(?!://|:/).*?[A-Za-z0-9]{1,}$
|
||||
// [\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$
|
||||
noProtocolPattern = compiler
|
||||
.compile("[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!%\\$&'\\(\\)\\*\\+,;=.]+$");
|
||||
// ipv6+port
|
||||
ipv6NoProtocolPattern = compiler
|
||||
.compile("\\[([A-Za-z0-9.:]+)\\][\\w\\-\\._~:/?#[\\]!%\\$&'\\(\\)\\*\\+,;=.]*$");
|
||||
|
||||
// ip
|
||||
ipPattern = compiler.compile(
|
||||
"^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1," +
|
||||
"2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)$");
|
||||
// 内网IP
|
||||
internalIpPattern = compiler.compile(
|
||||
"((10\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(172"
|
||||
+ "\\.(1[6-9]|2[0-9]|3[0-1])\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(192"
|
||||
+ "\\.168\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)))");
|
||||
// 端口 port 1024-65535
|
||||
portPattern = compiler.compile(
|
||||
"^(102[4-9]|10[3-9][0-9]|1[1-9][0-9]{2}|[2-9][0-9]{3}|[1-5][0-9]{4}|6[0-4]{4}|65[0-4][0-9]{2}|655" +
|
||||
"[0-2][0-9]|6553[0-5])$");
|
||||
// ip port
|
||||
ipPortPattern = compiler.compile(
|
||||
"^(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1," +
|
||||
"2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ ":([0-9]{1,4}|[1-5][0-9]{4}|6[0-4]{4}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$");
|
||||
// 内网 ip port
|
||||
internalIpPortPattern = compiler.compile(
|
||||
"^((10\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)\\." +
|
||||
"(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(172"
|
||||
+ "\\.(1[6-9]|2[0-9]|3[0-1])\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0))|(192"
|
||||
+ "\\.168\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)"
|
||||
+ "\\.(25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[1-9]{1,2}|[1-9][0-9]|0)))"
|
||||
+ ":([0-9]{1,4}|[1-5][0-9]{4}|6[0-4]{4}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$");
|
||||
inputPwdPattern = compiler
|
||||
.compile("^(?![0-9]+$)(?![a-zA-Z]+$)(?![~!@#$%^&*()_+]+$)[0-9a-zA-Z~!@#$%^&*()_+]{8,16}$");
|
||||
// 用户名正则
|
||||
usernamePattern = compiler.compile("^[0-9a-zA-Z_]{4,16}$");
|
||||
// 手机号正则
|
||||
msisdnPattern = compiler.compile("^1[3,4,5,6,7,8,9][0-9]{9}$");
|
||||
// 邮箱格式
|
||||
emailPattern = compiler.compile("^[A-Za-z0-9\\u4e00-\\u9fa5_.]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
|
||||
} catch (MalformedPatternException e) {
|
||||
throw new RuntimeException("正则加载失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号正则校验
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isMsisdn(String str) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(str), msisdnPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱格式正则校验
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmail(String str) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(str), emailPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户名正则
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isUsername(String str) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(str), usernamePattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* url正则判断,http https
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isUrl(String url) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(url), urlPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* ipv6 url
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isIpv6Url(String url) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(url), ipv6UrlPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无协议url正则判断
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isNoProtocolUrl(String url) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(url), noProtocolPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无协议url正则判断
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isIpv6NoProtocolUrl(String url) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(url), ipv6NoProtocolPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 域名正则判断,http https
|
||||
*
|
||||
* @param domainName
|
||||
* @return
|
||||
*/
|
||||
public static boolean idDomainUrl(String domainName) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(domainName), domainPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* ip正则判断
|
||||
*
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
public static boolean isIp(String ip) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(ip), ipPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有IP正则
|
||||
*
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
public static boolean isInternalIp(String ip) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(ip), internalIpPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 外网IP正则判断
|
||||
*
|
||||
* @param ip
|
||||
* @return
|
||||
*/
|
||||
public static boolean isExternalIp(String ip) {
|
||||
return isIp(ip) && !isInternalIp(ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* 端口判断1024开始
|
||||
*
|
||||
* @param port
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPort(String port) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(port), portPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* ip端口整体正则判断
|
||||
*
|
||||
* @param ipPort
|
||||
* @return
|
||||
*/
|
||||
public static boolean isIpPort(String ipPort) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(ipPort), ipPortPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 私有ip端口正则判断
|
||||
*
|
||||
* @param internalIpPort
|
||||
* @return
|
||||
*/
|
||||
public static boolean isInternalIpPort(String internalIpPort) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(internalIpPort), internalIpPortPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 外网ip端口正则判断
|
||||
*
|
||||
* @param externalIpPort
|
||||
* @return
|
||||
*/
|
||||
public static boolean isExternalIpPort(String externalIpPort) {
|
||||
return isIpPort(externalIpPort) && !isInternalIpPort(externalIpPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pwd
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPwd(String pwd) {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
return matcher.matches(new PatternMatcherInput(pwd), inputPwdPattern);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,366 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* ClassName:Utils <br/>
|
||||
* Function: TODO ADD FUNCTION. <br/>
|
||||
* Reason: TODO ADD REASON. <br/>
|
||||
* Date: 2016年11月15日 下午2:42:45 <br/>
|
||||
*
|
||||
* @author chiwei
|
||||
* @see
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
@Slf4j
|
||||
public class Utils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
|
||||
private static final Random r = new SecureRandom();
|
||||
/**
|
||||
* genPwd:(). <br/>
|
||||
* <p>
|
||||
* 生成随机密码
|
||||
*
|
||||
* @author chiwei
|
||||
* @param len
|
||||
* @return
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
private static final String letter = "0123456789abcdefjhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private static final String base = "ABCDEFGHKMNPRWX2345689defhijkmnpqwxyz";
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static String getHostByUrl(String url) {
|
||||
try {
|
||||
URL myUrl = new URL(url);
|
||||
URI uri = new URI(null, null, myUrl.getHost(), myUrl.getPort(), null, null, null);
|
||||
return uri.getHost();
|
||||
} catch (Exception e) {
|
||||
log.error(url + " 获取domain异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static String getSchemaHostByUrl(String url) {
|
||||
try {
|
||||
URL myUrl = new URL(url);
|
||||
URI uri = new URI(myUrl.getProtocol(), myUrl.getUserInfo(), myUrl.getHost(), myUrl.getPort(), null, null,
|
||||
null);
|
||||
return uri.toString();
|
||||
} catch (Exception e) {
|
||||
logger.error(url + " 获取schema host异常", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domain
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getIpByDomain(String domain) {
|
||||
List<String> ipList = Lists.newArrayList();
|
||||
try {
|
||||
InetAddress[] addresses = InetAddress.getAllByName(domain);
|
||||
for (int i = 0; i < addresses.length; i++) {
|
||||
ipList.add(addresses[i].getHostAddress());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("域名解析IP异常", e);
|
||||
}
|
||||
return ipList;
|
||||
}
|
||||
|
||||
/**
|
||||
* readReqMsg:(). <br/>
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static String readReqMsg(HttpServletRequest request) {
|
||||
StringBuffer reqMsg = new StringBuffer();
|
||||
BufferedReader reader;
|
||||
try {
|
||||
reader = request.getReader();
|
||||
String str = "";
|
||||
while ((str = reader.readLine()) != null) {
|
||||
reqMsg.append(str);
|
||||
}
|
||||
return reqMsg.toString();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("请求信息读取有误");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* filterStr:(). <br/>
|
||||
* <p>
|
||||
* 过滤字符串前后空格以及空赋值
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static String filterStr(String str) {
|
||||
return str = (str == null ? "" : str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* lenOk:(). <br/>
|
||||
*
|
||||
* @param str
|
||||
* @param minLen
|
||||
* @param maxLen
|
||||
* @return
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static boolean lenOk(String str, int minLen, int maxLen) {
|
||||
return str.length() >= minLen && str.length() <= maxLen;
|
||||
}
|
||||
|
||||
/**
|
||||
* splitStr2List:(). <br/>
|
||||
*
|
||||
* @param str
|
||||
* @param seperator
|
||||
* @return
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static List<String> splitStr2List(String str, String seperator) {
|
||||
Iterator<String> iter = Splitter.on(seperator).trimResults().omitEmptyStrings().split(str).iterator();
|
||||
List<String> list = new ArrayList<String>();
|
||||
while (iter.hasNext()) {
|
||||
list.add(iter.next());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* genRandomNum:(). <br/>
|
||||
* <p>
|
||||
* 生成指定长度的随机数字
|
||||
*
|
||||
* @param len
|
||||
* @return
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static String genRandomNum(int len) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.append(r.nextInt(10));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
public static String genRandomStr(int len) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int letterLen = letter.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.append(letter.charAt(r.nextInt(letterLen)));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* uuid:(). <br/>
|
||||
*
|
||||
* @return
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static String uuid() {
|
||||
return UUID.randomUUID().toString().replaceAll("-", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* genRandomHexString:().<br/>
|
||||
* <p>
|
||||
* 获取16进制随机数
|
||||
*
|
||||
* @param len
|
||||
* @return
|
||||
* @author whb
|
||||
* @since JDK 1.8
|
||||
*/
|
||||
public static String genRandomHexString(int len) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.append(Integer.toHexString(r.nextInt(16)));
|
||||
}
|
||||
return sb.toString().toUpperCase();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* randomNum:(). <br/>
|
||||
*
|
||||
* @param begin
|
||||
* @param end
|
||||
* @return
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static int randomNum(int begin, int end) {
|
||||
return r.nextInt(end - begin) + begin;
|
||||
}
|
||||
|
||||
/**
|
||||
* genCode:(). <br/>
|
||||
* <p>
|
||||
* 图形验证码
|
||||
*
|
||||
* @param len
|
||||
* @return
|
||||
*/
|
||||
public static String genCode(int len) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.append(base.charAt(r.nextInt(base.length() - 1)));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* code:(). <br/>
|
||||
*
|
||||
* @param content
|
||||
* @param out
|
||||
* @throws Exception
|
||||
* @author chiwei
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public static void code(String content, OutputStream out) throws Exception {
|
||||
int width = 80;
|
||||
int height = 30;
|
||||
// 干扰颜色
|
||||
Color[] interColor = new Color[]{new Color(176, 196, 222), new Color(245, 222, 179), new Color(255, 228, 225),
|
||||
new Color(192, 192, 192)};
|
||||
// 字符颜色
|
||||
Color[] wordColor = new Color[]{new Color(47, 79, 79), new Color(0, 128, 128), new Color(95, 158, 160),
|
||||
new Color(70, 130, 180), new Color(105, 105, 105)};
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics g = image.getGraphics();
|
||||
// 背景画图
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, width, height);
|
||||
// 边框画图
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawRect(1, 1, width - 2, height - 2);
|
||||
// 干扰画图
|
||||
for (int i = 0; i < 20; i++) {
|
||||
int x1 = r.nextInt(width);
|
||||
int y1 = r.nextInt(height);
|
||||
int x2 = r.nextInt(width);
|
||||
int y2 = r.nextInt(height);
|
||||
g.setColor(interColor[r.nextInt(interColor.length - 1)]);
|
||||
g.drawLine(x1, y1, x2, y2);
|
||||
}
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
Font[] fonts = new Font[]{new Font("宋体", Font.BOLD, 30), new Font("黑体", Font.PLAIN, 30),
|
||||
new Font("楷体", Font.ITALIC, 30),};
|
||||
int x = 5;
|
||||
for (int i = 0; i < content.length(); i++) {
|
||||
g.setFont(fonts[r.nextInt(fonts.length - 1)]);
|
||||
g.setColor(wordColor[r.nextInt(wordColor.length - 1)]);
|
||||
int degree = r.nextInt() % 30;
|
||||
String ch = String.valueOf(content.charAt(i));
|
||||
// 设置旋转角度
|
||||
g2.rotate(degree * Math.PI / 180, x, 5);
|
||||
g2.drawString(ch, x, randomNum(20, 30));
|
||||
// 旋转回来
|
||||
g2.rotate(-degree * Math.PI / 180, x, 5);
|
||||
x += randomNum(15, 20);
|
||||
}
|
||||
ImageIO.write(image, "jpg", out);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
private static boolean urlIsReachable(String str) {
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(str);
|
||||
URLConnection co = url.openConnection();
|
||||
co.setConnectTimeout(1000);
|
||||
co.connect();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.error("URL " + str + " 不可达", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url url
|
||||
* @return urlIsReachable
|
||||
*/
|
||||
public static boolean checkFgUrl(String url) {
|
||||
if (!urlIsReachable(url)) {
|
||||
return urlIsReachable(url);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 防止缓存雪崩,随机过期时间
|
||||
*
|
||||
* @param ttl
|
||||
* @return
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
*/
|
||||
public static int randomTTL(int ttl) {
|
||||
return ttl + randomNum(0, ttl);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 1; i++) {
|
||||
System.out.println(genRandomStr(64));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.dispose.common;
|
||||
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorFactory;
|
||||
import org.hibernate.validator.HibernateValidator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
@Configuration
|
||||
public class ValidationConfig {
|
||||
|
||||
@Bean
|
||||
public Validator validator() {
|
||||
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure().failFast(true)
|
||||
.buildValidatorFactory();
|
||||
Validator validator = validatorFactory.getValidator();
|
||||
|
||||
return validator;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,16 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
@ConfigurationProperties(prefix = "dispose")
|
||||
public class DisposeConfigure {
|
||||
/**
|
||||
* The Check protocol timeout.
|
||||
*/
|
||||
private String checkProtocolTimeout;
|
||||
/**
|
||||
* The Check request token.
|
||||
*/
|
||||
private String checkRequestToken;
|
||||
/**
|
||||
* The Check admin permission.
|
||||
*/
|
||||
private String checkAdminPermission;
|
||||
}
|
||||
|
|
|
@ -6,10 +6,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 自定义配置
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
* The type My config.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -17,16 +14,49 @@ import org.springframework.stereotype.Component;
|
|||
@ConfigurationProperties(prefix = "phoenix")
|
||||
public class MyConfig {
|
||||
|
||||
/**
|
||||
* The System name.
|
||||
*/
|
||||
private String systemName;
|
||||
/**
|
||||
* The Swagger switch.
|
||||
*/
|
||||
private String swaggerSwitch;
|
||||
/**
|
||||
* The Redis server.
|
||||
*/
|
||||
private String redisServer;
|
||||
/**
|
||||
* The Request dec switch.
|
||||
*/
|
||||
private String requestDecSwitch;
|
||||
/**
|
||||
* The Response enc switch.
|
||||
*/
|
||||
private String responseEncSwitch;
|
||||
/**
|
||||
* The Aes key.
|
||||
*/
|
||||
private String aesKey;
|
||||
/**
|
||||
* The Redis redisson sentinel master name.
|
||||
*/
|
||||
private String redisRedissonSentinelMasterName;
|
||||
/**
|
||||
* The Redis redisson pwd.
|
||||
*/
|
||||
private String redisRedissonPwd;
|
||||
/**
|
||||
* The Threat info key.
|
||||
*/
|
||||
private String threatInfoKey;
|
||||
/**
|
||||
* The Threat info version url.
|
||||
*/
|
||||
private String threatInfoVersionUrl;
|
||||
/**
|
||||
* The Threat info download.
|
||||
*/
|
||||
private String threatInfoDownload;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.dispose.config;
|
||||
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.TaskService;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
|
@ -12,9 +13,17 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
@Slf4j
|
||||
public class SetupInit implements CommandLineRunner {
|
||||
/**
|
||||
* The Dispose node manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
/**
|
||||
* The Task service.
|
||||
*/
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
/**
|
||||
* Run.
|
||||
|
@ -25,8 +34,7 @@ public class SetupInit implements CommandLineRunner {
|
|||
public void run(String... args) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("System Setup................................................");
|
||||
//fileLoadService.mailFileRefresh();
|
||||
|
||||
disposeNodeManager.loadDisposeNodeFromDB();
|
||||
taskService.loadTaskFromDatabase();
|
||||
}
|
||||
}
|
|
@ -34,9 +34,15 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||
@Component
|
||||
public class AuthController {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
|
|
|
@ -42,9 +42,15 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
@Api(value = "抗DDoS处置平台能力节点信息接口", tags = "抗DDoS处置平台能力节点信息接口")
|
||||
@Component
|
||||
public class DisposeNodeInfoController {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Dispose node manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
|
|
|
@ -38,9 +38,15 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
@Api(value = "抗DDoS处置平台能力节点管理接口", tags = "抗DDoS处置平台能力节点管理接口")
|
||||
@Component
|
||||
public class DisposeNodeManagerController {
|
||||
/**
|
||||
* The Dispose node manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
/**
|
||||
* The User account cache manager.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountCacheManager userAccountCacheManager;
|
||||
|
||||
|
|
|
@ -181,6 +181,7 @@ public class DisposeTaskController {
|
|||
* @param mr the mr
|
||||
* @param headers the headers
|
||||
* @return the node task
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@PostMapping("/get_node")
|
||||
@ResponseBody
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.dispose.dispose;
|
||||
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import java.util.List;
|
||||
|
@ -10,12 +12,23 @@ import java.util.List;
|
|||
*/
|
||||
public interface DisposeEntryManager {
|
||||
/**
|
||||
* Run dispose int.
|
||||
* Run dispose error code.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @return the int
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
*/
|
||||
int runDispose(String ip);
|
||||
ErrorCode runDispose(String ip, DeviceCapacity type);
|
||||
|
||||
/**
|
||||
* Stop dispose error code.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode stopDispose(String ipAddr, DeviceCapacity type);
|
||||
|
||||
|
||||
/**
|
||||
* Gets all detection object.
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.dispose.dispose.impl;
|
|||
import com.dispose.Interceptor.SoapPasswordCallbackHandler;
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.DpTechAttackType;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.config.DisposeConfigure;
|
||||
|
@ -12,6 +14,7 @@ import com.dispose.pojo.po.DisposeDeviceCapacity;
|
|||
import com.dptech.dispose.AbnormalFlowCleaningServicePortType;
|
||||
import com.dptech.dispose.ArrayOfDetectionObjectDataForService;
|
||||
import com.dptech.dispose.ArrayOfProtectionObjectDataForService;
|
||||
import com.dptech.dispose.NtcRequestResultInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -38,6 +41,9 @@ public class DPTechImpl implements DisposeEntryManager {
|
|||
* The Clean type port.
|
||||
*/
|
||||
AbnormalFlowCleaningServicePortType cleanTypePort;
|
||||
/**
|
||||
* The Dispose configure.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeConfigure disposeConfigure;
|
||||
|
||||
|
@ -182,14 +188,77 @@ public class DPTechImpl implements DisposeEntryManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Run dispose int.
|
||||
* Run dispose boolean.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @return the int
|
||||
* @param type the type
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public int runDispose(String ip) {
|
||||
return 0;
|
||||
public ErrorCode runDispose(String ip, DeviceCapacity type) {
|
||||
if (type != DeviceCapacity.CLEANUP) {
|
||||
return ErrorCode.ERR_UNSUPPORT;
|
||||
}
|
||||
|
||||
try {
|
||||
for(int d : new int[] {0, 1}) {
|
||||
for (DpTechAttackType t : DpTechAttackType.values()) {
|
||||
NtcRequestResultInfo ret = cleanTypePort.startAbnormalTaskForUMC(ip,
|
||||
t.getCode(),
|
||||
d);
|
||||
|
||||
if (ret.getResultRetVal() != ErrorCode.ERR_OK.getCode()) {
|
||||
log.error("Start {} cleanup task error: {}", ip, ret.getResultInfo());
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
return ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_INTERRUPT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dispose boolean.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode stopDispose(String ipAddr, DeviceCapacity type) {
|
||||
if (type != DeviceCapacity.CLEANUP) {
|
||||
return ErrorCode.ERR_UNSUPPORT;
|
||||
}
|
||||
|
||||
try {
|
||||
for(int d : new int[] {0, 1}) {
|
||||
for (DpTechAttackType t : DpTechAttackType.values()) {
|
||||
NtcRequestResultInfo ret = cleanTypePort.stopAbnormalTaskForUMC(ipAddr,
|
||||
t.getCode(),
|
||||
d);
|
||||
|
||||
if (ret.getResultRetVal() != ErrorCode.ERR_OK.getCode()) {
|
||||
log.error("Start {} cleanup task error: {}", ipAddr, ret.getResultInfo());
|
||||
return ErrorCode.ERR_CALLDEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
return ErrorCode.ERR_SYSTEMEXCEPTION;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_INTERRUPT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.dispose.dispose.impl;
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.dispose.po.DeviceInfo;
|
||||
|
@ -12,23 +13,47 @@ import java.util.List;
|
|||
* The type Virtual device.
|
||||
*/
|
||||
public class VirtualDeviceImpl implements DisposeEntryManager {
|
||||
/**
|
||||
* Instantiates a new Virtual device.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
*/
|
||||
public VirtualDeviceImpl(String ipAddr) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Virtual device.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
*/
|
||||
public VirtualDeviceImpl(String ipAddr, IPAddrType type) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Run dispose int.
|
||||
* Run dispose boolean.
|
||||
*
|
||||
* @param ip the ip
|
||||
* @return the int
|
||||
* @param type the type
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public int runDispose(String ip) {
|
||||
return 0;
|
||||
public ErrorCode runDispose(String ip, DeviceCapacity type) {
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dispose boolean.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode stopDispose(String ipAddr, DeviceCapacity type) {
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +97,9 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
|
|||
|
||||
capList.add(DisposeDeviceCapacity.builder()
|
||||
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||
.protectIpV4(new String[]{"192.168.1.1", "192.168.1.2"})
|
||||
.protectIpV4(new String[]{"192.168.3.2-192.168.3.5",
|
||||
"192.168.5.2-192.168.5.10",
|
||||
"192.168.4.2-192.168.4.5"})
|
||||
.protectIpV6(new String[]{})
|
||||
.tolFlowCapacity(1024)
|
||||
.build());
|
||||
|
|
|
@ -11,14 +11,41 @@ import lombok.NoArgsConstructor;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
public class DeviceInfo {
|
||||
/**
|
||||
* The Vendor.
|
||||
*/
|
||||
private String vendor;
|
||||
/**
|
||||
* The Model.
|
||||
*/
|
||||
private String model;
|
||||
/**
|
||||
* The Firmware.
|
||||
*/
|
||||
private String firmware;
|
||||
/**
|
||||
* The Os.
|
||||
*/
|
||||
private String os;
|
||||
/**
|
||||
* The Kernel.
|
||||
*/
|
||||
private String kernel;
|
||||
/**
|
||||
* The Arch.
|
||||
*/
|
||||
private String arch;
|
||||
/**
|
||||
* The Memory.
|
||||
*/
|
||||
private int memory;
|
||||
/**
|
||||
* The Free memory.
|
||||
*/
|
||||
private int freeMemory;
|
||||
/**
|
||||
* The Cpu used.
|
||||
*/
|
||||
private int cpuUsed;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package com.dispose.help;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
public class GetVersion {
|
||||
private String commitId;
|
||||
private String commitDescribe;
|
||||
private String commitTime;
|
||||
private String tagName;
|
||||
private String tags;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.dispose.help;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* The type Git information.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Component
|
||||
@PropertySource("classpath:git.properties")
|
||||
public class GitInformation {
|
||||
@SuppressWarnings("checkstyle:MemberName")
|
||||
@Value("${git.commit.id}")
|
||||
private String commit_id;
|
||||
@SuppressWarnings("checkstyle:MemberName")
|
||||
@Value("${git.commit.id.describe}")
|
||||
private String commit_describe;
|
||||
@SuppressWarnings("checkstyle:MemberName")
|
||||
@Value("${git.commit.time}")
|
||||
private String commit_time;
|
||||
@SuppressWarnings("checkstyle:MemberName")
|
||||
@Value("${git.closest.tag.name}")
|
||||
private String tag_name;
|
||||
@Value("${git.tags}")
|
||||
private String tags;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.dispose.manager;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Task cache manager.
|
||||
*/
|
||||
public interface TaskCacheManager {
|
||||
/**
|
||||
* Add task error code.
|
||||
*
|
||||
* @param taskData the task data
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode addTask(TaskInfoDetail taskData);
|
||||
|
||||
/**
|
||||
* Gets task by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the task by id
|
||||
*/
|
||||
TaskInfoDetail getTaskById(Long id);
|
||||
|
||||
/**
|
||||
* Gets all task.
|
||||
*
|
||||
* @return the all task
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTask();
|
||||
|
||||
/**
|
||||
* Remove task error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode removeTask(Long id);
|
||||
|
||||
/**
|
||||
* Upgrade task status error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode upgradeTaskStatus(Long id, int status);
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package com.dispose.manager.impl;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* The type Task cache manager.
|
||||
*/
|
||||
@Component
|
||||
public class TaskCacheManagerImpl implements TaskCacheManager {
|
||||
/**
|
||||
* The Task cache map.
|
||||
*/
|
||||
private final ConcurrentHashMap<Long, TaskInfoDetail> taskCacheMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Gets all task.
|
||||
*
|
||||
* @return the all task
|
||||
*/
|
||||
@Override
|
||||
public List<TaskInfoDetail> getAllTask() {
|
||||
return new ArrayList<>(taskCacheMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets task by id.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the task by id
|
||||
*/
|
||||
@Override
|
||||
public TaskInfoDetail getTaskById(Long id) {
|
||||
if(taskCacheMap.containsKey(id)) {
|
||||
return taskCacheMap.get(id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add task error code.
|
||||
*
|
||||
* @param taskData the task data
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode addTask(TaskInfoDetail taskData) {
|
||||
if(taskData == null
|
||||
|| taskData.getDisposeIp() == null
|
||||
|| taskData.getDisposeIp().length() == 0) {
|
||||
return ErrorCode.ERR_INPUTMISS;
|
||||
}
|
||||
|
||||
if(taskCacheMap.containsKey(taskData.getId())) {
|
||||
return ErrorCode.ERR_DEVICEEXISTS;
|
||||
}
|
||||
|
||||
taskCacheMap.put(taskData.getId(), taskData);
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove task error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode removeTask(Long id) {
|
||||
|
||||
if(!taskCacheMap.containsKey(id)) {
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
taskCacheMap.remove(id);
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade task status error code.
|
||||
*
|
||||
* @param id the id
|
||||
* @param status the status
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode upgradeTaskStatus(Long id, int status) {
|
||||
if(!taskCacheMap.containsKey(id)) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
taskCacheMap.get(id).setCurrentStatus(status);
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
}
|
|
@ -24,10 +24,22 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
@Slf4j
|
||||
public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
|
||||
/**
|
||||
* The constant RANDOM_GEN.
|
||||
*/
|
||||
private static final Random RANDOM_GEN = new Random(System.currentTimeMillis());
|
||||
/**
|
||||
* The User account cache.
|
||||
*/
|
||||
private final ConcurrentHashMap<String, UserAccountCache> userAccountCache = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The Dispose configure.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeConfigure disposeConfigure;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
@ -247,6 +259,13 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user token string.
|
||||
*
|
||||
* @param username the username
|
||||
* @return the string
|
||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||
*/
|
||||
private String createUserToken(String username) throws NoSuchAlgorithmException {
|
||||
// 获取指定摘要算法的messageDigest对象
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); // 此处的sha代表sha1
|
||||
|
|
|
@ -103,4 +103,28 @@ public interface DisposeTaskMapper extends Mapper<TaskInfoDetail>,
|
|||
* @return the all task by status
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTaskByStatus(@Param("status") int status);
|
||||
|
||||
/**
|
||||
* Gets task by task info.
|
||||
*
|
||||
* @param devId the dev id
|
||||
* @param userId the user id
|
||||
* @param ipAddr the ip addr
|
||||
* @param type the type
|
||||
* @return the task by task info
|
||||
*/
|
||||
List<TaskInfoDetail> getTaskByTaskInfo(
|
||||
@Param("devId")Long devId,
|
||||
@Param("userId")Long userId,
|
||||
@Param("ipAddr")String ipAddr,
|
||||
@Param("type")int type
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets all task by type.
|
||||
*
|
||||
* @param type the type
|
||||
* @return the all task by type
|
||||
*/
|
||||
List<TaskInfoDetail> getAllTaskByType(@Param("type")int type);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,15 @@ import lombok.NoArgsConstructor;
|
|||
@ApiModel("通信协议实体")
|
||||
@JsonPropertyOrder({"ver", "cryptoType", "timeStamp", "msgContent"})
|
||||
public abstract class ProtocolDTO {
|
||||
/**
|
||||
* The Ver.
|
||||
*/
|
||||
@ApiModelProperty(value = "协议版本号", required = true, example = "1")
|
||||
private int ver;
|
||||
|
||||
/**
|
||||
* The Crypto type.
|
||||
*/
|
||||
@ApiModelProperty(value = "msgContent字段内容编码格式:\n" +
|
||||
"0:无编码格式,普通字符串\n" +
|
||||
"1:base64编码格式\n" +
|
||||
|
@ -29,9 +35,15 @@ public abstract class ProtocolDTO {
|
|||
example = "0")
|
||||
private int cryptoType;
|
||||
|
||||
/**
|
||||
* The Time stamp.
|
||||
*/
|
||||
@ApiModelProperty(value = "当前UTC时间戳", required = true, example = "1526625689000")
|
||||
private Long timeStamp;
|
||||
|
||||
/**
|
||||
* The Msg content.
|
||||
*/
|
||||
@ApiModelProperty(value = "协议详细内容,Json字符串格式。\n" +
|
||||
"保存该cmdId命令相关的详细内容,\n" +
|
||||
"具体每个cmdId命令的详细内容参看对应的命令协议定义",
|
||||
|
|
|
@ -18,8 +18,14 @@ import org.springframework.http.HttpHeaders;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ProtocolReqDTO extends ProtocolDTO {
|
||||
/**
|
||||
* The constant OBJECT_MAPPER.
|
||||
*/
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* The constant token.
|
||||
*/
|
||||
private static String token;
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,10 +24,20 @@ import lombok.NoArgsConstructor;
|
|||
@JsonPropertyOrder({"ver", "cryptoType", "timeStamp", "code", "msgContent"})
|
||||
public class ProtocolRespDTO extends ProtocolDTO {
|
||||
|
||||
@ApiModelProperty(value = "服务器返回状态码", required = false,
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
@ApiModelProperty(value = "服务器返回状态码",
|
||||
example = "200")
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* Gets object json.
|
||||
*
|
||||
* @param obj the obj
|
||||
* @return the object json
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
private static String getObjectJson(Object obj) throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
|
|
@ -36,19 +36,19 @@ public class DisposeDevice implements Serializable {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备唯一标识符
|
||||
* The Id.
|
||||
*/
|
||||
@Id
|
||||
//@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备IP地址, IPv4/IPv6
|
||||
* The Ip addr.
|
||||
*/
|
||||
private String ipAddr;
|
||||
|
||||
/**
|
||||
* 能力节点类型,能力节点类型,0:迪普UMC平台,1:浩瀚设备
|
||||
* The Type.
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
|
@ -58,47 +58,50 @@ public class DisposeDevice implements Serializable {
|
|||
private Integer areaCode;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
* The Name.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 生产厂商
|
||||
* The Manufacturer.
|
||||
*/
|
||||
private String manufacturer;
|
||||
|
||||
/**
|
||||
* 型号
|
||||
* The Model.
|
||||
*/
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* 软件版本
|
||||
* The Version.
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
* The Readme.
|
||||
*/
|
||||
private String readme;
|
||||
|
||||
/**
|
||||
* 状态,0:正常, 1:删除
|
||||
* The Status.
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 链路状态,0:断开连接, 1:正常
|
||||
* The Link status.
|
||||
*/
|
||||
@Transient
|
||||
private Integer linkStatus;
|
||||
|
||||
/**
|
||||
* 能力设备支持的能力列表
|
||||
* The Dev caps.
|
||||
*/
|
||||
@Transient
|
||||
private List<DisposeDeviceCapacity> devCaps;
|
||||
|
||||
/**
|
||||
* The Dev info.
|
||||
*/
|
||||
@Transient
|
||||
private DeviceInfo devInfo;
|
||||
}
|
||||
|
|
|
@ -32,35 +32,35 @@ public class UserAccount implements Serializable {
|
|||
private static final long serialVersionUID = -1L;
|
||||
|
||||
/**
|
||||
* 账户唯一编号
|
||||
* The Id.
|
||||
*/
|
||||
@Id
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
* The Username.
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码, SHA256
|
||||
* The Password.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 最后一次成功登录时间
|
||||
* The Last login time.
|
||||
*/
|
||||
private String lastLoginTime;
|
||||
|
||||
|
||||
/**
|
||||
* 账户锁定时间
|
||||
* The Lock time.
|
||||
*/
|
||||
private String lockTime;
|
||||
|
||||
/**
|
||||
* 账户状态
|
||||
* The Status.
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
||||
|
|
|
@ -19,22 +19,22 @@ import lombok.ToString;
|
|||
public class DisposeDeviceCapacity {
|
||||
|
||||
/**
|
||||
* 0:清洗 1:高防 2:黑洞 3: 检测
|
||||
* The Capacity.
|
||||
*/
|
||||
private Integer capacity;
|
||||
|
||||
/**
|
||||
* 处置设备储备能力(MB)
|
||||
* The Tol flow capacity.
|
||||
*/
|
||||
private Integer tolFlowCapacity;
|
||||
|
||||
/**
|
||||
* 防护IPv4对象
|
||||
* The Protect ip v 4.
|
||||
*/
|
||||
private String[] protectIpV4;
|
||||
|
||||
/**
|
||||
* 防护IPv6对象
|
||||
* The Protect ip v 6.
|
||||
*/
|
||||
private String[] protectIpV6;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,13 @@ import lombok.Getter;
|
|||
@Getter
|
||||
@Builder
|
||||
public class MReturnType<A, B> {
|
||||
/**
|
||||
* The First param.
|
||||
*/
|
||||
private final A firstParam;
|
||||
/**
|
||||
* The Second param.
|
||||
*/
|
||||
private final B secondParam;
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,18 +16,45 @@ import org.springframework.lang.Nullable;
|
|||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class NewNodeInfo {
|
||||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
private int type;
|
||||
/**
|
||||
* The Ip addr.
|
||||
*/
|
||||
private String ipAddr;
|
||||
/**
|
||||
* The Area code.
|
||||
*/
|
||||
private int areaCode;
|
||||
/**
|
||||
* The Name.
|
||||
*/
|
||||
@Nullable
|
||||
private String name;
|
||||
/**
|
||||
* The Manufacturer.
|
||||
*/
|
||||
@Nullable
|
||||
private String manufacturer;
|
||||
/**
|
||||
* The Model.
|
||||
*/
|
||||
@Nullable
|
||||
private String model;
|
||||
/**
|
||||
* The Version.
|
||||
*/
|
||||
@Nullable
|
||||
private String version;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
@Nullable
|
||||
private String readme;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,13 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ReturnStatus {
|
||||
/**
|
||||
* The Status.
|
||||
*/
|
||||
private int status;
|
||||
/**
|
||||
* The Message.
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,8 +9,20 @@ import lombok.Data;
|
|||
@Data
|
||||
@Builder
|
||||
public class UserAccountCache {
|
||||
/**
|
||||
* The Username.
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* The Token.
|
||||
*/
|
||||
private String token;
|
||||
/**
|
||||
* The Last access.
|
||||
*/
|
||||
private Long lastAccess;
|
||||
/**
|
||||
* The Pwd err times.
|
||||
*/
|
||||
private Integer pwdErrTimes;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,12 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class LoginReq {
|
||||
/**
|
||||
* The User name.
|
||||
*/
|
||||
private String userName;
|
||||
/**
|
||||
* The Password.
|
||||
*/
|
||||
private String password;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,20 @@ import lombok.NoArgsConstructor;
|
|||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"})
|
||||
public class LoginRsp extends ReturnStatus {
|
||||
/**
|
||||
* The User name.
|
||||
*/
|
||||
private String userName;
|
||||
/**
|
||||
* The Token.
|
||||
*/
|
||||
private String token;
|
||||
/**
|
||||
* The Log time.
|
||||
*/
|
||||
private Long logTime;
|
||||
/**
|
||||
* The Expire time.
|
||||
*/
|
||||
private Long expireTime;
|
||||
}
|
||||
|
|
|
@ -18,5 +18,8 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"userName", "token", "logTime", "expireTime", "status", "message"})
|
||||
public class LogoutRsp extends ReturnStatus {
|
||||
/**
|
||||
* The User name.
|
||||
*/
|
||||
private String userName;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,24 @@ import lombok.Setter;
|
|||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DisposeCapacity {
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
@JsonView(BaseView.class)
|
||||
private int type;
|
||||
/**
|
||||
* The Dispose ip.
|
||||
*/
|
||||
@JsonView(DependIpView.class)
|
||||
private String disposeIp;
|
||||
/**
|
||||
* The Tol capacity.
|
||||
*/
|
||||
@JsonView(CapacityView.class)
|
||||
private int tolCapacity;
|
||||
/**
|
||||
* The Used capacity.
|
||||
*/
|
||||
@JsonView(CapacityView.class)
|
||||
private int usedCapacity;
|
||||
|
||||
|
|
|
@ -15,6 +15,12 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class IDArrayReq {
|
||||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private String[] id;
|
||||
/**
|
||||
* The Task id.
|
||||
*/
|
||||
private String[] taskId;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,12 @@ import lombok.NoArgsConstructor;
|
|||
@JsonPropertyOrder({"id", "devId", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class IDReturnStatus extends ReturnStatus {
|
||||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* The Dev id.
|
||||
*/
|
||||
private String devId;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Task info data.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
|
@ -16,13 +19,40 @@ import lombok.NoArgsConstructor;
|
|||
@JsonPropertyOrder({"id", "taskId", "type", "disposeIp", "leftTime", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class TaskInfoData extends IDReturnStatus {
|
||||
/**
|
||||
* The Task id.
|
||||
*/
|
||||
private String taskId;
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* The Dispose ip.
|
||||
*/
|
||||
private String disposeIp;
|
||||
/**
|
||||
* The Left time.
|
||||
*/
|
||||
private Integer leftTime;
|
||||
/**
|
||||
* The Start time.
|
||||
*/
|
||||
private Integer startTime;
|
||||
/**
|
||||
* The Dispose time.
|
||||
*/
|
||||
private Integer disposeTime;
|
||||
/**
|
||||
* The Flow direction.
|
||||
*/
|
||||
private Integer flowDirection;
|
||||
/**
|
||||
* The Attack type.
|
||||
*/
|
||||
private Integer[] attackType;
|
||||
/**
|
||||
* The Flow band width.
|
||||
*/
|
||||
private Integer flowBandWidth;
|
||||
}
|
||||
|
|
|
@ -17,5 +17,8 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddNodeReq {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
private List<NewNodeInfo> items;
|
||||
}
|
||||
|
|
|
@ -18,5 +18,8 @@ import lombok.NoArgsConstructor;
|
|||
@JsonPropertyOrder({"id", "ipAddr", "devId", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AddNodeRetData extends IDReturnStatus {
|
||||
/**
|
||||
* The Ip addr.
|
||||
*/
|
||||
private String ipAddr;
|
||||
}
|
||||
|
|
|
@ -14,5 +14,8 @@ import lombok.NoArgsConstructor;
|
|||
@JsonPropertyOrder({"id", "capacity", "status", "message"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeviceCapacityRsp {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
private List<DeviceCapacityData> items;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,17 @@ import lombok.NoArgsConstructor;
|
|||
@JsonPropertyOrder({"id"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class DeviceInfoData extends DeviceInfo {
|
||||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* The Status.
|
||||
*/
|
||||
private int status;
|
||||
/**
|
||||
* The Message.
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,13 +22,37 @@ import lombok.NoArgsConstructor;
|
|||
@JsonPropertyOrder({"id", "type", "name", "ip", "areaCode", "manufacturer", "model", "version", "readme", "status",
|
||||
"message"})
|
||||
public class DisposeNodeData extends DeviceCapacityData {
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
private int type;
|
||||
/**
|
||||
* The Name.
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* The Ip.
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* The Area code.
|
||||
*/
|
||||
private Integer areaCode;
|
||||
/**
|
||||
* The Manufacturer.
|
||||
*/
|
||||
private String manufacturer;
|
||||
/**
|
||||
* The Model.
|
||||
*/
|
||||
private String model;
|
||||
/**
|
||||
* The Version.
|
||||
*/
|
||||
private String version;
|
||||
/**
|
||||
* The Readme.
|
||||
*/
|
||||
private String readme;
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,5 +10,8 @@ import lombok.NoArgsConstructor;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
public class DisposeNodeListRsp {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
private List<DisposeNodeData> items;
|
||||
}
|
||||
|
|
|
@ -18,5 +18,8 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "devId", "online", "status", "message"})
|
||||
public class LinkStatusRsp extends IDReturnStatus {
|
||||
/**
|
||||
* The Online.
|
||||
*/
|
||||
private int online;
|
||||
}
|
||||
|
|
|
@ -18,5 +18,8 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "devId", "version", "status", "message"})
|
||||
public class VersionRsp extends IDReturnStatus {
|
||||
/**
|
||||
* The Version.
|
||||
*/
|
||||
private String version;
|
||||
}
|
||||
|
|
|
@ -15,11 +15,32 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class StartTaskReq {
|
||||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private int id;
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
private int type;
|
||||
/**
|
||||
* The Dispose ip.
|
||||
*/
|
||||
private String disposeIp;
|
||||
/**
|
||||
* The Dispose time.
|
||||
*/
|
||||
private int disposeTime;
|
||||
/**
|
||||
* The Flow direction.
|
||||
*/
|
||||
private Integer flowDirection;
|
||||
/**
|
||||
* The Attack type.
|
||||
*/
|
||||
private Integer[] attackType;
|
||||
/**
|
||||
* The Flow band width.
|
||||
*/
|
||||
private Integer flowBandWidth;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Start task rsp.
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Builder
|
||||
|
@ -15,6 +18,12 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"id", "taskId", "expireTime", "status", "message"})
|
||||
public class StartTaskRsp extends IDReturnStatus {
|
||||
/**
|
||||
* The Task id.
|
||||
*/
|
||||
private String taskId;
|
||||
/**
|
||||
* The Expire time.
|
||||
*/
|
||||
private int expireTime;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,16 @@ import lombok.NoArgsConstructor;
|
|||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({"id", "type", "disposeIp"})
|
||||
public class StopTaskData {
|
||||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* The Type.
|
||||
*/
|
||||
private int type;
|
||||
/**
|
||||
* The Dispose ip.
|
||||
*/
|
||||
private String disposeIp;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,17 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The type Stop task req.
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class StopTaskReq {
|
||||
/**
|
||||
* The Items.
|
||||
*/
|
||||
List<StopTaskData> items;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.dispose.service;
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.MReturnType;
|
||||
|
@ -60,4 +61,13 @@ public interface DisposeNodeManager {
|
|||
* Load dispose node from db.
|
||||
*/
|
||||
void loadDisposeNodeFromDB();
|
||||
|
||||
/**
|
||||
* Gets dispose device.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param capacity the capacity
|
||||
* @return the dispose device
|
||||
*/
|
||||
DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package com.dispose.service;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
|
||||
/**
|
||||
* The interface Task service.
|
||||
*/
|
||||
public interface TaskService {
|
||||
/**
|
||||
* Load task from database.
|
||||
*/
|
||||
void loadTaskFromDatabase();
|
||||
|
||||
/**
|
||||
* Create task error code.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode createTask(TaskInfoDetail task);
|
||||
|
||||
/**
|
||||
* Start task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode startTask(Long taskId);
|
||||
|
||||
/**
|
||||
* Stop task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode stopTask(Long taskId);
|
||||
|
||||
/**
|
||||
* Finish task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
ErrorCode finishTask(Long taskId);
|
||||
|
||||
/**
|
||||
* Task is running boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean taskIsRunning(TaskInfoDetail task);
|
||||
|
||||
/**
|
||||
* Task is expired boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
boolean taskIsExpired(TaskInfoDetail task);
|
||||
}
|
|
@ -1,18 +1,22 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.IPAddrType;
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.pojo.po.MReturnType;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import inet.ipaddr.AddressStringException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -21,9 +25,18 @@ import org.springframework.stereotype.Service;
|
|||
*/
|
||||
@Service
|
||||
public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||
/**
|
||||
* The Dispose dev map.
|
||||
*/
|
||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
|
@ -174,11 +187,83 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
|||
return findRet.orElse(null);
|
||||
}
|
||||
|
||||
private Boolean isDisposeDeviceExists(String ipAddr) {
|
||||
return disposeDevMap.containsKey(ipAddr);
|
||||
// /**
|
||||
// * Is dispose device exists boolean.
|
||||
// *
|
||||
// * @param ipAddr the ip addr
|
||||
// * @return the boolean
|
||||
// */
|
||||
// private Boolean isDisposeDeviceExists(String ipAddr) {
|
||||
// return disposeDevMap.containsKey(ipAddr);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Add dispose device to cache.
|
||||
// *
|
||||
// * @param dev the dev
|
||||
// */
|
||||
// private void addDisposeDeviceToCache(DisposeDevice dev) {
|
||||
// disposeDevMap.put(dev.getIpAddr(), dev);
|
||||
// }
|
||||
//
|
||||
// private boolean devSupportCapacity(DisposeDevice dev, DeviceCapacity capacity) {
|
||||
// List<DisposeDeviceCapacity> capList = dev.getDevCaps()
|
||||
// .stream()
|
||||
// .filter(f -> f.getCapacity() == capacity.getCode())
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// return capList.size() > 0;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Is ip in range boolean.
|
||||
*
|
||||
* @param cap the cap
|
||||
* @param ipAddr the ip addr
|
||||
* @return the boolean
|
||||
*/
|
||||
private boolean isIpInRange(DisposeDeviceCapacity cap, String ipAddr) {
|
||||
try {
|
||||
if(IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV4_TYPE) {
|
||||
for(String s : cap.getProtectIpV4()) {
|
||||
if(IPAddrType.ipInRange(s, ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if(IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV6_TYPE) {
|
||||
for(String s : cap.getProtectIpV6()) {
|
||||
if(IPAddrType.ipInRange(s, ipAddr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (AddressStringException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addDisposeDeviceToCache(DisposeDevice dev) {
|
||||
disposeDevMap.put(dev.getIpAddr(), dev);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose device.
|
||||
*
|
||||
* @param ipAddr the ip addr
|
||||
* @param capacity the capacity
|
||||
* @return the dispose device
|
||||
*/
|
||||
@Override
|
||||
public DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity) {
|
||||
for (DisposeDevice dev : disposeDevMap.values()) {
|
||||
List<DisposeDeviceCapacity> capList = dev.getDevCaps()
|
||||
.stream()
|
||||
.filter(f -> f.getCapacity() == capacity.getCode())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if(capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
package com.dispose.service.impl;
|
||||
|
||||
import com.dispose.common.DisposeTaskStatus;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.service.TaskService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* The type Task service.
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TaskServiceImpl implements TaskService {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Task cache manager.
|
||||
*/
|
||||
@Resource
|
||||
private TaskCacheManager taskCacheManager;
|
||||
|
||||
/**
|
||||
* The Dispose task mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
|
||||
|
||||
/**
|
||||
* Load task from database.
|
||||
*/
|
||||
@Override
|
||||
public void loadTaskFromDatabase() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
if (taskCacheManager.addTask(v) != ErrorCode.ERR_OK) {
|
||||
try {
|
||||
log.error("load error:\n" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create task error code.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode createTask(TaskInfoDetail task) {
|
||||
ErrorCode err = taskCacheManager.addTask(task);
|
||||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
List<TaskInfoDetail> taskList = disposeTaskMapper.getTaskByTaskInfo(task.getId(), task.getAccountId(),
|
||||
task.getDisposeIp(), task.getType());
|
||||
|
||||
for (TaskInfoDetail v : taskList) {
|
||||
if (!taskIsExpired(v) && taskIsRunning(v)) {
|
||||
return ErrorCode.ERR_TASKRUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
disposeTaskMapper.addNewTask(task);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode startTask(Long taskId) {
|
||||
TaskInfoDetail task = taskCacheManager.getTaskById(taskId);
|
||||
|
||||
if (task == null) {
|
||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||
}
|
||||
|
||||
if(taskIsExpired(task)) {
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
} else if (!taskIsRunning(task)) {
|
||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode stopTask(Long taskId) {
|
||||
ErrorCode err = taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_STOP.getCode());
|
||||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_STOP.getCode());
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish task error code.
|
||||
*
|
||||
* @param taskId the task id
|
||||
* @return the error code
|
||||
*/
|
||||
@Override
|
||||
public ErrorCode finishTask(Long taskId) {
|
||||
ErrorCode err = taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
|
||||
if (err == ErrorCode.ERR_OK) {
|
||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Task is running boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean taskIsRunning(TaskInfoDetail task) {
|
||||
return task.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()
|
||||
|| task.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Task is expired boolean.
|
||||
*
|
||||
* @param task the task
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean taskIsExpired(TaskInfoDetail task) {
|
||||
LocalDateTime lt = LocalDateTime.parse(task.getPlanEndTime(),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
log.info(lt.toString());
|
||||
|
||||
return LocalDateTime.parse(task.getPlanEndTime(),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
||||
.isBefore(LocalDateTime.now());
|
||||
}
|
||||
}
|
|
@ -19,9 +19,15 @@ import org.springframework.stereotype.Service;
|
|||
@Slf4j
|
||||
public class UserAccountServiceImpl implements UserAccountService {
|
||||
|
||||
/**
|
||||
* The User account cache manager.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountCacheManager userAccountCacheManager;
|
||||
|
||||
/**
|
||||
* The User account mapper.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountMapper userAccountMapper;
|
||||
|
||||
|
|
|
@ -15,16 +15,23 @@ import springfox.documentation.spring.web.plugins.Docket;
|
|||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* @author phoenix
|
||||
* @date 2020年2月10日
|
||||
* The type Swagger 2 config.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
|
||||
/**
|
||||
* The My config.
|
||||
*/
|
||||
@Resource
|
||||
private MyConfig myConfig;
|
||||
|
||||
/**
|
||||
* Api docket.
|
||||
*
|
||||
* @return the docket
|
||||
*/
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).enable(Boolean.parseBoolean(myConfig.getSwaggerSwitch()))
|
||||
|
@ -34,6 +41,11 @@ public class Swagger2Config {
|
|||
.build().apiInfo(apiInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Api info api info.
|
||||
*
|
||||
* @return the api info
|
||||
*/
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfo(
|
||||
"phoenix脚手架工程API示例", "展示所有API信息,方便测试", "API V1.0", "xxx", new Contact("phoenix",
|
||||
|
|
|
@ -7,7 +7,6 @@ import com.dispose.pojo.entity.DisposeDevice;
|
|||
import com.dispose.service.DisposeNodeManager;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -16,8 +15,10 @@ import org.springframework.stereotype.Component;
|
|||
* The type Device manager task.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeviceManagerTask {
|
||||
/**
|
||||
* The Dispose node manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
|
@ -37,7 +38,6 @@ public class DeviceManagerTask {
|
|||
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
||||
v.setVersion(dp.getVersion());
|
||||
v.setDevInfo(dp.getDeviceInfo());
|
||||
log.info("Upgrade {} Device Status", v.getIpAddr());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package com.dispose.task;
|
||||
|
||||
import com.dispose.manager.TaskCacheManager;
|
||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||
import com.dispose.service.TaskService;
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* The type Task manager task.
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TaskManagerTask {
|
||||
/**
|
||||
* The Task cache manager.
|
||||
*/
|
||||
@Resource
|
||||
private TaskCacheManager taskCacheManager;
|
||||
|
||||
/**
|
||||
* The Task service.
|
||||
*/
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
/**
|
||||
* Thread pool task.
|
||||
*/
|
||||
@Async("bizExecutor")
|
||||
@Scheduled(fixedRate = 5000)
|
||||
public void threadPoolTask() {
|
||||
Iterator it = taskCacheManager.getAllTask().iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
TaskInfoDetail taskData = (TaskInfoDetail) it.next();
|
||||
|
||||
// if (taskData.getCurrentStatus() == DisposeTaskStatus.TASK_RUNNING.getCode()) {
|
||||
// if (taskService.taskIsExpired(taskData)) {
|
||||
// log.info("Finish Task {}", taskData.getId());
|
||||
// if (taskService.finishTask(taskData.getId()) != ErrorCode.ERR_OK) {
|
||||
// log.error("Finish Task {}:{} error\n", taskData.getId(), taskData.getDisposeIp());
|
||||
// }
|
||||
// } else {
|
||||
// if (taskService.startTask(taskData.getId()) != ErrorCode.ERR_OK) {
|
||||
// log.error("startTask Task {}:{} error\n", taskData.getId(), taskData.getDisposeIp());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } else if (taskData.getCurrentStatus() == DisposeTaskStatus.TASK_NEW.getCode()) {
|
||||
// log.info("Finish Task {}", taskData.getId());
|
||||
// if (taskService.finishTask(taskData.getId()) != ErrorCode.ERR_OK) {
|
||||
// log.error("Finish Task {}:{} error\n", taskData.getId(), taskData.getDisposeIp());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,12 +6,16 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
/**
|
||||
* @author phoenix
|
||||
* @date 2020年2月5日
|
||||
* The type Thread pool config.
|
||||
*/
|
||||
@Configuration
|
||||
public class ThreadPoolConfig {
|
||||
|
||||
/**
|
||||
* Log executor executor.
|
||||
*
|
||||
* @return the executor
|
||||
*/
|
||||
@Bean
|
||||
public Executor logExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
|
@ -21,6 +25,11 @@ public class ThreadPoolConfig {
|
|||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Biz executor executor.
|
||||
*
|
||||
* @return the executor
|
||||
*/
|
||||
@Bean
|
||||
public Executor bizExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
#Generated by Git-Commit-Id-Plugin
|
||||
#Tue Apr 21 15:12:20 CST 2020
|
||||
git.branch=master
|
||||
git.build.host=DESKTOP-GJUT8MA
|
||||
git.build.time=2020-04-21T15\:12\:20+0800
|
||||
git.build.user.email=huangxin@\u0096cmhi.chinamobile.com
|
||||
git.build.user.name=HuangXin
|
||||
git.build.version=1.0.0
|
||||
git.closest.tag.commit.count=
|
||||
git.closest.tag.name=
|
||||
git.commit.id=4c06518a8623bb94f3da53fa27e43cd5c60625e0
|
||||
git.commit.id.abbrev=4c06518
|
||||
git.commit.id.describe=4c06518-dirty
|
||||
git.commit.id.describe-short=4c06518-dirty
|
||||
git.commit.message.full=OCT\nREM\:\n1. \u6DFB\u52A0idea\u5DE5\u7A0B\u914D\u7F6E\u6587\u4EF6\u8FC7\u6EE4\u89C4\u5219
|
||||
git.commit.message.short=OCT REM\: 1. \u6DFB\u52A0idea\u5DE5\u7A0B\u914D\u7F6E\u6587\u4EF6\u8FC7\u6EE4\u89C4\u5219
|
||||
git.commit.time=2020-04-21T15\:06\:48+0800
|
||||
git.commit.user.email=huangxin@cmhi.chinamobile.com
|
||||
git.commit.user.name=huangxin
|
||||
git.dirty=true
|
||||
git.local.branch.ahead=0
|
||||
git.local.branch.behind=0
|
||||
git.remote.origin.url=git@git.komect.net\:DDOSAQ/phoenix_ddos_handle.git
|
||||
git.tags=
|
||||
git.total.commit.count=47
|
|
@ -27,6 +27,10 @@
|
|||
dispose_task
|
||||
SET
|
||||
currentStatus = #{status, jdbcType=INTEGER}
|
||||
<if test="status != @com.dispose.common.DisposeTaskStatus@TASK_NEW.getCode()
|
||||
and status != @com.dispose.common.DisposeTaskStatus@TASK_RUNNING.getCode()">
|
||||
, endTime = CURRENT_TIMESTAMP
|
||||
</if>
|
||||
WHERE
|
||||
id = #{id, jdbcType=INTEGER}
|
||||
</update>
|
||||
|
@ -85,4 +89,22 @@
|
|||
currentStatus = #{status, jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
<select id="getTaskByTaskInfo" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT * FROM dispose_task
|
||||
WHERE
|
||||
deviceId = #{devId, jdbcType=INTEGER} AND
|
||||
accountId = #{userId, jdbcType=INTEGER} AND
|
||||
disposeIp = #{ipAddr, jdbcType=VARCHAR} AND
|
||||
type = #{type, jdbcType=INTEGER} AND
|
||||
currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()} AND
|
||||
currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_FINISH.getCode()}
|
||||
</select>
|
||||
|
||||
<select id="getAllTaskByType" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||
SELECT * FROM dispose_task
|
||||
WHERE
|
||||
type = #{type, jdbcType=INTEGER} AND
|
||||
currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -19,9 +19,21 @@ import org.springframework.test.context.ActiveProfiles;
|
|||
@Getter
|
||||
@ActiveProfiles("test")
|
||||
public class InitTestEnvironment {
|
||||
/**
|
||||
* The constant logToken.
|
||||
*/
|
||||
private static String logToken = "45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122";
|
||||
/**
|
||||
* The User name.
|
||||
*/
|
||||
private final String USER_NAME = "admin";
|
||||
/**
|
||||
* The Password.
|
||||
*/
|
||||
private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58";
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ import com.dispose.controller.DeviceNodeInfoControllerTest;
|
|||
import com.dispose.controller.DeviceNodeManagerControllerTest;
|
||||
import com.dispose.controller.TaskControllerTest;
|
||||
import com.dispose.dptech.DPTechInterfaceTestCase;
|
||||
import com.dispose.help.GetVersionTest;
|
||||
import com.dispose.manager.UserAccountManagerTest;
|
||||
import com.dispose.mapper.DisposeDeviceMapperTest;
|
||||
import com.dispose.mapper.DisposeTaskMapperTest;
|
||||
import com.dispose.mapper.UserAccountMapperTest;
|
||||
import com.dispose.service.DisposeNodeManagerTest;
|
||||
import com.dispose.service.UserAccountServiceTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
@ -24,8 +24,8 @@ import org.junit.runners.Suite;
|
|||
@Suite.SuiteClasses({
|
||||
MyConfigTest.class,
|
||||
DisposeConfigureTest.class,
|
||||
GetVersionTest.class,
|
||||
DisposeTaskMapperTest.class,
|
||||
DisposeNodeManagerTest.class,
|
||||
DPTechInterfaceTestCase.class,
|
||||
UserAccountMapperTest.class,
|
||||
UserAccountManagerTest.class,
|
||||
|
@ -36,5 +36,6 @@ import org.junit.runners.Suite;
|
|||
UserAccountServiceTest.class,
|
||||
TaskControllerTest.class
|
||||
})
|
||||
|
||||
public class AllDisposePlatformTest {
|
||||
}
|
||||
|
|
|
@ -12,14 +12,25 @@ import org.junit.runners.MethodSorters;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* The type Dispose configure test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class DisposeConfigureTest {
|
||||
/**
|
||||
* The Dispose configure.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeConfigure disposeConfigure;
|
||||
|
||||
/**
|
||||
* T 1 dispose cfg test.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t1_disposeCfgTest() throws JsonProcessingException {
|
||||
Assert.assertNotNull(disposeConfigure);
|
||||
|
|
|
@ -12,14 +12,25 @@ import org.junit.runners.MethodSorters;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* The type My config test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class MyConfigTest {
|
||||
/**
|
||||
* The My config.
|
||||
*/
|
||||
@Resource
|
||||
private MyConfig myConfig;
|
||||
|
||||
/**
|
||||
* T 1 my config test.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
@Test
|
||||
public void t1_myConfigTest() throws JsonProcessingException {
|
||||
Assert.assertNotNull(myConfig);
|
||||
|
|
|
@ -32,8 +32,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@Slf4j
|
||||
public class AuthControllerTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
|
|
@ -34,19 +34,36 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
|
||||
/**
|
||||
* Gets exists device id.
|
||||
*
|
||||
* @return the exists device id
|
||||
*/
|
||||
private Long getExistsDeviceId() {
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
|
||||
|
@ -232,7 +249,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 3 get device protected ip.
|
||||
* T 4 get device protected ip.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -248,7 +265,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
||||
|
||||
String var = mockMvc.perform(MockMvcRequestBuilders
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/protected_ip")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", "Bearer " + getLogToken())
|
||||
|
@ -261,7 +278,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 3 get device protected ip all.
|
||||
* T 4 get device protected ip all.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -290,7 +307,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 3 get dispose node list.
|
||||
* T 5 get dispose node list.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -318,7 +335,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 3 get dispose node list all.
|
||||
* T 5 get dispose node list all.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -347,7 +364,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 3 get dispose node details.
|
||||
* T 6 get dispose node details.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -376,7 +393,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 3 get dispose node details all.
|
||||
* T 6 get dispose node details all.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
@ -404,6 +421,11 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
.getContentAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* T 7 get link status.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void t7_getLinkStatus() throws Exception {
|
||||
IDArrayReq reqData = IDArrayReq.builder()
|
||||
|
@ -428,6 +450,11 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
|||
.getContentAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* T 7 get link status all.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void t7_getLinkStatusAll() throws Exception {
|
||||
IDArrayReq reqData = IDArrayReq.builder()
|
||||
|
|
|
@ -33,9 +33,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
@Slf4j
|
||||
public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
@ -110,6 +116,11 @@ public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
|
|||
.getContentAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* T 3 del device err 1.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void t3_delDeviceErr1() throws Exception {
|
||||
IDArrayReq reqData = IDArrayReq.builder()
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.dispose.pojo.vo.common.IDArrayReq;
|
|||
import com.dispose.pojo.vo.task.StartTaskReq;
|
||||
import com.dispose.pojo.vo.task.StopTaskData;
|
||||
import com.dispose.pojo.vo.task.StopTaskReq;
|
||||
import com.dispose.service.UserAccountService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Resource;
|
||||
|
@ -33,15 +32,18 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class TaskControllerTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
/**
|
||||
* T 1 start task.
|
||||
*
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.dispose.dptech;
|
||||
|
||||
import com.dispose.Global.InitTestEnvironment;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.dispose.DeviceRouter;
|
||||
import com.dispose.dispose.DisposeEntryManager;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
|
@ -10,6 +12,7 @@ import com.dptech.dispose.ProtectionObjectDataForService;
|
|||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
|
@ -27,7 +30,12 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* User login.
|
||||
*/
|
||||
@Override
|
||||
public void userLogin() {
|
||||
}
|
||||
|
@ -46,6 +54,8 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
|||
|
||||
Assert.assertNotEquals(detDevs.size(), 0);
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(detDevs));
|
||||
|
||||
} catch (Exception ex) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
@ -65,6 +75,8 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
|||
|
||||
Assert.assertNotEquals(proDevs.length(), 0);
|
||||
|
||||
log.info("Protect Device: " + proDevs);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
@ -84,6 +96,8 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
|||
|
||||
Assert.assertNotEquals(proObjs.size(), 0);
|
||||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(proObjs));
|
||||
|
||||
} catch (Exception ex) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
@ -116,6 +130,22 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
|||
|
||||
Assert.assertNotEquals(capList.size(), 0);
|
||||
|
||||
log.info(new ObjectMapper().writeValueAsString(capList));
|
||||
log.info(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(capList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void t6_runDisposeTest() {
|
||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||
"10.88.77.15");
|
||||
|
||||
Assert.assertEquals(dp.runDispose("192.168.3.5", DeviceCapacity.CLEANUP), ErrorCode.ERR_OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void t7_stopDisposeTest() {
|
||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||
"10.88.77.15");
|
||||
|
||||
Assert.assertEquals(dp.stopDispose("192.168.3.5", DeviceCapacity.CLEANUP), ErrorCode.ERR_OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,14 @@ public class ExceptionTest {
|
|||
*/
|
||||
@Rule
|
||||
public ExpectedException expectedEx = ExpectedException.none();
|
||||
/**
|
||||
* The Mock mvc.
|
||||
*/
|
||||
@Resource
|
||||
private MockMvc mockMvc;
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package com.dispose.help;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@PropertySource("classpath:git.properties")
|
||||
public class GetVersionTest {
|
||||
@Resource
|
||||
private GitInformation gitInformation;
|
||||
|
||||
@Test
|
||||
public void t1_getVersionTest() throws JsonProcessingException {
|
||||
GetVersion ver = GetVersion.builder().commitId(gitInformation.getCommit_id())
|
||||
.commitDescribe(gitInformation.getCommit_describe())
|
||||
.commitTime(gitInformation.getCommit_time())
|
||||
.tagName(gitInformation.getTag_name())
|
||||
.tags(gitInformation.getTags())
|
||||
.build();
|
||||
|
||||
log.info(new ObjectMapper().writeValueAsString(ver));
|
||||
|
||||
Assert.assertNotNull(ver);
|
||||
}
|
||||
}
|
|
@ -25,9 +25,18 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class UserAccountManagerTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The constant userToken.
|
||||
*/
|
||||
private static String userToken;
|
||||
/**
|
||||
* The User account cache manager.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountCacheManager userAccountCacheManager;
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.dispose.Global.InitTestEnvironment;
|
|||
import com.dispose.common.DisposeDeviceType;
|
||||
import com.dispose.pojo.entity.DisposeDevice;
|
||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||
import com.dispose.service.DisposeNodeManager;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.util.ArrayList;
|
||||
|
@ -17,7 +16,9 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* The type Dispose device mapper test.
|
||||
|
@ -26,16 +27,21 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
/**
|
||||
* T 1 add new dispose device.
|
||||
*
|
||||
|
@ -61,7 +67,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
|||
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dev));
|
||||
|
||||
Assert.assertNotEquals(devId, dev.getId());
|
||||
Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(dev.getIpAddr()), 0);
|
||||
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
|
||||
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
|
||||
|
@ -128,7 +134,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 100 del dispose device by ip.
|
||||
* T 0 del dispose device by ip.
|
||||
*
|
||||
* @throws JsonProcessingException the json processing exception
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,9 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* The type Dispose task mapper test.
|
||||
|
@ -26,6 +28,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
@SpringBootTest
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class DisposeTaskMapperTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Obj mapper.
|
||||
|
@ -72,11 +76,10 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 1 add new task test.
|
||||
* Add new task test.
|
||||
*/
|
||||
@Test
|
||||
public void t1_addNewTaskTest() {
|
||||
LocalDateTime endTime = LocalDateTime.now().plusMinutes(10);
|
||||
public void addNewTaskTest() {
|
||||
TaskInfoDetail taskData = TaskInfoDetail.builder()
|
||||
.id(-1L)
|
||||
.deviceId(deviceId)
|
||||
|
@ -86,8 +89,8 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
.attackType("0")
|
||||
.flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode())
|
||||
.currentStatus(DisposeTaskStatus.TASK_NEW.getCode())
|
||||
.planEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
||||
.endTime(endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
||||
.planEndTime(LocalDateTime.now().plusMinutes(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd " +
|
||||
"HH:mm:ss")))
|
||||
.build();
|
||||
|
||||
disposeTaskMapper.addNewTask(taskData);
|
||||
|
@ -96,6 +99,17 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
Assert.assertNotNull(disposeTaskMapper.getTaskInfoById(taskData.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove task test.
|
||||
*/
|
||||
@Test
|
||||
public void removeTaskTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
disposeTaskMapper.removeTaskById(v.getId());
|
||||
Assert.assertNull(disposeTaskMapper.getTaskInfoById(v.getId()));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* T 2 change task status test.
|
||||
*/
|
||||
|
@ -105,6 +119,11 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
for (DisposeTaskStatus k : DisposeTaskStatus.values()) {
|
||||
disposeTaskMapper.changeTaskCurrentStatus(v.getId(), k.getCode());
|
||||
Assert.assertEquals(disposeTaskMapper.getTaskCurrentStatus(v.getId()), k.getCode());
|
||||
try {
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(v));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -132,6 +151,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Test
|
||||
public void t4_getAllTaskByDisposeIpTest() {
|
||||
Assert.assertNotNull(disposeTaskMapper.selectAll());
|
||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||
.getAllTaskByDisposeIp(v.getDisposeIp())
|
||||
.forEach(k -> {
|
||||
|
@ -146,7 +166,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 5 get all task by node dev id.
|
||||
* T 5 get all task by node dev id test.
|
||||
*/
|
||||
@Test
|
||||
public void t5_getAllTaskByNodeDevIdTest() {
|
||||
|
@ -164,7 +184,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 6 get all task by node user id.
|
||||
* T 6 get node all task by user id test.
|
||||
*/
|
||||
@Test
|
||||
public void t6_getNodeAllTaskByUserIdTest() {
|
||||
|
@ -181,10 +201,13 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* T 7 get node task by ip and status test.
|
||||
*/
|
||||
@Test
|
||||
public void t7_getNodeTaskByIpAndStatusTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||
.getNodeTaskByIpAndStatus(v.getAccountId(), v.getDisposeIp(), v.getCurrentStatus())
|
||||
.getNodeTaskByIpAndStatus(v.getDeviceId(), v.getDisposeIp(), v.getCurrentStatus())
|
||||
.forEach(k -> {
|
||||
Assert.assertEquals(k.getAccountId(), v.getAccountId());
|
||||
Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp());
|
||||
|
@ -199,13 +222,38 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
|||
}
|
||||
|
||||
/**
|
||||
* T 99 remove task test.
|
||||
* T 8 get all task by ip test.
|
||||
*/
|
||||
@Test
|
||||
public void t99_removeTaskTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
disposeTaskMapper.removeTaskById(v.getId());
|
||||
Assert.assertNull(disposeTaskMapper.getTaskInfoById(v.getId()));
|
||||
});
|
||||
public void t8_getAllTaskByIpTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||
.getAllTaskByIp(v.getDisposeIp())
|
||||
.forEach(k -> {
|
||||
Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp());
|
||||
try {
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* T 9 get all task by status test.
|
||||
*/
|
||||
@Test
|
||||
public void t9_getAllTaskByStatusTest() {
|
||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||
.getAllTaskByStatus(v.getCurrentStatus())
|
||||
.forEach(k -> {
|
||||
Assert.assertEquals(k.getCurrentStatus(), v.getCurrentStatus());
|
||||
try {
|
||||
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ import org.junit.runner.RunWith;
|
|||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* The type User account mapper test.
|
||||
|
@ -23,10 +25,18 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class UserAccountMapperTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Obj mapper.
|
||||
*/
|
||||
@Autowired
|
||||
private ObjectMapper objMapper;
|
||||
|
||||
/**
|
||||
* The User account mapper.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountMapper userAccountMapper;
|
||||
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package com.dispose.service;
|
||||
|
||||
import com.dispose.Global.InitTestEnvironment;
|
||||
import com.dispose.common.DeviceCapacity;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* The type Dispose node manager test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class DisposeNodeManagerTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The Object mapper.
|
||||
*/
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* The Dispose node manager.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeNodeManager disposeNodeManager;
|
||||
|
||||
/**
|
||||
* The Used ip addr.
|
||||
*/
|
||||
private final String[] usedIpAddr = new String[]{"192.168.3.2", "192.168.3.4",
|
||||
"192.168.5.8", "192.168.5.10",
|
||||
"192.168.4.2", "192.168.4.5"};
|
||||
|
||||
/**
|
||||
* The Un used ip addr.
|
||||
*/
|
||||
private final String[] unUsedIpAddr = new String[]{"192.168.3.1", "192.168.3.6",
|
||||
"192.168.6.8", "192.168.6.10",
|
||||
"0.0.0.0", "255.255.255.255"};
|
||||
|
||||
/**
|
||||
* User login.
|
||||
*/
|
||||
@Override
|
||||
public void userLogin() {
|
||||
}
|
||||
|
||||
/**
|
||||
* T 1 get dispose device test.
|
||||
*/
|
||||
@Test
|
||||
public void t1_getDisposeDeviceTest() {
|
||||
|
||||
for (String s : usedIpAddr) {
|
||||
Assert.assertNotNull(disposeNodeManager.getDisposeDevice(s, DeviceCapacity.CLEANUP));
|
||||
}
|
||||
|
||||
for (String s : unUsedIpAddr) {
|
||||
Assert.assertNull(disposeNodeManager.getDisposeDevice(s, DeviceCapacity.CLEANUP));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* T 2 load dispose node from db test.
|
||||
*/
|
||||
@Test
|
||||
public void t2_loadDisposeNodeFromDbTest() {
|
||||
Assert.assertNotEquals(disposeNodeManager.getAllDisposeDevice().size(), 0);
|
||||
}
|
||||
}
|
|
@ -16,15 +16,29 @@ import org.junit.runners.MethodSorters;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* The type User account service test.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class UserAccountServiceTest extends InitTestEnvironment {
|
||||
/**
|
||||
* The constant token.
|
||||
*/
|
||||
private static String token = "";
|
||||
/**
|
||||
* The User account service.
|
||||
*/
|
||||
@Resource
|
||||
private UserAccountService userAccountService;
|
||||
|
||||
/**
|
||||
* User login test.
|
||||
*
|
||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||
*/
|
||||
@Before
|
||||
public void userLoginTest() throws NoSuchAlgorithmException {
|
||||
MReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(),
|
||||
|
@ -35,6 +49,11 @@ public class UserAccountServiceTest extends InitTestEnvironment {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* T 1 log service test.
|
||||
*
|
||||
* @throws NoSuchAlgorithmException the no such algorithm exception
|
||||
*/
|
||||
@Test
|
||||
public void t1_logServiceTest() throws NoSuchAlgorithmException {
|
||||
MReturnType<ErrorCode, String> ret = userAccountService.loginService(getUSER_NAME(),
|
||||
|
@ -52,12 +71,18 @@ public class UserAccountServiceTest extends InitTestEnvironment {
|
|||
Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_PASSWORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* T 2 logout service test.
|
||||
*/
|
||||
@Test
|
||||
public void t2_logoutServiceTest() {
|
||||
ErrorCode err = userAccountService.logoutService(getUSER_NAME(), token);
|
||||
Assert.assertEquals(err, ErrorCode.ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* T 3 get user by token test.
|
||||
*/
|
||||
@Test
|
||||
public void t3_getUserByTokenTest() {
|
||||
UserAccount username = userAccountService.getUserByToken(UserAccountServiceTest.token);
|
||||
|
@ -65,6 +90,9 @@ public class UserAccountServiceTest extends InitTestEnvironment {
|
|||
Assert.assertEquals(username.getUsername(), getUSER_NAME());
|
||||
}
|
||||
|
||||
/**
|
||||
* T 4 auth token check test.
|
||||
*/
|
||||
@Test
|
||||
public void t4_authTokenCheckTest() {
|
||||
Assert.assertEquals(userAccountService.authTokenCheck(token), ErrorCode.ERR_OK);
|
||||
|
|
Loading…
Reference in New Issue