Commit 551d15f4 authored by 技术部-任文超's avatar 技术部-任文超

支持测试环境白名单192.168.0.0/16:-Dtest=true

parent 612094d7
......@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
@RequestMapping("/lock")
public class LockIpv4Controller implements IBaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(LockIpv4Controller.class);
private static final String WORD = "Are you a robot monkey?(^_^)";
@Autowired
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> redisTemplate;
......@@ -43,16 +44,18 @@ public class LockIpv4Controller implements IBaseController {
*/
@RequestMapping("/key")
public JsonResult key(@RequestParam(required = false)String act, HttpServletRequest request) {
//系统环境
String jvmTest = Boolean.valueOf(System.getProperty("test")).toString();
if(Objects.equals(Boolean.TRUE.toString(), act) || Objects.equals(Boolean.FALSE.toString(), act)){
// 操作标记
boolean lock = Objects.equals(Boolean.TRUE.toString(), act);
String header_key = request.getHeader(Constants.IPV4_LOCK.replace(":", ""));
if(Objects.equals(Constants.CLEAR_LOCK_FOR_IPV4, header_key)){
String md5Key = ValidationUtil.getMd5Key(lock);
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)", md5Key);
return JsonResult.buildErrorStateResult(WORD.concat(jvmTest), md5Key);
}
}
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
return JsonResult.buildErrorStateResult(WORD.concat(jvmTest),null);
}
/**
......@@ -70,7 +73,7 @@ public class LockIpv4Controller implements IBaseController {
HttpServletRequest request) {
if(!ValidationUtil.validateIpv4(ip) || StringUtils.isBlank(act) || StringUtils.isBlank(key)){
LOGGER.info("Lock_ipv4: fail to clear_or_lock ip:{}", ip);
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
return JsonResult.buildErrorStateResult(WORD,null);
}
if(Objects.equals(Boolean.TRUE.toString(), act) || Objects.equals(Boolean.FALSE.toString(), act)){
// 操作标记
......@@ -82,7 +85,7 @@ public class LockIpv4Controller implements IBaseController {
}
}
LOGGER.info("Lock_ipv4: fail to clear_or_lock ip:{}", ip);
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
return JsonResult.buildErrorStateResult(WORD,null);
}
/**
......@@ -131,7 +134,7 @@ public class LockIpv4Controller implements IBaseController {
HttpServletRequest request) {
if(!ValidationUtil.validateIpv4(ip) || StringUtils.isBlank(key) || StringUtils.isBlank(act) || StringUtils.isBlank(type)){
LOGGER.info("Lock_ipv4: fail to config hit list for ip:{}", ip);
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
return JsonResult.buildErrorStateResult(WORD,null);
}
boolean actOk = Objects.equals(Boolean.TRUE.toString(), act) || Objects.equals(Boolean.FALSE.toString(), act);
boolean typeOk = Objects.equals(Boolean.TRUE.toString(), type) || Objects.equals(Boolean.FALSE.toString(), type);
......@@ -144,7 +147,7 @@ public class LockIpv4Controller implements IBaseController {
return JsonResult.buildSuccessResult("Success",null);
}
LOGGER.info("Lock_ipv4: fail to config hit list for ip:{}", ip);
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
return JsonResult.buildErrorStateResult(WORD,null);
}
/**
......@@ -194,7 +197,7 @@ public class LockIpv4Controller implements IBaseController {
HttpServletRequest request) {
if(StringUtils.isBlank(key) || StringUtils.isBlank(act) || !StringUtils.isNumeric(counts) || !StringUtils.isNumeric(minutes)){
LOGGER.info("Lock_ipv4: fail to config noun");
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
return JsonResult.buildErrorStateResult(WORD,null);
}
boolean actOk = Objects.equals(Boolean.TRUE.toString(), act) || Objects.equals(Boolean.FALSE.toString(), act);
boolean valid = actOk && ValidationUtil.isValid(key, Objects.equals(Boolean.TRUE.toString(), act));
......@@ -211,7 +214,7 @@ public class LockIpv4Controller implements IBaseController {
}
}
LOGGER.info("Lock_ipv4: fail to config noun");
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
return JsonResult.buildErrorStateResult(WORD,null);
}
/**
......
......@@ -5,10 +5,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.*;
/**
* IP地址工具类
......@@ -31,6 +28,11 @@ public class IPUtil {
static {
String[] ips = {"172.16.", "172.20.", "172.30.", "192.168.3.", "192.168.4."};
WHITE_ADDRESS.addAll(Arrays.asList(ips));
//系统环境
String jvmTest = System.getProperty("test");
if(Boolean.valueOf(jvmTest)){
WHITE_ADDRESS.add("192.168.");
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment