Commit 1094ea89 authored by 技术部-任文超's avatar 技术部-任文超

锁定时长调整为30分钟

parent 92d23e69
......@@ -35,15 +35,17 @@ public interface Constants {
String REDIS_VOICE_DEVICE_COUNT = "Voice_Device_verification_code_count:";
String REDIS_VERIFICATION_COUNT = "verification_code_count:";
final Long Image_Need_Count=3L;
Long Image_Need_Count=3L;
String REDIS_PASSWORD_ERROR_COUNT = "password_error_count:";
String REDIS_PASSWORD_ERROR_COUNT_FOR_IPV4 = "password_error_count_4_ipv4:";
String IPV4_LOCK = "lock_ipv4:";
final Long IPV4_LOCK_MINUTES = 6 * 60L;
final Long IPV4_COUNT_MINUTES = 1L;
final Long IPV4_LOCK_ON_COUNTS = 200L;
final int DANGEROUS_TIME_START = 22;
final int DANGEROUS_TIME_END = 6;
Long IPV4_LOCK_MINUTES = 30L;
Long IPV4_COUNT_MINUTES = 1L;
Long IPV4_LOCK_ON_COUNTS = 200L;
int DANGEROUS_TIME_START = 22;
int DANGEROUS_TIME_END = 6;
String CLEAR_LOCK_FOR_IPV4 = "x-clear-lock-11241842-y";
String CLEAR_LOCK_FOR_IPV4_KEY = "lhp.family.dwy.sjs.yym.cxy.cpg";
/**
* redis中token的key值前缀
*/
......
......@@ -23,6 +23,7 @@ import cn.quantgroup.xyqb.util.DateUtils;
import cn.quantgroup.xyqb.util.MqUtils;
import cn.quantgroup.xyqb.util.PasswordUtil;
import cn.quantgroup.xyqb.util.ValidationUtil;
import cn.quantgroup.xyqb.util.encrypt.MD5Util;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
......@@ -36,9 +37,8 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
......@@ -50,7 +50,6 @@ public class UserController implements IBaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
private final String pwdSalt = "_lkb";
@Autowired
......@@ -95,24 +94,54 @@ public class UserController implements IBaseController {
return loginWithHttpBasic(channelId, appChannel, createdFrom, merchant, request, openId,dimension);
}
}
//@LogHttpCaller
//@RequestMapping("/login2")
//public JsonResult login2(
// @RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
// @RequestParam(required = false, defaultValue = "1") Long createdFrom,
// @RequestParam(required = false, defaultValue = "") String userId, HttpServletRequest request, @RequestParam(required = false) String openId,@RequestParam(required = false) String dimension) {
//
// if (!StringUtils.isEmpty(userId) && userId.length() > 10) {
//
// return loginWithUserId(channelId, appChannel, createdFrom, userId, null, dimension);
// } else {
// return loginWithHttpBasic(channelId, appChannel, createdFrom, null, request, null,dimension);
// }
//}
@RequestMapping("/test")
public JsonResult test() {
return JsonResult.buildSuccessResult("", getCurrentUserFromRedis());
/**
* 解锁特定IP
* @param ip - 目标IP
* @param act - 操作标记,true-lock,false-unlock
* @param key - 密令
* @param request
* @return
*/
@RequestMapping("/lock_ipv4")
public JsonResult clearLockForIpv4(@RequestParam(required = true)String ip,
@RequestParam(required = false)String act,
@RequestParam(required = true)String key,
HttpServletRequest request) {
if(!ValidationUtil.validateIpv4(ip) || StringUtils.isBlank(act) || StringUtils.isBlank(key)){
LOGGER.info("Fail to clear_or_lock ip:{}", ip);
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
}
// 操作标记
boolean lock = Objects.equals(Boolean.TRUE.toString(), act);
// 解析密令
String header_key = request.getHeader(Constants.CLEAR_LOCK_FOR_IPV4);
byte[] buf = Base64.decodeBase64(header_key);
header_key = new String(buf, Charset.forName("UTF-8"));
boolean valid = isValid(header_key, lock);
if(valid){
String lockIpv4Key = getLockIpv4Key(ip);
stringRedisTemplate.delete(lockIpv4Key);
LOGGER.info("Clear_or_lock ip Success:{}", ip);
return JsonResult.buildSuccessResult("Success",null);
}
LOGGER.info("Fail to clear_or_lock ip:{}", ip);
return JsonResult.buildErrorStateResult("Are you a robot monkey?(^_^)",null);
}
/**
* 验证密令
* 私钥 + 操作 + 时
* @param key - Md5密令
* @param lock - true or false
* @return
*/
private boolean isValid(String key, boolean lock) {
Calendar today = Calendar.getInstance();
int hour_24 = today.get(Calendar.HOUR_OF_DAY);
StringBuilder _key = new StringBuilder();
_key.append(Constants.CLEAR_LOCK_FOR_IPV4_KEY).append(lock).append(hour_24);
return Objects.equals(key, MD5Util.build(_key.toString()));
}
@RequestMapping("/login/fast")
......@@ -186,12 +215,7 @@ public class UserController implements IBaseController {
}
credential = credential.substring(verificationHeader.length(), credential.length());
byte[] buf = Base64.decodeBase64(credential);
try {
credential = new String(buf, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.error("不支持的编码.");
result.put("fail", JsonResult.buildErrorStateResult("登录失败", null));
}
credential = new String(buf, Charset.forName("UTF-8"));
String[] credentialArr = credential.split(":");
if (credentialArr.length != 2) {
result.put("fail", JsonResult.buildErrorStateResult("登录失败", null));
......
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