parent
a217dad8ec
commit
535d436d1e
|
@ -1,6 +0,0 @@
|
|||
# Default ignored files
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
/intellij-javadocs-4.0.1.xml
|
||||
/sqldialects.xml
|
|
@ -0,0 +1 @@
|
|||
phoenix-boot
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CheckStyle-IDEA">
|
||||
<option name="configuration">
|
||||
<map>
|
||||
<entry key="active-configuration" value="LOCAL_FILE:C:/Users/xajhu/Documents/checkstyle.xml:hyCheckStyle" />
|
||||
<entry key="checkstyle-version" value="8.23" />
|
||||
<entry key="copy-libs" value="true" />
|
||||
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
|
||||
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
|
||||
<entry key="location-2" value="LOCAL_FILE:C:/Users/xajhu/Documents/checkstyle.xml:hyCheckStyle" />
|
||||
<entry key="scan-before-checkin" value="false" />
|
||||
<entry key="scanscope" value="JavaOnly" />
|
||||
<entry key="suppress-errors" value="false" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
This folder contains libraries copied from the "phoenix_ddos_handle" project.
|
||||
It is managed by the CheckStyle-IDEA IDE plugin.
|
||||
Do not modify this folder while the IDE is running.
|
||||
When the IDE is stopped, you may delete this folder at any time. It will be recreated as needed.
|
||||
In order to prevent the CheckStyle-IDEA IDE plugin from creating this folder,
|
||||
uncheck the "Copy libraries from project directory" option in the CheckStyle-IDEA settings dialog.
|
|
@ -2,7 +2,6 @@
|
|||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
|
@ -12,7 +11,6 @@
|
|||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="phoenix-boot" target="1.8" />
|
||||
<module name="phoenix-data" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="@172.28.72.118" uuid="9e091392-bdd9-4edc-aa76-e9c49c1953c4">
|
||||
<driver-ref>mysql.8</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://172.28.72.118:33061/</jdbc-url>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
|
@ -3,6 +3,5 @@
|
|||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -8,10 +8,9 @@
|
|||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/data-pom.xml" />
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="13.0.1" project-jdk-type="JavaSDK" />
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources/mappers/DisposeDeviceManager.xml" dialect="GenericSQL" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,3 +0,0 @@
|
|||
# 把下面语句编辑到crontab里,定时清理日志,每天凌晨1点清理日志,保留7天日志
|
||||
|
||||
0 1 * * * find /apprun/phoenix-boot/logs -mtime +7 -name "*.log.*" -exec rm -rf {} \;
|
|
@ -1,26 +0,0 @@
|
|||
# crontab里加上进程自动拉起任务,做个简单的监控
|
||||
# */1 * * * * source /etc/profile;sh /apprun/${YOUR_APP_NAME}/bin/processor_check.sh
|
||||
# processor_check.sh脚本内容如下
|
||||
|
||||
#!/bin/bash
|
||||
APP_NAME=phoenix-boot.jar
|
||||
WORK_PATH=$(cd `dirname $0`; pwd)
|
||||
|
||||
pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
|
||||
if [ "$pids" -le 0 ]
|
||||
then
|
||||
echo "start $APP_NAME processor ......"
|
||||
cd $WORK_PATH
|
||||
cd ..
|
||||
nohup sh bin/start.sh >/dev/null 2>&1 &
|
||||
sleep 5
|
||||
pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
|
||||
if [ "$pids" -gt 0 ]
|
||||
then
|
||||
echo "$APP_NAME processor started"
|
||||
else
|
||||
echo "Failed to start $APP_NAME processor"
|
||||
fi
|
||||
else
|
||||
echo "$APP_NAME processor is running ......"
|
||||
fi
|
|
@ -1,8 +0,0 @@
|
|||
#!/bin/bash
|
||||
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n "
|
||||
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
|
||||
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -server -Xms512M -Xmx512M -Xss256K -XX:MetaspaceSize=16M -XX:MaxMetaspaceSize=128M -XX:MaxDirectMemorySize=1g -XX:SurvivorRatio=8 -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof"
|
||||
WORK_PATH=$(cd `dirname $0`; pwd)
|
||||
cd $WORK_PATH
|
||||
cd ..
|
||||
$JAVA_HOME/bin/java $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS $JAVA_OPTS -jar phoenix-boot.jar
|
15
bin/stop.sh
15
bin/stop.sh
|
@ -1,15 +0,0 @@
|
|||
#!/bin/bash
|
||||
APP_NAME=phoenix-boot.jar
|
||||
|
||||
pids=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
|
||||
for pid in $pids
|
||||
do
|
||||
echo stop $APP_NAME java process: $pid
|
||||
kill -9 $pid
|
||||
done
|
||||
|
||||
nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
|
||||
while [ $nr_pids -gt 0 ]
|
||||
do
|
||||
nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l`
|
||||
done
|
2
pom.xml
2
pom.xml
|
@ -219,7 +219,7 @@
|
|||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.cmcc.hy.phoenix.PhoenixBootApplication</mainClass>
|
||||
<mainClass>com.dispose.PhoenixBootApplication</mainClass>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
</manifest>
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.aop;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
|
||||
|
||||
import com.cmcc.aqb.enc.dec.AesECB;
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
import com.cmcc.hy.phoenix.config.MyConfig;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月10日
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice(basePackages = { "com.cmcc.hy.phoenix.controller" })
|
||||
public class MyRequestBodyAdvice implements RequestBodyAdvice {
|
||||
|
||||
@Resource
|
||||
private MyConfig myConfig;
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Type targetType,
|
||||
Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
// TODO Auto-generated method stub
|
||||
return Boolean.parseBoolean(myConfig.getRequestDecSwitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
|
||||
Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
if (parameter.hasMethodAnnotation(ReqDec.class)) {
|
||||
try {
|
||||
return decBody(inputMessage);
|
||||
} catch (Exception e) {
|
||||
log.error("报文解密异常", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return inputMessage;
|
||||
}
|
||||
|
||||
private HttpInputMessage decBody(HttpInputMessage inputMessage) throws Exception {
|
||||
String enc = IOUtils.toString(inputMessage.getBody(), StandardCharsets.UTF_8);
|
||||
log.info("接收密文: {}", enc);
|
||||
String plain = new String(AesECB.decByAes(Base64.decodeBase64(enc), myConfig.getAesKey()));
|
||||
log.info("解密明文: {}", plain);
|
||||
InputStream is = IOUtils.toInputStream(plain, "UTF-8");
|
||||
return new MyHttpInputMessage(inputMessage.getHeaders(), is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
|
||||
Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("RequestBodyAdvice afterBodyRead body {}", body);
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
|
||||
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("RequestBodyAdvice handleEmptyBody body {}", body);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MyHttpInputMessage implements HttpInputMessage {
|
||||
|
||||
private HttpHeaders headers;
|
||||
|
||||
private InputStream body;
|
||||
|
||||
public MyHttpInputMessage(HttpHeaders headers, InputStream body) throws Exception {
|
||||
this.headers = headers;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
// TODO Auto-generated method stub
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.aop;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
import com.cmcc.aqb.enc.dec.AesECB;
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.RespEnc;
|
||||
import com.cmcc.hy.phoenix.config.MyConfig;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.MyResp;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.Resp;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月10日
|
||||
*/
|
||||
@Slf4j
|
||||
@ControllerAdvice(basePackages = { "com.cmcc.hy.phoenix.controller" })
|
||||
public class MyResponseBodyAdvice implements ResponseBodyAdvice<Object> {
|
||||
|
||||
@Resource
|
||||
private MyConfig myConfig;
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
// TODO Auto-generated method stub
|
||||
return returnType.hasMethodAnnotation(RespEnc.class) && Boolean.parseBoolean(myConfig.getResponseEncSwitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
|
||||
Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
|
||||
ServerHttpResponse response) {
|
||||
// TODO Auto-generated method stub
|
||||
if (body != null) {
|
||||
try {
|
||||
MyResp resp = (MyResp) body;
|
||||
String data = (String) resp.getData();
|
||||
if (StringUtils.isNotEmpty(data)) {
|
||||
String newData = Base64.encodeBase64String(
|
||||
AesECB.encByAes(data.getBytes(StandardCharsets.UTF_8), myConfig.getAesKey()));
|
||||
resp.setData(newData);
|
||||
return resp;
|
||||
} else {
|
||||
if (Resp.SUCCESS.getCode() != resp.getCode()) {
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("response数据加密异常", e);
|
||||
return MyResp.result(Resp.ERROR);
|
||||
}
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.*;
|
||||
import com.cmcc.hy.phoenix.service.LoginService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Builder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/handle")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||
@Component
|
||||
public class AuthController {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private LoginService loginService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@ResponseBody
|
||||
@ApiOperation("登录")
|
||||
@ReqDec
|
||||
@Builder
|
||||
public ProtocolResp userLogin(@RequestBody(required = true) ProtocolDTO mr,
|
||||
@RequestHeader HttpHeaders headers) {
|
||||
String msgCtx = "";
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
log.info("请求token: {}", headers.get("Authorization"));
|
||||
log.info("请求参数 {}", mr);
|
||||
|
||||
|
||||
if(mr == null) {
|
||||
err = ErrorCode.ERR_PARAMS;
|
||||
return ProtocolResp.result(err, -1, msgCtx);
|
||||
} else if (mr.IsRequestTimeout()) {
|
||||
err = ErrorCode.ERR_REQTIMEOUT;
|
||||
} else {
|
||||
try {
|
||||
if(mr.getCmdId() == ConstValue.ProtocolCmdId.AUTH_LOGIN) {
|
||||
EnumMap<ErrorCode, String> loginMap = userLogin(mr);
|
||||
err = loginMap.keySet().iterator().next();
|
||||
msgCtx = loginMap.get(err);
|
||||
} else if (mr.getCmdId() == ConstValue.ProtocolCmdId.AUTH_LOGOUT) {
|
||||
if(headers.get("Authorization") == null) {
|
||||
err = ErrorCode.ERR_MISSAUTHHEAD;
|
||||
} else {
|
||||
String token = Objects.
|
||||
requireNonNull(headers.get("Authorization"))
|
||||
.get(0).replaceFirst("Bearer ", "");
|
||||
|
||||
err = loginService.authTokenCheck(token);
|
||||
|
||||
EnumMap<ErrorCode, String> loginMap = userLogout(mr, token);
|
||||
err = loginMap.keySet().iterator().next();
|
||||
msgCtx = loginMap.get(err);
|
||||
}
|
||||
}else {
|
||||
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||
}
|
||||
} catch (JsonProcessingException | NoSuchAlgorithmException ex) {
|
||||
log.error(ex.getMessage());
|
||||
err = ErrorCode.ERR_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
return ProtocolResp.result(err, mr.getCmdId(), msgCtx);
|
||||
}
|
||||
|
||||
private EnumMap<ErrorCode, String> userLogout(ProtocolDTO mr, String token)
|
||||
throws JsonProcessingException {
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
UserLogoutRsp rspInfo = UserLogoutRsp.builder()
|
||||
.userName("")
|
||||
.status(err.getCode())
|
||||
.message(err.getMsg()).build();
|
||||
|
||||
UserLogoutReq reqInfo = objectMapper.readValue(mr.getMsgContent(), UserLogoutReq.class);
|
||||
rspInfo.setUserName(reqInfo.getUserName());
|
||||
|
||||
err = loginService.logoutService(reqInfo.userName, token);
|
||||
|
||||
rspInfo.setStatus(err.getCode());
|
||||
rspInfo.setMessage(err.getMsg());
|
||||
|
||||
retMap.put(err, objectMapper.writeValueAsString(rspInfo));
|
||||
|
||||
return retMap;
|
||||
}
|
||||
|
||||
private EnumMap<ErrorCode, String> userLogin(ProtocolDTO mr)
|
||||
throws NoSuchAlgorithmException, JsonProcessingException {
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
UserLoginRsp rspInfo = UserLoginRsp.builder()
|
||||
.userName("")
|
||||
.token("")
|
||||
.status(err.getCode())
|
||||
.message(err.getMsg())
|
||||
.expireTime(0L)
|
||||
.logTime(System.currentTimeMillis()).build();
|
||||
|
||||
UserLoginReq reqInfo = objectMapper.readValue(mr.getMsgContent(), UserLoginReq.class);
|
||||
|
||||
rspInfo.setUserName(reqInfo.getUserName());
|
||||
|
||||
EnumMap<ErrorCode, String> logMap = loginService.loginService(reqInfo.getUserName(),
|
||||
reqInfo.getPassword());
|
||||
|
||||
if(logMap.isEmpty()) {
|
||||
err = ErrorCode.ERR_USERNOTFOUND;
|
||||
} else {
|
||||
err = logMap.keySet().iterator().next();
|
||||
rspInfo.setToken(logMap.get(err));
|
||||
}
|
||||
|
||||
rspInfo.setStatus(err.getCode());
|
||||
rspInfo.setMessage(err.getMsg());
|
||||
|
||||
retMap.put(err, objectMapper.writeValueAsString(rspInfo));
|
||||
|
||||
return retMap;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.ProtocolResp;
|
||||
import com.cmcc.hy.phoenix.service.DisposeDeviceManager;
|
||||
import com.cmcc.hy.phoenix.service.UserAccountCacheService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Builder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/debug")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台调试接口", tags = "抗DDoS处置平台调试接口")
|
||||
@Component
|
||||
public class DebugController {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private UserAccountCacheService userAccountService;
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDevMgr;
|
||||
|
||||
@GetMapping("/cacheuser")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取缓存用户")
|
||||
@ReqDec
|
||||
@Builder
|
||||
public ProtocolResp getCacheUsers(@RequestBody(required = true) ProtocolDTO mr) throws JsonProcessingException {
|
||||
|
||||
return ProtocolResp.result(ErrorCode.ERR_OK, -1, userAccountService.getCacheUser());
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/devs")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取所有处置设备")
|
||||
@ReqDec
|
||||
@Builder
|
||||
public ProtocolResp getDisposeDevs(@RequestBody(required = true) ProtocolDTO mr) throws JsonProcessingException {
|
||||
|
||||
return ProtocolResp.result(ErrorCode.ERR_OK,
|
||||
-1,
|
||||
objectMapper.writeValueAsString(disposeDevMgr.getAllDisposeDevs()));
|
||||
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.Save;
|
||||
import com.cmcc.hy.phoenix.pojo.Update;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.DemoDTO;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
@RestController
|
||||
public class DemoController {
|
||||
|
||||
/**
|
||||
* @Validated中group定义验证边界,Save说明只验证DemoDTO中的username和age
|
||||
* @see com.cmcc.hy.phoenix.controller.IDemoController#save(com.cmcc.hy.phoenix.pojo.dto.DemoDTO)
|
||||
*/
|
||||
@PostMapping("/demo")
|
||||
public DemoDTO save(@RequestBody @Validated({ Save.class }) DemoDTO demoDTO) {
|
||||
return demoDTO;
|
||||
}
|
||||
|
||||
@PutMapping("/demo")
|
||||
public DemoDTO update(@RequestBody @Validated({ Update.class }) DemoDTO demoDTO) {
|
||||
return demoDTO;
|
||||
}
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DisposeDeviceInfo;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.*;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DisposeCapacityInfo;
|
||||
import com.cmcc.hy.phoenix.service.DisposeDeviceManager;
|
||||
import com.cmcc.hy.phoenix.service.LoginService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
|
||||
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Builder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.cmcc.hy.phoenix.common.ErrorCode.ERR_OK;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/handle")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||
@Component
|
||||
public class DisposeInfoController {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private LoginService loginService;
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceManager deviceManager;
|
||||
|
||||
SimpleFilterProvider filterProvider = new SimpleFilterProvider();
|
||||
|
||||
@PostMapping("/information")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取节点信息")
|
||||
@ReqDec
|
||||
@Builder
|
||||
public ProtocolResp disposeInfo(@RequestBody(required = true) ProtocolDTO mr,
|
||||
@RequestHeader HttpHeaders headers){
|
||||
// 存放返回信息Json字符串
|
||||
String msgCtx = "";
|
||||
ErrorCode err = ERR_OK;
|
||||
|
||||
log.info("请求token: {}", headers.get("Authorization"));
|
||||
log.info("请求参数 {}", mr);
|
||||
|
||||
// 参数检测
|
||||
if (mr == null) {
|
||||
err = ErrorCode.ERR_PARAMS;
|
||||
return ProtocolResp.result(err, -1, msgCtx);
|
||||
} else if (mr.IsRequestTimeout()) {
|
||||
err = ErrorCode.ERR_REQTIMEOUT;
|
||||
} else {
|
||||
try{
|
||||
// 获取 Token
|
||||
String token = Objects
|
||||
.requireNonNull(headers.get("Authorization"))
|
||||
.get(0).replaceFirst("Bearer ", "");
|
||||
|
||||
// 判断Head头是否存在
|
||||
if (headers.get("Authorization") == null) {
|
||||
err = ErrorCode.ERR_MISSAUTHHEAD;
|
||||
} else if ((err = loginService.authTokenCheck(token)) == ERR_OK) {
|
||||
// Token 正确则处理业务
|
||||
switch (mr.getCmdId()) {
|
||||
case ConstValue.ProtocolCmdId.GET_DISPOSE_POINT_CATACITY:
|
||||
msgCtx = getDevCapInfo(mr);
|
||||
break;
|
||||
case ConstValue.ProtocolCmdId.GET_DISPOSE_POINT_LIST:
|
||||
msgCtx = getDisposeDevicesList();
|
||||
break;
|
||||
|
||||
case ConstValue.ProtocolCmdId.GET_DISPOSE_POINT_DETAILS:
|
||||
msgCtx = getDisposeDevicesDetails(mr);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||
}
|
||||
}
|
||||
} catch (JsonProcessingException ex) {
|
||||
log.error(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
err = ErrorCode.ERR_EXCEPTION;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
err = ErrorCode.ERR_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
if(err != ERR_OK) {
|
||||
msgCtx = err.getMsg();
|
||||
}
|
||||
|
||||
return ProtocolResp.result(err, mr.getCmdId(), msgCtx);
|
||||
}
|
||||
|
||||
private String getDisposeDevicesList() throws IOException {
|
||||
DisposeDevicesResp rspInfo = new DisposeDevicesResp(new ArrayList<>());
|
||||
|
||||
Map<String, DisposeDevice> devs = deviceManager.getAllDisposeDevs();
|
||||
|
||||
devs.forEach((k, v) -> {
|
||||
rspInfo.getItems().add(DisposeDeviceInfo.builder()
|
||||
.id(String.valueOf(v.getId()))
|
||||
.type(v.getType())
|
||||
.name(v.getName())
|
||||
.ip(v.getIpv4()).build());
|
||||
});
|
||||
|
||||
String[] filterItems = new String[] {"areaCode", "readme", "capacity"};
|
||||
filterProvider.addFilter("DeviceInfo", //添加过滤器名称
|
||||
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||
|
||||
objectMapper.setFilterProvider(filterProvider);
|
||||
|
||||
return objectMapper.writeValueAsString(rspInfo);
|
||||
}
|
||||
|
||||
private String getDisposeDevicesDetails(ProtocolDTO mr) throws JsonProcessingException {
|
||||
DisposeDevicesResp rspInfo = new DisposeDevicesResp(new ArrayList<>());
|
||||
|
||||
GetInfoById reqInfo = objectMapper.readValue(mr.getMsgContent(), GetInfoById.class);
|
||||
|
||||
Map<String, DisposeDevice> devs = deviceManager.getAllDisposeDevs();
|
||||
|
||||
devs.forEach((k, v) -> {
|
||||
if(Arrays.stream(reqInfo.getId()).anyMatch(str -> str.equals(String.valueOf(v.getId())))) {
|
||||
List<DeviceCapacityInfo> devCaps = new ArrayList<>();
|
||||
|
||||
v.getDevCaps().forEach(m -> {
|
||||
DeviceCapacityInfo devCapInfo = DeviceCapacityInfo.builder()
|
||||
.capacity(m.getCapacity())
|
||||
.tolFlowCapacity(m.getTolFlowCapacity())
|
||||
.build();
|
||||
if(m.getCapacity() == ConstValue.DisposeDeviceCapacity.CLEANUP.getCode()) {
|
||||
devCapInfo.setDisposeIp(v.getDisposeIp().toArray(new String[v.getDisposeIp().size()]));
|
||||
}
|
||||
devCaps.add(devCapInfo);
|
||||
});
|
||||
|
||||
rspInfo.getItems().add(DisposeDeviceInfo.builder()
|
||||
.id(String.valueOf(v.getId()))
|
||||
.type(v.getType())
|
||||
.name(v.getName())
|
||||
.ip(v.getIpv4())
|
||||
.areaCode(v.getAreaCode())
|
||||
.readme(v.getReadme())
|
||||
.capacity(devCaps)
|
||||
.build());
|
||||
}
|
||||
});
|
||||
|
||||
String[] filterItems = new String[] {};
|
||||
filterProvider.addFilter("DeviceInfo", //添加过滤器名称
|
||||
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||
filterProvider.addFilter("DeviceCapacityInfo", //添加过滤器名称
|
||||
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||
|
||||
objectMapper.setFilterProvider(filterProvider);
|
||||
|
||||
return objectMapper.writeValueAsString(rspInfo);
|
||||
}
|
||||
|
||||
private String getDevCapInfo(ProtocolDTO mr) throws JsonProcessingException {
|
||||
|
||||
DisposeCapacityResp rspInfo = new DisposeCapacityResp(new ArrayList<>());
|
||||
|
||||
GetInfoById reqInfo = objectMapper.readValue(mr.getMsgContent(), GetInfoById.class);
|
||||
|
||||
for (String v: reqInfo.getId()
|
||||
) {
|
||||
|
||||
List<DeviceCapacityInfo> capInfo = deviceManager.getDeviceCapacityInfoByDeviceId(Long.valueOf(v));
|
||||
|
||||
DisposeCapacityInfo ret = DisposeCapacityInfo.builder()
|
||||
.id(v)
|
||||
.capacity(capInfo).build();
|
||||
|
||||
rspInfo.getItems().add(ret);
|
||||
}
|
||||
|
||||
String[] filterItems = new String[] {"disposeIp"};
|
||||
filterProvider.addFilter("DeviceCapacityInfo", //添加过滤器名称
|
||||
SimpleBeanPropertyFilter.serializeAllExcept(filterItems));
|
||||
|
||||
objectMapper.setFilterProvider(filterProvider);
|
||||
|
||||
return objectMapper.writeValueAsString(rspInfo);
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCmdInfo;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.AddDispointPointReq;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.DevManagerResp;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.ProtocolResp;
|
||||
import com.cmcc.hy.phoenix.service.DisposeDeviceManager;
|
||||
import com.cmcc.hy.phoenix.service.LoginService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Builder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.cmcc.hy.phoenix.common.ErrorCode.ERR_OK;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/handle")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||
@Component
|
||||
public class DisposePointController {
|
||||
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private LoginService loginService;
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceManager disposeDeviceManager;
|
||||
|
||||
@PostMapping("/manager")
|
||||
@ResponseBody
|
||||
@ApiOperation("节点管理")
|
||||
@ReqDec
|
||||
@Builder
|
||||
public ProtocolResp disposePointManager(@RequestBody(required = true) ProtocolDTO mr,
|
||||
@RequestHeader HttpHeaders headers) {
|
||||
// 存放返回信息Json字符串
|
||||
String msgCtx = "";
|
||||
ErrorCode err = ERR_OK;
|
||||
|
||||
log.info("请求token: {}", headers.get("Authorization"));
|
||||
log.info("请求参数 {}", mr);
|
||||
|
||||
// 参数检测
|
||||
if (mr == null) {
|
||||
err = ErrorCode.ERR_PARAMS;
|
||||
return ProtocolResp.result(err, -1, msgCtx);
|
||||
} else if (mr.IsRequestTimeout()) {
|
||||
err = ErrorCode.ERR_REQTIMEOUT;
|
||||
} else {
|
||||
try {
|
||||
// 获取 Token
|
||||
String token = Objects.
|
||||
requireNonNull(headers.get("Authorization"))
|
||||
.get(0).replaceFirst("Bearer ", "");
|
||||
|
||||
// 判断Head头是否存在
|
||||
if (headers.get("Authorization") == null) {
|
||||
err = ErrorCode.ERR_MISSAUTHHEAD;
|
||||
} else if ((err = loginService.authTokenCheck(token)) == ERR_OK) {
|
||||
// Token 正确则处理业务
|
||||
switch (mr.getCmdId()) {
|
||||
case ConstValue.ProtocolCmdId.ADD_DISPOSE_POINT:
|
||||
msgCtx = addDisposePoint(mr);
|
||||
break;
|
||||
case ConstValue.ProtocolCmdId.DEL_DISPOSE_POINT:
|
||||
break;
|
||||
|
||||
default:
|
||||
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||
}
|
||||
}
|
||||
} catch (JsonProcessingException ex) {
|
||||
log.error(ex.getMessage());
|
||||
err = ErrorCode.ERR_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
return ProtocolResp.result(err, mr.getCmdId(), msgCtx);
|
||||
}
|
||||
|
||||
private String addDisposePoint(ProtocolDTO mr)
|
||||
throws JsonProcessingException {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
DevManagerResp rspInfo = new DevManagerResp();
|
||||
List<DeviceCmdInfo> devRsp = new ArrayList<>();
|
||||
rspInfo.setResult(devRsp);
|
||||
|
||||
|
||||
AddDispointPointReq reqInfo = objectMapper.readValue(mr.getMsgContent(), AddDispointPointReq.class);
|
||||
|
||||
reqInfo.getItems().forEach(v -> {
|
||||
//
|
||||
DisposeDevice dev = new DisposeDevice();
|
||||
|
||||
dev.setIpv4(v.getIp());
|
||||
dev.setType(v.getType());
|
||||
dev.setAreaCode(v.getAreaCode());
|
||||
dev.setName(v.getName());
|
||||
dev.setReadme(v.getReadme());
|
||||
dev.setManufacturer(v.getManufacturer());
|
||||
dev.setModel(v.getModel());
|
||||
dev.setVersion(v.getVersion());
|
||||
|
||||
dev.setDevCaps(new ArrayList<>());
|
||||
|
||||
v.getCapacity().forEach(k -> {
|
||||
DeviceCapacity devCap = new DeviceCapacity();
|
||||
devCap.setCapacity(k.getType());
|
||||
devCap.setTolFlowCapacity(k.getTolFlowCapacity());
|
||||
dev.getDevCaps().add(devCap);
|
||||
});
|
||||
|
||||
EnumMap<ErrorCode, Long> ret = disposeDeviceManager.addNewDisposeDevice(dev);
|
||||
|
||||
ErrorCode errno = ret.keySet().iterator().next();
|
||||
devRsp.add(new DeviceCmdInfo(v.getId(), String.valueOf(ret.get(errno)), errno.getCode(), errno.getMsg()));
|
||||
|
||||
});
|
||||
|
||||
return objectMapper.writeValueAsString(rspInfo);
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.help.GitInformation;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.Resp;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.GetVersion;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.ProtocolResp;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Builder;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 通信协议控制器定义
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/dispose")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台接口", tags = "抗DDoS处置平台接口")
|
||||
@Component
|
||||
@PropertySource("classpath:git.properties")
|
||||
public class ProtocolController {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private GitInformation gitInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/version")
|
||||
@ResponseBody
|
||||
@ApiOperation("获取版本信息")
|
||||
@ReqDec
|
||||
@Builder
|
||||
public ProtocolResp GetVersion(@RequestBody(required = true) ProtocolDTO mr) {
|
||||
String msgCtx;
|
||||
log.info("请求参数 {}", mr);
|
||||
|
||||
if(mr == null) {
|
||||
return ProtocolResp.result(ErrorCode.ERR_PARAMS);
|
||||
} else if (mr.IsRequestTimeout()) {
|
||||
return ProtocolResp.result(ErrorCode.ERR_REQTIMEOUT);
|
||||
}
|
||||
|
||||
try {
|
||||
GetVersion ver = GetVersion.builder().commit_id(gitInfo.getCommit_id())
|
||||
.commit_describe(gitInfo.getCommit_describe())
|
||||
.commit_time(gitInfo.getCommit_time())
|
||||
.tag_name(gitInfo.getTag_name())
|
||||
.tags(gitInfo.getTags())
|
||||
.build();
|
||||
msgCtx = objectMapper.writeValueAsString(ver);
|
||||
} catch (JsonProcessingException ex) {
|
||||
log.error(ex.getMessage());
|
||||
return ProtocolResp.result(Resp.SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
return ProtocolResp.result(ErrorCode.ERR_OK, mr.getCmdId(), msgCtx);
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.RespEnc;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.MyReqDTO;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.MyResp;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.Resp;
|
||||
import com.cmcc.hy.phoenix.service.AsyncService;
|
||||
import com.cmcc.hy.phoenix.service.UserService;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 对外服务定义
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月4日
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/test")
|
||||
@Slf4j
|
||||
@Api(value = "测试控制器", tags = "测试控制器接口说明")
|
||||
public class TestController {
|
||||
|
||||
@Resource
|
||||
private AsyncService asyncService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/post")
|
||||
@ResponseBody
|
||||
@ApiOperation("postTest测试实体参数请求接口")
|
||||
@ReqDec
|
||||
public MyResp postTest(@RequestBody(required = false) MyReqDTO mr) {
|
||||
log.info("请求参数 {}", mr);
|
||||
if(mr == null) {
|
||||
return MyResp.result(Resp.PARAM_ERROR);
|
||||
}
|
||||
return MyResp.result(Resp.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/ok/{id}")
|
||||
@ResponseBody
|
||||
@RespEnc
|
||||
public MyResp okTest(@PathVariable long id) {
|
||||
return MyResp.builder().data(userService.testService(id)).code(Resp.SUCCESS.getCode()).msg(Resp.SUCCESS.getMsg())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/mail")
|
||||
@ResponseBody
|
||||
public MyResp sendMail() {
|
||||
//asyncService.sendMail("这是邮件内容");
|
||||
log.info("记住我的线程名 {},和实际发送的线程名不一样", Thread.currentThread().getName());
|
||||
return MyResp.result(Resp.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/exception")
|
||||
public MyResp exception() {
|
||||
throw new RuntimeException("抛出异常");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,427 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.controller;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.bodyencdec.ReqDec;
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.dispose.DisposeProcess;
|
||||
import com.cmcc.hy.phoenix.dispose.DptechUMC;
|
||||
import com.cmcc.hy.phoenix.pojo.dto.ProtocolDTO;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.*;
|
||||
import com.cmcc.hy.phoenix.service.LoginService;
|
||||
import com.dptech.umc.NtcRequestResultInfo;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Builder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.cmcc.hy.phoenix.common.ErrorCode.ERR_OK;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/handle")
|
||||
@Slf4j
|
||||
@Api(value = "抗DDoS处置平台认证接口", tags = "抗DDoS处置平台认证接口")
|
||||
@Component
|
||||
public class taskController {
|
||||
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private LoginService loginService;
|
||||
|
||||
@PostMapping("/command")
|
||||
@ResponseBody
|
||||
@ApiOperation("处置任务接口")
|
||||
@ReqDec
|
||||
@Builder
|
||||
public ProtocolResp disposeTaskCommand(@RequestBody(required = true) ProtocolDTO mr,
|
||||
@RequestHeader HttpHeaders headers) throws JsonProcessingException {
|
||||
// 存放返回信息Json字符串
|
||||
String msgCtx = "";
|
||||
ErrorCode err = ERR_OK;
|
||||
|
||||
log.info("请求token: {}", headers.get("Authorization"));
|
||||
log.info("请求参数 {}", mr);
|
||||
|
||||
// 参数检测
|
||||
if (mr == null) {
|
||||
err = ErrorCode.ERR_PARAMS;
|
||||
return ProtocolResp.result(err, -1, msgCtx);
|
||||
} else if (mr.IsRequestTimeout()) {
|
||||
err = ErrorCode.ERR_REQTIMEOUT;
|
||||
} else {
|
||||
try {
|
||||
// 获取 Token
|
||||
String token = Objects.
|
||||
requireNonNull(headers.get("Authorization"))
|
||||
.get(0).replaceFirst("Bearer ", "");
|
||||
|
||||
// 判断Head头是否存在
|
||||
if (headers.get("Authorization") == null) {
|
||||
err = ErrorCode.ERR_MISSAUTHHEAD;
|
||||
} else if ((err = loginService.authTokenCheck(token)) == ERR_OK) {
|
||||
// Token 正确则处理业务
|
||||
switch (mr.getCmdId()) {
|
||||
case ConstValue.ProtocolCmdId.START_DISPOSE_CMD:
|
||||
EnumMap<ErrorCode, String> startMap = StartTaskByTaskId(mr);
|
||||
err = startMap.keySet().iterator().next();
|
||||
msgCtx = startMap.get(err);
|
||||
break;
|
||||
//停止清洗任务
|
||||
case ConstValue.ProtocolCmdId.STOP_DISPOSE_CMD_BY_TASKID:
|
||||
EnumMap<ErrorCode, String> stopMap = StopTaskByTaskId(mr);
|
||||
err = stopMap.keySet().iterator().next();
|
||||
msgCtx = stopMap.get(err);
|
||||
break;
|
||||
case ConstValue.ProtocolCmdId.STOP_DISPOSE_CMD_BY_IP:
|
||||
EnumMap<ErrorCode, String> stopMapByIp = StopTaskByIp(mr);
|
||||
err = stopMapByIp.keySet().iterator().next();
|
||||
msgCtx = stopMapByIp.get(err);
|
||||
break;
|
||||
case ConstValue.ProtocolCmdId.STOP_DISPOSE_CMD_BY_POINT:
|
||||
EnumMap<ErrorCode, String> stopMapByPoint = StopTaskByPoint(mr);
|
||||
err = stopMapByPoint.keySet().iterator().next();
|
||||
msgCtx = stopMapByPoint.get(err);
|
||||
break;
|
||||
case ConstValue.ProtocolCmdId.STOP_DISPOSE_CMD_ALL:
|
||||
EnumMap<ErrorCode, String> stopMapByAll = StopTaskAll(mr);
|
||||
err = stopMapByAll.keySet().iterator().next();
|
||||
msgCtx = stopMapByAll.get(err);
|
||||
break;
|
||||
default:
|
||||
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||
}
|
||||
}
|
||||
} catch (JsonProcessingException ex) {
|
||||
log.error(ex.getMessage());
|
||||
err = ErrorCode.ERR_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
return ProtocolResp.result(err, mr.getCmdId(), msgCtx);
|
||||
}
|
||||
|
||||
private EnumMap<ErrorCode, String> StopTaskByTaskId(ProtocolDTO mr) throws JsonProcessingException {
|
||||
String ipAddr = "10.88.77.15";
|
||||
DisposeProcess dp = new DptechUMC(ipAddr);
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
List<StopTaskResult> results = new ArrayList<>();
|
||||
StopTaskRsp repInfo = StopTaskRsp.builder().result(results).build();
|
||||
|
||||
StopTaskReq reqInfo = objectMapper.readValue(mr.getMsgContent(), StopTaskReq.class);
|
||||
//遍历处置任务唯一编号taskId
|
||||
if (reqInfo.getTaskId().size() == 0) {
|
||||
System.out.println("无指定TaskId的清洗任务");
|
||||
err = ErrorCode.ERR_INPUTMISS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
for (String v : reqInfo.getTaskId()) {
|
||||
System.out.println(v);
|
||||
//每个taskId对应保护IP disposeIp,通过taskId获取disposeIp
|
||||
String disposeIp = "192.168.5.2";
|
||||
int attackType = 1;
|
||||
int direction = 0;
|
||||
|
||||
NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(disposeIp, attackType, direction);
|
||||
|
||||
StopTaskResult sig_results = new StopTaskResult();
|
||||
sig_results.setTaskId(v);
|
||||
sig_results.setType(0); //目前只有清洗设备
|
||||
sig_results.setDisposeIp(disposeIp);
|
||||
if (ntc_result.getResultRetVal().equals(0)) {
|
||||
sig_results.setStatus(ntc_result.getResultRetVal());
|
||||
}
|
||||
|
||||
//把每一次遍历的结果都存入results
|
||||
results.add(sig_results);
|
||||
repInfo.setResult(results);
|
||||
}
|
||||
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
private EnumMap<ErrorCode, String> StopTaskByIp(ProtocolDTO mr) throws JsonProcessingException {
|
||||
String ipAddr = "10.88.77.15";
|
||||
DisposeProcess dp = new DptechUMC(ipAddr);
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
List<StopTaskResult> results = new ArrayList<>();
|
||||
StopTaskRsp repInfo = StopTaskRsp.builder().result(results).build();
|
||||
|
||||
StopTaskByIpReq reqInfo = objectMapper.readValue(mr.getMsgContent(), StopTaskByIpReq.class);
|
||||
if (reqInfo.getItems().size() == 0) {
|
||||
System.out.println("无该处置IP的清洗任务");
|
||||
err = ErrorCode.ERR_INPUTMISS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
} else {
|
||||
for (StopTaskByIpReqMsg v : reqInfo.getItems()
|
||||
) {
|
||||
if ((v.getType() < -1) || (v.getType() > 3)) {
|
||||
System.out.println("任务类型输入错误");
|
||||
err = ErrorCode.ERR_PARAMS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
} else if ((v.getId().length() == 0) || (String.valueOf(v.getType()).length() == 0) || (v.getDisposeIP().length() == 0)) {
|
||||
System.out.println("缺少必要输入信息");
|
||||
err = ErrorCode.ERR_INPUTMISS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (StopTaskByIpReqMsg v : reqInfo.getItems()
|
||||
) {
|
||||
//输出指定IP
|
||||
System.out.println(v.getDisposeIP());
|
||||
int attackType = 1;
|
||||
int direction = 0;
|
||||
|
||||
NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(v.getDisposeIP(), attackType, direction);
|
||||
|
||||
StopTaskResult result = new StopTaskResult();
|
||||
result.setId(v.getId());
|
||||
result.setType(v.getType());
|
||||
result.setDisposeIp(v.getDisposeIP());
|
||||
if (ntc_result.getResultRetVal().equals(0)) {
|
||||
result.setStatus(ntc_result.getResultRetVal());
|
||||
}
|
||||
|
||||
//数据库中对应设备Id(deviceId)找到taskId,测试情况假设deviceId与找到taskId相同
|
||||
String taskId = v.getId();
|
||||
result.setTaskId(taskId);
|
||||
|
||||
//把每一次遍历的结果都存入results
|
||||
results.add(result);
|
||||
repInfo.setResult(results);
|
||||
}
|
||||
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
private EnumMap<ErrorCode, String> StopTaskByPoint(ProtocolDTO mr) throws JsonProcessingException {
|
||||
String ipAddr = "10.88.77.15";
|
||||
DisposeProcess dp = new DptechUMC(ipAddr);
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
List<StopTaskResult> results = new ArrayList<>();
|
||||
StopTaskRsp repInfo = StopTaskRsp.builder().result(results).build();
|
||||
|
||||
StopTaskByPonitReq reqInfo = objectMapper.readValue(mr.getMsgContent(), StopTaskByPonitReq.class);
|
||||
|
||||
if (reqInfo.getItems().size() == 0) {
|
||||
System.out.println("无该指定能力节点的清洗任务");
|
||||
err = ErrorCode.ERR_INPUTMISS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
} else {
|
||||
for (StopTaskByPonitReqMsg v : reqInfo.getItems()
|
||||
) {
|
||||
if ((v.getType() < -1) || (v.getType() > 3)) {
|
||||
System.out.println("任务类型输入错误");
|
||||
err = ErrorCode.ERR_PARAMS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
} else if ((v.getId().length() == 0) || (String.valueOf(v.getType()).length() == 0)) {
|
||||
System.out.println("缺少必要输入信息");
|
||||
err = ErrorCode.ERR_INPUTMISS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (StopTaskByPonitReqMsg v : reqInfo.getItems()
|
||||
) {
|
||||
//通过能力节点唯一标识符id找到对应的清洗IP,清洗IP以列表形式保存,一能力节点会对应多个IP
|
||||
//foreach嵌套-List<String> getDisposeIP
|
||||
List<String> getDisposeIps = new ArrayList<>();
|
||||
getDisposeIps.add("192.168.1.1");
|
||||
getDisposeIps.add("192.168.2.1");
|
||||
int attackType = 1;
|
||||
int direction = 0;
|
||||
int taskid = 0;
|
||||
|
||||
for (String getDisposeIp : getDisposeIps
|
||||
) {
|
||||
NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(getDisposeIp, attackType, direction);
|
||||
StopTaskResult result = new StopTaskResult();
|
||||
result.setId(v.getId());
|
||||
result.setType(v.getType());
|
||||
result.setDisposeIp(getDisposeIp);
|
||||
if (ntc_result.getResultRetVal().equals(0)) {
|
||||
result.setStatus(ntc_result.getResultRetVal());
|
||||
}
|
||||
|
||||
//数据库中对应设备Id(deviceId)找到taskId
|
||||
//test taskId自增1
|
||||
String taskId = String.valueOf(taskid);
|
||||
result.setTaskId(taskId);
|
||||
|
||||
//把每一次遍历的结果都存入results
|
||||
results.add(result);
|
||||
repInfo.setResult(results);
|
||||
taskid++;
|
||||
}
|
||||
}
|
||||
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
private EnumMap<ErrorCode, String> StopTaskAll(ProtocolDTO mr) throws JsonProcessingException {
|
||||
String ipAddr = "10.88.77.15";
|
||||
DisposeProcess dp = new DptechUMC(ipAddr);
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
List<StopTaskResult> results = new ArrayList<>();
|
||||
StopTaskRsp repInfo = StopTaskRsp.builder().result(results).build();
|
||||
|
||||
StopTaskAllReq reqInfo = objectMapper.readValue(mr.getMsgContent(), StopTaskAllReq.class);
|
||||
|
||||
if (String.valueOf(reqInfo.getType()).length() == 0) {
|
||||
System.out.println("缺少必要输入参数");
|
||||
err = ErrorCode.ERR_INPUTMISS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
} else if ((reqInfo.getType() < -1) || (reqInfo.getType() > 3)) {
|
||||
System.out.println("任务类型输入错误");
|
||||
err = ErrorCode.ERR_PARAMS;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
int type = reqInfo.getType();
|
||||
if (type == 0) {
|
||||
//任务类型为清洗,清洗所有清洗任务
|
||||
//MySql获取所有taskId,遍历执行清洗任务,测试添加多个taskId
|
||||
List<String> taskIds = new ArrayList<>();
|
||||
taskIds.add("1");
|
||||
taskIds.add("2");
|
||||
taskIds.add("3");
|
||||
taskIds.add("4");
|
||||
|
||||
String disposeIp = "";
|
||||
|
||||
for (String v : taskIds
|
||||
) {
|
||||
//每个taskId对应disposeIp,通过taskId获取disposeIp
|
||||
//test 不同的taskId对应不同disposeIp
|
||||
if (v.equals("1")) {
|
||||
disposeIp = "192.168.10.1";
|
||||
} else if (v.equals("2")) {
|
||||
disposeIp = "192.168.10.2";
|
||||
} else if (v.equals("3")) {
|
||||
disposeIp = "192.168.10.3";
|
||||
} else {
|
||||
disposeIp = "192.168.10.4";
|
||||
}
|
||||
|
||||
int attackType = 1;
|
||||
int direction = 0;
|
||||
|
||||
NtcRequestResultInfo ntc_result = dp.stopAbnormalTask(disposeIp, attackType, direction);
|
||||
|
||||
StopTaskResult result = new StopTaskResult();
|
||||
result.setTaskId(v);
|
||||
result.setType(0); //目前只有清洗设备
|
||||
result.setDisposeIp(disposeIp);
|
||||
if (ntc_result.getResultRetVal().equals(0)) {
|
||||
result.setStatus(ntc_result.getResultRetVal());
|
||||
}
|
||||
|
||||
//数据库中对应设备taskId(deviceId)找到Id,测试情况假设deviceId与找到taskId相同
|
||||
result.setId(v);
|
||||
|
||||
//把每一次遍历的结果都存入results
|
||||
results.add(result);
|
||||
repInfo.setResult(results);
|
||||
}
|
||||
}
|
||||
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
|
||||
private EnumMap<ErrorCode, String> StartTaskByTaskId(ProtocolDTO mr) throws JsonProcessingException {
|
||||
String ipAddr = "10.88.77.15";
|
||||
DisposeProcess dp = new DptechUMC(ipAddr);
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
int status_result = 0;
|
||||
|
||||
StartTaskRep repInfo = StartTaskRep.builder()
|
||||
.id("")
|
||||
.taskId("")
|
||||
.expireTime(0L)
|
||||
.status(err.getCode()).build();
|
||||
|
||||
StartTaskReq reqInfo = objectMapper.readValue(mr.getMsgContent(), StartTaskReq.class);
|
||||
|
||||
List<Integer> attackTypes = reqInfo.getAttackType();
|
||||
int direction = reqInfo.getFlowDirection();
|
||||
String disposeIp = reqInfo.getDisposeIp();
|
||||
|
||||
for (Integer attackType : attackTypes
|
||||
) {
|
||||
NtcRequestResultInfo ntc_result = dp.startAbnormalTask(disposeIp, attackType, direction);
|
||||
int ret_err = -1;
|
||||
if (ntc_result.getResultRetVal().equals(ret_err)) {
|
||||
System.out.println("启动清洗任务失败");
|
||||
err = ErrorCode.ERR_UNKNOWNCMD;
|
||||
repInfo = null;
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
status_result = ntc_result.getResultRetVal();
|
||||
}
|
||||
|
||||
repInfo.setId(reqInfo.getId());
|
||||
//MySql 根据设备Id查找对应的taskId
|
||||
//test 假设设备id与taskId相同
|
||||
repInfo.setTaskId(reqInfo.getId());
|
||||
repInfo.setExpireTime(System.currentTimeMillis()+reqInfo.getDisposeTime());
|
||||
repInfo.setStatus(status_result);
|
||||
|
||||
//启动清洗任务成功,task数据到MySql
|
||||
|
||||
retMap.put(err, objectMapper.writeValueAsString(repInfo));
|
||||
return retMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.dispose;
|
||||
|
||||
import com.dptech.umc.NtcRequestResultInfo;
|
||||
|
||||
public interface DisposeProcess {
|
||||
public int runDispose(String ip);
|
||||
|
||||
public <T> T getAllDetectionObject();
|
||||
|
||||
public <T> T getAllProtectionObject();
|
||||
|
||||
public String getDetectionDevices();
|
||||
|
||||
public String getProtectDevices();
|
||||
|
||||
public NtcRequestResultInfo stopAbnormalTask(String abnormalIp, int attackType, int direction);
|
||||
|
||||
public NtcRequestResultInfo startAbnormalTask(String abnormalIp, int attackType, int direction);
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.exception;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.MissingPathVariableException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.vo.MyResp;
|
||||
import com.cmcc.hy.phoenix.pojo.vo.Resp;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月5日
|
||||
*/
|
||||
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Throwable.class)
|
||||
@ResponseBody
|
||||
public MyResp handleException(HttpServletRequest request, Throwable e) {
|
||||
log.error("进入全局异常处理", e);
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("url", request.getRequestURL().toString());
|
||||
map.put("exception", ExceptionUtils.getMessage(e));
|
||||
return MyResp.builder().code(Resp.ERROR.getCode()).msg(Resp.ERROR.getMsg()).data(map).build();
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public MyResp paramException(HttpServletRequest request, Exception e) {
|
||||
log.error("进入参数校验异常处理", e);
|
||||
StringBuffer errorMsg = new StringBuffer();
|
||||
if (e instanceof ConstraintViolationException) {
|
||||
Set<ConstraintViolation<?>> cves = ((ConstraintViolationException) e).getConstraintViolations();
|
||||
cves.forEach(ex -> errorMsg.append(ex.getMessage()));
|
||||
} else if (e instanceof MissingPathVariableException) {
|
||||
errorMsg.append("请检查参数 " + ((MissingPathVariableException) e).getVariableName());
|
||||
} else if (e instanceof MethodArgumentNotValidException) {
|
||||
errorMsg.append(
|
||||
((MethodArgumentNotValidException) e).getBindingResult().getAllErrors().get(0).getDefaultMessage());
|
||||
} else {
|
||||
log.error("请求异常", e);
|
||||
errorMsg.append("参数异常");
|
||||
}
|
||||
return MyResp.builder().code(Resp.PARAM_ERROR.getCode()).msg(errorMsg.toString()).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.manager;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.entity.InfoCollection;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.User;
|
||||
|
||||
/**
|
||||
* 系统在15张数据表规模以下的,建议整个工程就一个manager 项目主程负责编写这个接口,掌握整个系统的数据逻辑操作
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
public interface GlobalManager {
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: 整个工程会有多个service需要这个方法
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public User findUserById(long id);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param phone
|
||||
* @param productType
|
||||
* @return
|
||||
*/
|
||||
public int deleteIcByPhoneAndPt(String phone, String productType);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @return
|
||||
*/
|
||||
public int deleteAllIc();
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param ic
|
||||
* @return
|
||||
*/
|
||||
public int saveInfoCollection(InfoCollection ic);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param phone
|
||||
* @param productType
|
||||
* @return
|
||||
*/
|
||||
public InfoCollection findIcByPhoneAndProductType(String phone, String productType);
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public InfoCollection findIcById(long id);
|
||||
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.manager.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cmcc.hy.phoenix.aop.cache.CacheDel;
|
||||
import com.cmcc.hy.phoenix.aop.cache.CacheGet;
|
||||
import com.cmcc.hy.phoenix.aop.cache.CachePut;
|
||||
import com.cmcc.hy.phoenix.aop.cache.MyCache;
|
||||
import com.cmcc.hy.phoenix.manager.GlobalManager;
|
||||
import com.cmcc.hy.phoenix.mapper.InfoCollectionMapper;
|
||||
import com.cmcc.hy.phoenix.mapper.UserMapper;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.InfoCollection;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.User;
|
||||
import com.cmcc.hy.phoenix.redis.RedisClient;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
import tk.mybatis.mapper.entity.Example.Criteria;
|
||||
|
||||
/**
|
||||
* 此类依赖所有DAO以及redisClient 数据缓存也在这里,外部系统调用也在这里
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class GlobalManagerImpl implements GlobalManager {
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Resource
|
||||
private InfoCollectionMapper infoCollectionMapper;
|
||||
|
||||
@Resource
|
||||
private RedisClient redisClient;
|
||||
|
||||
@Override
|
||||
public User findUserById(long id) {
|
||||
// TODO Auto-generated method stub
|
||||
// 封装DAO
|
||||
User user = userMapper.selectByPrimaryKey(id);
|
||||
log.info("manager层出查询出用户信息 {}", user);
|
||||
redisClient.put("test", "mocktest", 100);
|
||||
return user;
|
||||
}
|
||||
|
||||
@CacheDel(clazz = InfoCollection.class, key = { "#phone", "#productType" })
|
||||
@Override
|
||||
public int deleteIcByPhoneAndPt(String phone, String productType) {
|
||||
// TODO Auto-generated method stub
|
||||
Example example = new Example(InfoCollection.class);
|
||||
Criteria c = example.createCriteria();
|
||||
c.andEqualTo("phoneNumber", phone);
|
||||
c.andEqualTo("productType", productType);
|
||||
return infoCollectionMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteAllIc() {
|
||||
// TODO Auto-generated method stub
|
||||
List<InfoCollection> list = infoCollectionMapper.selectAll();
|
||||
list.forEach((ic)->infoCollectionMapper.delete(ic));
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 这里key的设置需要查看该对象的查询方法的key设置,保持key全覆盖
|
||||
*
|
||||
* @see com.cmcc.hy.phoenix.manager.GlobalManager#saveInfoCollection(com.cmcc.hy.phoenix.pojo.entity.InfoCollection)
|
||||
*/
|
||||
@MyCache(put = { @CachePut(key = "#ic.id"), @CachePut(key = { "#ic.phoneNumber", "#ic.productType" }) })
|
||||
@Override
|
||||
public int saveInfoCollection(InfoCollection ic) {
|
||||
// TODO Auto-generated method stub
|
||||
return infoCollectionMapper.insert(ic);
|
||||
}
|
||||
|
||||
@CacheGet(key = {"#phone","#productType"})
|
||||
@Override
|
||||
public InfoCollection findIcByPhoneAndProductType(String phone, String productType) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("根据手机号,产品类型查询用户信息");
|
||||
Example example = new Example(InfoCollection.class);
|
||||
Criteria c = example.createCriteria();
|
||||
c.andEqualTo("phoneNumber", phone);
|
||||
c.andEqualTo("productType", productType);
|
||||
List<InfoCollection> list = infoCollectionMapper.selectByExample(example);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@CacheGet(key = "#id")
|
||||
@Override
|
||||
public InfoCollection findIcById(long id) {
|
||||
log.info("根据ID查询用户信息");
|
||||
return infoCollectionMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.mapper;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DeviceCapacityMapper extends Mapper<DisposeDevice> {
|
||||
List<DeviceCapacity> getDeviceCapacityByDeviceId(Long id);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.mapper;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The interface Dispose device mapper.
|
||||
*/
|
||||
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>,
|
||||
IdsMapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
|
||||
|
||||
/**
|
||||
* 获取所有处置设备
|
||||
*
|
||||
* @return the all
|
||||
*/
|
||||
List<DisposeDevice> getAllDisposeDevice();
|
||||
|
||||
DisposeDevice getDisposeDisposeDevByIp(String ipv4);
|
||||
List<DeviceCapacityInfo> getDisposeDisposeDevById(Long devId);
|
||||
|
||||
void addNewDisposeDevice(DisposeDevice dev);
|
||||
|
||||
void updateDisposeDeviceByIp(String ipv4);
|
||||
|
||||
void removeDisposeDevice(String ipAddr);
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.mapper;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.InfoCollection;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeTask;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DisposeTaskMapper extends Mapper<DisposeTask>,
|
||||
MySqlMapper<DisposeTask> {
|
||||
|
||||
/**
|
||||
* 获取所有处置任务
|
||||
*
|
||||
* @return the all
|
||||
*/
|
||||
List<DisposeTask> getAllDisposeTask();
|
||||
|
||||
/**
|
||||
* 获取所有处置任务唯一编号
|
||||
*/
|
||||
List<Long> getAllTaskId();
|
||||
|
||||
/**
|
||||
* 通过处置任务唯一编号获取设备唯一标识符
|
||||
*/
|
||||
Long getDeviceIdByTaskId();
|
||||
|
||||
/**
|
||||
* 通过设备唯一标识符获取处置任务唯一编号
|
||||
*/
|
||||
Long getTaskIdByDeviceId();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.mapper;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.entity.InfoCollection;
|
||||
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
public interface InfoCollectionMapper extends Mapper<InfoCollection>, MySqlMapper<InfoCollection> {
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.mapper;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.entity.UserAccount;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public interface UserAccountMapper extends Mapper<UserAccount>,
|
||||
IdsMapper<UserAccount>, MySqlMapper<UserAccount> {
|
||||
|
||||
UserAccount getUserByName(String username);
|
||||
|
||||
void lockUserAccount(@Param("username")String username);
|
||||
void unlockUserAccount(@Param("username")String username);
|
||||
void refreshLoginTime(@Param("username")String username);
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.mapper;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.entity.User;
|
||||
|
||||
import tk.mybatis.mapper.common.IdsMapper;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
import tk.mybatis.mapper.common.MySqlMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* User Mapper
|
||||
* </p>
|
||||
*
|
||||
* @description: User Mapper
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
public interface UserMapper extends Mapper<User>,IdsMapper<User>,MySqlMapper<User> {
|
||||
|
||||
/**
|
||||
* 根据用户名统计(假设它是一个很复杂的SQL)
|
||||
*
|
||||
* @param name 用户名
|
||||
* @return 统计结果
|
||||
*/
|
||||
int countByName(String name);
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
public interface Save {
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
public interface Update {
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.dto;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.UserId;
|
||||
import com.cmcc.hy.phoenix.pojo.Save;
|
||||
import com.cmcc.hy.phoenix.pojo.Update;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DemoDTO {
|
||||
|
||||
@UserId(groups = { Update.class })
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "username 不能为空", groups = { Save.class, Update.class })
|
||||
private String username;
|
||||
|
||||
@Min(value = 0, message = "age 在必须 0 - 150 之间", groups = { Save.class, Update.class })
|
||||
@Max(value = 150, message = "age 在必须 0 - 150 之间", groups = { Save.class, Update.class })
|
||||
private Integer age;
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 请求参数实体
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月4日
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
@ApiModel("MyReq请求参数实体")
|
||||
public class MyReqDTO {
|
||||
|
||||
@ApiModelProperty("MyReq的id参数")
|
||||
private Long id;
|
||||
@ApiModelProperty("MyReq的type参数")
|
||||
private Integer type;
|
||||
@ApiModelProperty("MyReq的msg参数")
|
||||
private String msg;
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.dto;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 通信协议定义
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@ApiModel("通信协议实体")
|
||||
@NoArgsConstructor
|
||||
public class ProtocolDTO {
|
||||
@ApiModelProperty(value="命令编号(必要字段): \n" +
|
||||
"0-9999范围为请求命令\n" +
|
||||
"10000-19999 范围为对应请求的响应命令\n" +
|
||||
"响应命令值为10000+请求命令值\n", required = true,
|
||||
allowableValues = "rang[0, 19999]",
|
||||
example = "1")
|
||||
private int cmdId;
|
||||
|
||||
@ApiModelProperty(value="协议版本号", required = true, example = "1")
|
||||
private int ver;
|
||||
|
||||
@ApiModelProperty(value="msgContent字段内容编码格式:\n" +
|
||||
"0:无编码格式,普通字符串\n" +
|
||||
"1:base64编码格式\n" +
|
||||
"2:采用AES加密后的base64编码格式\n", required = true,
|
||||
allowableValues = "0, 1, 2",
|
||||
example = "0")
|
||||
private int cryptoType;
|
||||
|
||||
@ApiModelProperty(value="当前UTC时间戳", required = true, example = "1526625689000")
|
||||
private Long timeStamp;
|
||||
|
||||
@ApiModelProperty(value="协议详细内容,Json字符串格式。\n" +
|
||||
"保存该cmdId命令相关的详细内容,\n" +
|
||||
"具体每个cmdId命令的详细内容参看对应的命令协议定义", required = false,
|
||||
example = "{}")
|
||||
private String msgContent;
|
||||
|
||||
@ApiModelProperty(value="服务器返回状态码", required = false,
|
||||
example = "200")
|
||||
private int code;
|
||||
|
||||
public Boolean IsRequestTimeout() {
|
||||
Long current = System.currentTimeMillis();
|
||||
Long timeDiff = current - this.timeStamp;
|
||||
|
||||
if (timeDiff > 0 && timeDiff <= 3000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.entity;
|
||||
|
||||
import lombok.*;
|
||||
import tk.mybatis.mapper.annotation.KeySql;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type Device capacity.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Table(name = "dispose_device")
|
||||
public class DeviceCapacity implements Serializable {
|
||||
|
||||
/**
|
||||
* The constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备能力唯一标识符
|
||||
*/
|
||||
@Id
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备唯一标识符
|
||||
*/
|
||||
private Integer deviceId;
|
||||
|
||||
/**
|
||||
* 0:清洗 1:高防 2:黑洞
|
||||
*/
|
||||
private Integer capacity;
|
||||
|
||||
/**
|
||||
* 处置设备储备能力(MB)
|
||||
*/
|
||||
private Integer tolFlowCapacity;
|
||||
|
||||
public DeviceCapacity(Integer capacity, Integer tolFlowCapacity) {
|
||||
this.capacity = capacity;
|
||||
this.tolFlowCapacity = tolFlowCapacity;
|
||||
}
|
||||
|
||||
public DeviceCapacity(Integer capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.entity;
|
||||
|
||||
import lombok.*;
|
||||
import tk.mybatis.mapper.annotation.KeySql;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Dispose device.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Table(name = "dispose_device")
|
||||
@NameStyle(Style.normal)
|
||||
public class DisposeDevice implements Serializable {
|
||||
|
||||
/**
|
||||
* The constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 设备唯一标识符
|
||||
*/
|
||||
@Id
|
||||
//@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备IPv4地址
|
||||
*/
|
||||
private String ipv4;
|
||||
|
||||
/**
|
||||
* 设备IPv6地址
|
||||
*/
|
||||
private String ipv6;
|
||||
|
||||
/**
|
||||
* 能力节点类型,0:平台,1:设备
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* The Area code.
|
||||
*/
|
||||
private Integer areaCode;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 生产厂商
|
||||
*/
|
||||
private String manufacturer;
|
||||
|
||||
/**
|
||||
* 型号
|
||||
*/
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* 软件版本
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String readme;
|
||||
|
||||
|
||||
/**
|
||||
* 能力设备支持的能力列表
|
||||
*/
|
||||
@Transient
|
||||
private List<DeviceCapacity> devCaps;
|
||||
|
||||
/**
|
||||
* 处置设备支持的处置IP,从处置设备获取
|
||||
*/
|
||||
@Transient
|
||||
private List<String> disposeIp;
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.entity;
|
||||
|
||||
import lombok.*;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* The type Dispose task.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Table(name = "dispose_task")
|
||||
@NameStyle(Style.normal)
|
||||
public class DisposeTask implements Serializable {
|
||||
/**
|
||||
* 处置任务唯一编号
|
||||
*/
|
||||
@Id
|
||||
//@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备唯一标识符
|
||||
*/
|
||||
private Integer deviceId;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long accountId;
|
||||
|
||||
/**
|
||||
* 设备能力唯一标识符
|
||||
*/
|
||||
private Long capacityId;
|
||||
|
||||
/**
|
||||
* 处置IP地址,A.B.C.D格式
|
||||
*/
|
||||
private String disposeIp;
|
||||
|
||||
/**
|
||||
* 任务开始时间.
|
||||
*/
|
||||
private String beginTime;
|
||||
|
||||
/**
|
||||
* 任务计划结束时间
|
||||
*/
|
||||
private String planEndTime;
|
||||
|
||||
/**
|
||||
* 任务结束时间
|
||||
*/
|
||||
private String endTime;
|
||||
|
||||
/**
|
||||
* 任务状态 0:成功;其它:失败原因
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import tk.mybatis.mapper.annotation.KeySql;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
@Table(name = "info_collection")
|
||||
public class InfoCollection implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
private String username;
|
||||
private String organization;
|
||||
private String provinceCode;
|
||||
private String province;
|
||||
private String city;
|
||||
private String district;
|
||||
private String address;
|
||||
private String email;
|
||||
|
||||
private String phoneNumber;
|
||||
private String comment;
|
||||
private String productType;
|
||||
private Integer syncStatus;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import tk.mybatis.mapper.annotation.KeySql;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户实体类
|
||||
* </p>
|
||||
*
|
||||
* @description: 用户实体类
|
||||
* @author phoenix
|
||||
* @date 2020年2月8日
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Table(name = "phoenix_user")
|
||||
public class User implements Serializable {
|
||||
private static final long serialVersionUID = -1840831686851699943L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 加密后的密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 加密使用的盐
|
||||
*/
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String phoneNumber;
|
||||
|
||||
/**
|
||||
* 状态,-1:逻辑删除,0:禁用,1:启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 上次登录时间
|
||||
*/
|
||||
private Date lastLoginTime;
|
||||
|
||||
/**
|
||||
* 上次更新时间
|
||||
*/
|
||||
private Date lastUpdateTime;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.entity;
|
||||
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.*;
|
||||
import tk.mybatis.mapper.annotation.KeySql;
|
||||
import tk.mybatis.mapper.annotation.NameStyle;
|
||||
import tk.mybatis.mapper.code.Style;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The type User account.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Table(name = "user_account")
|
||||
@NameStyle(Style.normal)
|
||||
public class UserAccount implements Serializable {
|
||||
|
||||
/**
|
||||
* The constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 账户唯一编号
|
||||
*/
|
||||
@Id
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码, SHA256
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 最后一次成功登录时间
|
||||
*/
|
||||
private String lastLoginTime;
|
||||
|
||||
|
||||
/**
|
||||
* 账户锁定时间
|
||||
*/
|
||||
private String lockTime;
|
||||
|
||||
/**
|
||||
* 账户状态
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.po;
|
||||
|
||||
import lombok.*;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class DeciveCaps {
|
||||
private int type;
|
||||
@Nullable
|
||||
private int tolFlowCapacity;
|
||||
@Nullable
|
||||
private String disposeIp;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.po;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@JsonFilter("DeviceCapacityInfo")
|
||||
public class DeviceCapacityInfo {
|
||||
private int capacity;
|
||||
@Nullable
|
||||
private int tolFlowCapacity;
|
||||
private int usedCapacity;
|
||||
private String[] disposeIp;
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.po;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DeviceCmdInfo {
|
||||
private String id;
|
||||
private String devId;
|
||||
private int status;
|
||||
private String message;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.po;
|
||||
|
||||
import lombok.*;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DisposeAddInfo {
|
||||
private String id;
|
||||
private int type;
|
||||
private String name;
|
||||
private String ip;
|
||||
private int areaCode;
|
||||
@Nullable
|
||||
private String manufacturer;
|
||||
@Nullable
|
||||
private String model;
|
||||
@Nullable
|
||||
private String version;
|
||||
@Nullable
|
||||
private String readme;
|
||||
private List<DeciveCaps> capacity;
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.po;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DisposeCapacityInfo {
|
||||
private String id;
|
||||
private List<DeviceCapacityInfo> capacity;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.po;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@JsonFilter("DeviceInfo")
|
||||
public class DisposeDeviceInfo {
|
||||
private String id;
|
||||
private int type;
|
||||
private String name;
|
||||
private String ip;
|
||||
private int areaCode;
|
||||
@Nullable
|
||||
private String readme;
|
||||
private List<DeviceCapacityInfo> capacity;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.po;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserAccountCache {
|
||||
private String username;
|
||||
private String token;
|
||||
private Long lastAccess;
|
||||
private Integer pwdErrTimes;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.po.DisposeAddInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AddDispointPointReq {
|
||||
private List<DisposeAddInfo> items;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCmdInfo;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DevManagerResp {
|
||||
private List<DeviceCmdInfo> result;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.po.DisposeCapacityInfo;
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
import lombok.Builder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class DisposeCapacityResp {
|
||||
private List<DisposeCapacityInfo> items;
|
||||
|
||||
public DisposeCapacityResp(List<DisposeCapacityInfo> ret) {
|
||||
this.items = ret;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import com.cmcc.hy.phoenix.pojo.po.DisposeDeviceInfo;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class DisposeDevicesResp {
|
||||
List<DisposeDeviceInfo> items;
|
||||
|
||||
public DisposeDevicesResp(List<DisposeDeviceInfo> devInfos){
|
||||
this.items = devInfos;
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class GetInfoById {
|
||||
private String[] id;
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.Builder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class GetVersion {
|
||||
private String commit_id;
|
||||
private String commit_describe;
|
||||
private String commit_time;
|
||||
private String tag_name;
|
||||
private String tags;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 前后端交互统一数据格式
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月4日
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class MyResp {
|
||||
|
||||
private int code;
|
||||
private Object data;
|
||||
private String msg;
|
||||
|
||||
public static MyResp result(Resp resp) {
|
||||
return MyResp.builder().code(resp.getCode()).msg(resp.getMsg()).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 服务器响应请求通信协议
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class ProtocolResp {
|
||||
@ApiModelProperty(value="命令编号(必要字段): \n" +
|
||||
"0-9999范围为请求命令\n" +
|
||||
"10000-19999 范围为对应请求的响应命令\n" +
|
||||
"响应命令值为10000+请求命令值\n", required = true,
|
||||
allowableValues = "rang[0, 19999]",
|
||||
example = "1")
|
||||
private int cmdId;
|
||||
|
||||
@ApiModelProperty(value="协议版本号", required = true, example = "1")
|
||||
private int ver;
|
||||
|
||||
@ApiModelProperty(value="msgContent字段内容编码格式:\n" +
|
||||
"0:无编码格式,普通字符串\n" +
|
||||
"1:base64编码格式\n" +
|
||||
"2:采用AES加密后的base64编码格式\n", required = true,
|
||||
allowableValues = "0, 1, 2",
|
||||
example = "0")
|
||||
private int cryptoType;
|
||||
|
||||
@ApiModelProperty(value="当前UTC时间戳", required = true, example = "1526625689000")
|
||||
private Long timeStamp;
|
||||
|
||||
@ApiModelProperty(value="协议详细内容,Json字符串格式。\n" +
|
||||
"保存该cmdId命令相关的详细内容,\n" +
|
||||
"具体每个cmdId命令的详细内容参看对应的命令协议定义", required = false,
|
||||
example = "{}")
|
||||
private String msgContent;
|
||||
|
||||
@ApiModelProperty(value="服务器返回状态码", required = false,
|
||||
example = "200")
|
||||
private int code;
|
||||
|
||||
public static ProtocolResp result(Resp resp) {
|
||||
return ProtocolResp.builder().code(resp.getCode()).msgContent(resp.getMsg()).build();
|
||||
}
|
||||
|
||||
public static ProtocolResp result(ErrorCode err) {
|
||||
return ProtocolResp.builder()
|
||||
.ver(ConstValue.Protocol.VERSION)
|
||||
.cryptoType(ConstValue.Protocol.CRYPTO_NONE)
|
||||
.code(err.getHttpCode())
|
||||
.timeStamp(System.currentTimeMillis())
|
||||
.msgContent(err.getMsg()).build();
|
||||
}
|
||||
|
||||
public static ProtocolResp result(ErrorCode err, Integer cmdId, String respMsg) {
|
||||
return result(err, cmdId, respMsg, ConstValue.Protocol.CRYPTO_NONE);
|
||||
}
|
||||
|
||||
public static ProtocolResp result(ErrorCode err, Integer cmdId, String respMsg, Integer crypto) {
|
||||
|
||||
return ProtocolResp.builder()
|
||||
.cmdId(cmdId + ConstValue.Protocol.RESP_CMD_BASE)
|
||||
.ver(ConstValue.Protocol.VERSION)
|
||||
.cryptoType(crypto)
|
||||
.timeStamp(System.currentTimeMillis())
|
||||
.code(err.getHttpCode())
|
||||
.msgContent(respMsg).build();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
/**
|
||||
* 后端返回码定义
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月4日
|
||||
*/
|
||||
public enum Resp {
|
||||
|
||||
// 成功返回码
|
||||
SUCCESS(200, "SUCCESS"),
|
||||
|
||||
// 3XX
|
||||
PARAM_ERROR(300, "自定义参数错误"),
|
||||
|
||||
// 4XX
|
||||
SYSTEM_ERROR(400, "系统内部自定义错误"),
|
||||
|
||||
// 5XX
|
||||
ERROR(500, "服务端系统错误"),
|
||||
|
||||
;
|
||||
|
||||
private int code;
|
||||
private String msg;
|
||||
|
||||
Resp(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class StartTaskRep {
|
||||
private String id;
|
||||
private String taskId;
|
||||
private long expireTime;
|
||||
private int status;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StartTaskReq {
|
||||
private String id;
|
||||
private int type;
|
||||
private String disposeIp;
|
||||
private long disposeTime;
|
||||
private int flowDirection;
|
||||
private List<Integer> attackType;
|
||||
private int flowBandwidth;
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StopTaskAllReq {
|
||||
int type;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StopTaskByIpReq {
|
||||
public List<StopTaskByIpReqMsg> items;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StopTaskByIpReqMsg {
|
||||
private String id;
|
||||
//任务类型 0:清洗 1:高防 2:黑洞 3:检测 -1: 所有类型
|
||||
private int type;
|
||||
//处置IP
|
||||
private String disposeIP;
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StopTaskByPonitReq {
|
||||
public List<StopTaskByPonitReqMsg> items;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StopTaskByPonitReqMsg {
|
||||
private String id;
|
||||
//任务类型 0:清洗 1:高防 2:黑洞 3:检测 -1: 所有类型
|
||||
private int type;
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StopTaskReq {
|
||||
public List<String> taskId;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StopTaskResult {
|
||||
private String id;
|
||||
private String taskId;
|
||||
private int type;
|
||||
private String disposeIp;
|
||||
private int leftTime;
|
||||
private int status;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class StopTaskRsp {
|
||||
public List<StopTaskResult> result;
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserLoginReq {
|
||||
public String userName;
|
||||
public String password;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class UserLoginRsp {
|
||||
private String userName;
|
||||
private String token;
|
||||
private Long logTime;
|
||||
private Long expireTime;
|
||||
private Integer status;
|
||||
private String message;
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserLogoutReq {
|
||||
public String userName;
|
||||
public String token;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.pojo.vo;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class UserLogoutRsp {
|
||||
private String userName;
|
||||
private Integer status;
|
||||
private String message;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月7日
|
||||
*/
|
||||
public interface AsyncService {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface DisposeDeviceManager {
|
||||
void loadDisposeFromDB();
|
||||
EnumMap<ErrorCode, Long> addNewDisposeDevice(DisposeDevice dev);
|
||||
|
||||
Map<String, DisposeDevice> getAllDisposeDevs();
|
||||
|
||||
List<DeviceCapacityInfo> getDeviceCapacityInfoById(Long id);
|
||||
|
||||
List<DeviceCapacityInfo> getDeviceCapacityInfoByDeviceId(Long deviceId);
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service;
|
||||
|
||||
public interface DisposeService {
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.EnumMap;
|
||||
|
||||
public interface LoginService {
|
||||
public EnumMap<ErrorCode, String> loginService(String username, String password) throws NoSuchAlgorithmException;
|
||||
public ErrorCode logoutService(String username, String token);
|
||||
ErrorCode authTokenCheck(String token);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public interface UserAccountCacheService {
|
||||
String getUserToken(String username) throws NoSuchAlgorithmException;
|
||||
int getUsrPwdErrTimes(String username);
|
||||
void setUserPwdErrTimes(String username, Integer errTimes);
|
||||
void cleanUserToken(String username);
|
||||
ErrorCode verifyUserLogin(String username, String token);
|
||||
ErrorCode verifyToken(String token);
|
||||
|
||||
String getCacheUser() throws JsonProcessingException;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service;
|
||||
|
||||
/**
|
||||
* 接口定义
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月5日
|
||||
*/
|
||||
public interface UserService {
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description: 服务测试方法
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public String testService(long id);
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service.impl;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.cmcc.hy.phoenix.service.AsyncService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月5日
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AsyncServiceImpl implements AsyncService {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service.impl;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.dispose.DeviceRouter;
|
||||
import com.cmcc.hy.phoenix.dispose.DisposeProcess;
|
||||
import com.cmcc.hy.phoenix.mapper.DeviceCapacityMapper;
|
||||
import com.cmcc.hy.phoenix.mapper.DisposeDeviceMapper;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DeviceCapacity;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.DisposeDevice;
|
||||
import com.cmcc.hy.phoenix.pojo.po.DeviceCapacityInfo;
|
||||
import com.dptech.umc.DetectionObjectDataForService;
|
||||
import com.dptech.umc.ProtectionObjectDataForService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import com.cmcc.hy.phoenix.service.DisposeDeviceManager;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private DataSourceTransactionManager dataSourceTransactionManager;
|
||||
@Resource
|
||||
private TransactionDefinition transactionDefinition;
|
||||
|
||||
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
|
||||
@Resource
|
||||
private DeviceCapacityMapper deviceCapacityMapper;
|
||||
|
||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public List<DeviceCapacityInfo> getDeviceCapacityInfoByDeviceId(Long deviceId) {
|
||||
List<DeviceCapacityInfo> devList = new ArrayList<>();
|
||||
|
||||
List<DeviceCapacity> devCaps = deviceCapacityMapper.getDeviceCapacityByDeviceId(deviceId);
|
||||
|
||||
devCaps.forEach(v -> {
|
||||
devList.add(DeviceCapacityInfo.builder()
|
||||
.capacity(v.getCapacity())
|
||||
.tolFlowCapacity(v.getTolFlowCapacity())
|
||||
.usedCapacity(0)
|
||||
.disposeIp(new String[]{}).build());
|
||||
});
|
||||
|
||||
return devList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceCapacityInfo> getDeviceCapacityInfoById(Long id) {
|
||||
|
||||
List<DeviceCapacityInfo> dev = disposeDeviceMapper.getDisposeDisposeDevById(id);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumMap<ErrorCode, Long> addNewDisposeDevice(DisposeDevice dev) {
|
||||
TransactionStatus transactionStatus = null;
|
||||
|
||||
EnumMap<ErrorCode, Long> retMap = new EnumMap<>(ErrorCode.class);
|
||||
if(isDisposeDeviceExists(dev.getIpv4())){
|
||||
retMap.put(ErrorCode.ERR_DEVICEEXISTS, -1L);
|
||||
return retMap;
|
||||
}
|
||||
|
||||
List<String> disposeIp = getDisposeIpFromDevice(dev.getType(), dev.getIpv4());
|
||||
|
||||
if(disposeIp == null) {
|
||||
retMap.put(ErrorCode.ERR_NOSUCHDEVICE, -1L);
|
||||
return retMap;
|
||||
}
|
||||
|
||||
if(dev.getDisposeIp() == null) {
|
||||
dev.setDisposeIp(disposeIp);
|
||||
} else {
|
||||
dev.getDisposeIp().addAll(disposeIp);
|
||||
}
|
||||
|
||||
try {
|
||||
transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
disposeDeviceMapper.addNewDisposeDevice(dev);
|
||||
dataSourceTransactionManager.commit(transactionStatus);
|
||||
retMap.put(ErrorCode.ERR_OK, dev.getId());
|
||||
addDisposeDeviceToCache(dev);
|
||||
} catch (Exception ex) {
|
||||
assert transactionStatus != null;
|
||||
dataSourceTransactionManager.rollback(transactionStatus);
|
||||
retMap.put(ErrorCode.ERR_EXCEPTION, -1L);
|
||||
}
|
||||
|
||||
return retMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadDisposeFromDB() {
|
||||
List<DisposeDevice> dp = disposeDeviceMapper.getAllDisposeDevice();
|
||||
|
||||
dp.forEach(v -> {
|
||||
v.setDisposeIp(getDisposeIpFromDevice(v.getType(), v.getIpv4()));
|
||||
disposeDevMap.put(v.getIpv4(), v);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, DisposeDevice> getAllDisposeDevs() {
|
||||
return disposeDevMap;
|
||||
}
|
||||
|
||||
private Boolean isDisposeDeviceExists(String ipv4) {
|
||||
return disposeDevMap.containsKey(ipv4);
|
||||
}
|
||||
|
||||
private void addDisposeDeviceToCache(DisposeDevice dev) {
|
||||
disposeDevMap.put(dev.getIpv4(), dev);
|
||||
}
|
||||
|
||||
private List<String> getDisposeIpFromDevice(int devType, String ipAddr) {
|
||||
DisposeProcess dptechUMC = DeviceRouter.deviceRouterFactory(devType, ipAddr);
|
||||
|
||||
if(dptechUMC == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
List<ProtectionObjectDataForService> detDevs = dptechUMC.getAllProtectionObject();
|
||||
|
||||
List<String> ipList = new ArrayList<>();
|
||||
|
||||
detDevs.forEach(v -> {
|
||||
String ipSegment = v.getIpSegment().getValue();
|
||||
|
||||
if(ipSegment.length() > 0) {
|
||||
ipList.addAll(Arrays.asList(v.getIpSegment().getValue().replaceAll("\\d{1,}_", "").split(",")));
|
||||
}
|
||||
});
|
||||
|
||||
return ipList;
|
||||
} catch(Exception ex) {
|
||||
log.info(ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service.impl;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.mapper.UserAccountMapper;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.UserAccount;
|
||||
import com.cmcc.hy.phoenix.service.LoginService;
|
||||
import com.cmcc.hy.phoenix.service.UserAccountCacheService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.EnumMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LoginServiceImpl implements LoginService {
|
||||
@Resource
|
||||
private UserAccountCacheService userAccountService;
|
||||
|
||||
@Resource
|
||||
private UserAccountMapper userAccountMapper;
|
||||
|
||||
@Override
|
||||
public ErrorCode authTokenCheck(String token) {
|
||||
return ErrorCode.ERR_OK;
|
||||
//return userAccountService.verifyToken(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumMap<ErrorCode, String> loginService(String username, String password) throws NoSuchAlgorithmException {
|
||||
EnumMap<ErrorCode, String> retMap = new EnumMap<>(ErrorCode.class);
|
||||
|
||||
// Example exp = new Example(UserAccount.class);
|
||||
// exp.createCriteria().andEqualTo("username", username);
|
||||
userAccountMapper.refreshLoginTime(username);
|
||||
UserAccount loginUser = userAccountMapper.getUserByName(username);
|
||||
|
||||
// 用户为空
|
||||
if(loginUser == null) {
|
||||
retMap.put(ErrorCode.ERR_USERNOTFOUND, "");
|
||||
} else {
|
||||
if(loginUser.getStatus() == ConstValue.UserAccountStatus.LOCKED) {
|
||||
retMap.put(ErrorCode.ERR_USERLOCK, "");
|
||||
} else if(!loginUser.getPassword().equals(password)) {
|
||||
// 密码错误
|
||||
int errTimes = userAccountService.getUsrPwdErrTimes(username) + 1;
|
||||
|
||||
// 更新密码错误次数
|
||||
userAccountService.setUserPwdErrTimes(username, errTimes);
|
||||
|
||||
if(errTimes == ConstValue.GlobalConfigure.ALLOW_PWD_ERR_TIMES - 1) {
|
||||
// 提示用户即将锁定账户
|
||||
retMap.put(ErrorCode.ERR_PASSWORDMORE, "");
|
||||
} else if(errTimes >= ConstValue.GlobalConfigure.ALLOW_PWD_ERR_TIMES) {
|
||||
// 锁定账户
|
||||
retMap.put(ErrorCode.ERR_USERLOCK, "");
|
||||
userAccountMapper.lockUserAccount(username);
|
||||
} else {
|
||||
retMap.put(ErrorCode.ERR_PASSWORD, "");
|
||||
}
|
||||
} else {
|
||||
retMap.put(ErrorCode.ERR_OK, userAccountService.getUserToken(username));
|
||||
userAccountService.setUserPwdErrTimes(username, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return retMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode logoutService(String username, String token) {
|
||||
ErrorCode err = ErrorCode.ERR_OK;
|
||||
|
||||
UserAccount loginUser = userAccountMapper.getUserByName(username);
|
||||
|
||||
// 用户为空
|
||||
if(loginUser == null) {
|
||||
err = ErrorCode.ERR_USERNOTFOUND;
|
||||
} else {
|
||||
|
||||
err = userAccountService.verifyUserLogin(username, token);
|
||||
|
||||
if(err == ErrorCode.ERR_OK) {
|
||||
userAccountService.cleanUserToken(username);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.cmcc.hy.phoenix.common.ErrorCode;
|
||||
import com.cmcc.hy.phoenix.pojo.po.UserAccountCache;
|
||||
import com.cmcc.hy.phoenix.service.UserAccountCacheService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserAccountCacheServiceImpl implements UserAccountCacheService {
|
||||
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private ConcurrentHashMap<String, UserAccountCache> userAccountMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public ErrorCode verifyToken(String token) {
|
||||
//userAccountMap
|
||||
|
||||
if(!userAccountMap.containsKey(token)){
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
} else {
|
||||
UserAccountCache uc = userAccountMap.get(token);
|
||||
|
||||
if((System.currentTimeMillis() - uc.getLastAccess())
|
||||
>= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) {
|
||||
return ErrorCode.ERR_TOKENTIMEOUT;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode verifyUserLogin(String username, String token) {
|
||||
Optional<UserAccountCache> findRet = userAccountMap.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if(!findRet.isPresent()) {
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
UserAccountCache uc = findRet.get();
|
||||
|
||||
if(uc.getToken().length() == 0) {
|
||||
return ErrorCode.ERR_LOGOUT;
|
||||
}
|
||||
|
||||
if((System.currentTimeMillis() - uc.getLastAccess())
|
||||
>= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS)
|
||||
{
|
||||
return ErrorCode.ERR_TOKENTIMEOUT;
|
||||
}
|
||||
|
||||
if(!uc.getToken().equals(token)) {
|
||||
return ErrorCode.ERR_TOKENNOTFOUND;
|
||||
}
|
||||
|
||||
return ErrorCode.ERR_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCacheUser() throws JsonProcessingException {
|
||||
return objectMapper.writeValueAsString(userAccountMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUserToken(String username) {
|
||||
Optional<UserAccountCache> findRet = userAccountMap.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if(findRet.isPresent()) {
|
||||
UserAccountCache uc = findRet.get();
|
||||
userAccountMap.remove(uc.getToken());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUsrPwdErrTimes(String username) {
|
||||
Optional<UserAccountCache> findRet = userAccountMap.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if(findRet.isPresent()) {
|
||||
UserAccountCache uc = findRet.get();
|
||||
return uc.getPwdErrTimes();
|
||||
} else {
|
||||
UserAccountCache uc = UserAccountCache.builder()
|
||||
.username(username)
|
||||
.token("")
|
||||
.lastAccess(System.currentTimeMillis())
|
||||
.pwdErrTimes(0)
|
||||
.lastAccess(System.currentTimeMillis()).build();
|
||||
|
||||
userAccountMap.put(uc.getToken(), uc);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserPwdErrTimes(String username, Integer errTimes) {
|
||||
Optional<UserAccountCache> findRet = userAccountMap.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if(findRet.isPresent()) {
|
||||
UserAccountCache uc = findRet.get();
|
||||
uc.setPwdErrTimes(Math.abs(errTimes));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserToken(String username) throws NoSuchAlgorithmException {
|
||||
|
||||
Optional<UserAccountCache> findRet = userAccountMap.values().stream()
|
||||
.filter(userAccountCache -> username.equals(userAccountCache.getUsername()))
|
||||
.findFirst();
|
||||
|
||||
if(findRet.isPresent()) {
|
||||
UserAccountCache uc = findRet.get();
|
||||
|
||||
if((System.currentTimeMillis() - uc.getLastAccess())
|
||||
>= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS
|
||||
|| uc.getToken().length() == 0) {
|
||||
uc.setToken(createUserToken(username));
|
||||
log.info("Refresh {} Token:{}", username, uc.getToken());
|
||||
} else {
|
||||
log.info("Get {} Token:{}", username, uc.getToken());
|
||||
}
|
||||
|
||||
uc.setLastAccess(System.currentTimeMillis());
|
||||
|
||||
return uc.getToken();
|
||||
} else {
|
||||
UserAccountCache uc = UserAccountCache.builder()
|
||||
.username(username)
|
||||
.token(createUserToken(username))
|
||||
.lastAccess(System.currentTimeMillis())
|
||||
.pwdErrTimes(0)
|
||||
.lastAccess(System.currentTimeMillis()).build();
|
||||
|
||||
userAccountMap.put(uc.getToken(), uc);
|
||||
|
||||
log.info("Create {} Token:{}", username, uc.getToken());
|
||||
|
||||
return uc.getToken();
|
||||
}
|
||||
}
|
||||
|
||||
private String createUserToken(String username) throws NoSuchAlgorithmException {
|
||||
// 获取指定摘要算法的messageDigest对象
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); // 此处的sha代表sha1
|
||||
|
||||
String tokenKey = username +
|
||||
Convert.toStr(new Random(System.currentTimeMillis()).nextInt()) +
|
||||
Convert.toStr(System.currentTimeMillis());
|
||||
// 调用digest方法,进行加密操作
|
||||
byte[] cipherBytes = messageDigest.digest(tokenKey.getBytes());
|
||||
|
||||
return Hex.encodeHexString(cipherBytes);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package com.cmcc.hy.phoenix.service.impl;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.cmcc.hy.phoenix.config.MyConfig;
|
||||
import com.cmcc.hy.phoenix.manager.GlobalManager;
|
||||
import com.cmcc.hy.phoenix.pojo.entity.User;
|
||||
import com.cmcc.hy.phoenix.service.UserService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author phoenix
|
||||
* @date 2020年2月5日
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Resource
|
||||
private MyConfig myConfig;
|
||||
|
||||
@Resource
|
||||
private GlobalManager globalManager;
|
||||
|
||||
@Override
|
||||
public String testService(long id) {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("进入service方法");
|
||||
User user = globalManager.findUserById(id);
|
||||
if(user == null ) {
|
||||
return "user is null";
|
||||
}
|
||||
log.info("service层查出用户信息 {}", user);
|
||||
log.info("自定义配置获取 {}", myConfig.getSystemName());
|
||||
// 返回用户名
|
||||
return user.getName();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.cmcc.hy.phoenix.Interceptor;
|
||||
package com.dispose.Interceptor;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.ConstValue;
|
||||
import com.dispose.common.ConstValue;
|
||||
import org.apache.wss4j.common.ext.WSPasswordCallback;
|
||||
|
||||
import javax.security.auth.callback.Callback;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix;
|
||||
package com.dispose;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -21,7 +21,7 @@ import tk.mybatis.spring.annotation.MapperScan;
|
|||
@EnableScheduling
|
||||
@EnableAspectJAutoProxy
|
||||
@EnableTransactionManagement
|
||||
@MapperScan(basePackages = { "com.cmcc.hy.phoenix.mapper" })
|
||||
@MapperScan(basePackages = { "com.cmcc.dispose.mapper" })
|
||||
@Slf4j
|
||||
public class PhoenixBootApplication {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.cmcc.hy.phoenix.annotation;
|
||||
package com.dispose.annotation;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.validator.UserIdValidator;
|
||||
import com.dispose.annotation.validator.UserIdValidator;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.annotation.bodyencdec;
|
||||
package com.dispose.annotation.bodyencdec;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.annotation.bodyencdec;
|
||||
package com.dispose.annotation.bodyencdec;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
|
@ -1,6 +1,6 @@
|
|||
package com.cmcc.hy.phoenix.annotation.validator;
|
||||
package com.dispose.annotation.validator;
|
||||
|
||||
import com.cmcc.hy.phoenix.annotation.UserId;
|
||||
import com.dispose.annotation.UserId;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.Set;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.aop;
|
||||
package com.dispose.aop;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.aop.cache;
|
||||
package com.dispose.aop.cache;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.aop.cache;
|
||||
package com.dispose.aop.cache;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.aop.cache;
|
||||
package com.dispose.aop.cache;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.aop.cache;
|
||||
package com.dispose.aop.cache;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.aop.cache;
|
||||
package com.dispose.aop.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -20,8 +20,8 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cmcc.hy.phoenix.common.Utils;
|
||||
import com.cmcc.hy.phoenix.redis.RedisClient;
|
||||
import com.dispose.common.Utils;
|
||||
import com.dispose.redis.RedisClient;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.cmcc.hy.phoenix.common;
|
||||
package com.dispose.common;
|
||||
|
||||
public class ConstValue {
|
||||
public class GlobalConfigure {
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue