Commit ee380f09 authored by Java-刘 彧阳's avatar Java-刘 彧阳

对innerapi的访问进行IP限制

parent 9e948f96
package cn.quantgroup.xyqb.interceptors;
import cn.quantgroup.xyqb.util.IPUtil;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -9,6 +10,8 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
/**
......@@ -21,6 +24,8 @@ public class IPWhiteListInterceptor implements HandlerInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(IPWhiteListInterceptor.class);
private static final String patternStr = "172.*";
private static final String [] allowIPs = {"139.198.7.123"};
private static Set<String> allowIPSet = Sets.newHashSet(allowIPs);
private static final Pattern pattern = Pattern.compile(patternStr);
public IPWhiteListInterceptor(Integer isDebug) {
......@@ -32,15 +37,16 @@ public class IPWhiteListInterceptor implements HandlerInterceptor {
if(isDebug !=0) return true;
String remoteIP = IPUtil.getRemoteIP(request);
if(StringUtils.isNoneBlank(remoteIP)){
/*boolean isMatch = pattern.matcher(remoteIP).matches();
remoteIP = remoteIP.trim();
boolean isMatch = pattern.matcher(remoteIP).matches();
isMatch = Boolean.logicalOr(isMatch,allowIPSet.contains(remoteIP));
if(!isMatch){
LOGGER.info("非法IP尝试访问,ip:[{}]",remoteIP);
}
return isMatch;*/
LOGGER.info("来源IP:[{}]",remoteIP);
return isMatch;
}
// LOGGER.info("未能获取remoteIP");
return true;
LOGGER.info("未能获取remoteIP");
return false;
}
@Override
......
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