You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.8 KiB
78 lines
2.8 KiB
3 years ago
|
package com.eco.plugin.xx.gfjjwhite.utils;
|
||
|
|
||
|
import com.eco.plugin.xx.gfjjwhite.config.PluginSimpleConfig;
|
||
|
import com.fr.data.NetworkHelper;
|
||
|
import com.fr.decision.webservice.v10.config.ConfigService;
|
||
|
import com.fr.decision.webservice.v10.login.TokenResource;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.plugin.transform.FunctionRecorder;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.third.springframework.web.util.WebUtils;
|
||
|
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import java.io.IOException;
|
||
|
|
||
|
@FunctionRecorder
|
||
|
public class IPWhiteUtils{
|
||
|
|
||
|
private static String ipWhite;
|
||
|
private static String servletName="decision";
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 判断是否是白名单IP "192.168.1.1," + //设置单个IP的白名单
|
||
|
* "192.168.*.2," + //设置ip通配符,对一个ip段进行匹配
|
||
|
* "192.168.3.17-192.168.3.38"; //设置一个IP范围
|
||
|
* @param req
|
||
|
* @return
|
||
|
*/
|
||
|
public static boolean inWhite(HttpServletRequest req) {
|
||
|
try {
|
||
|
servletName = ConfigService.getInstance().getBasicParam().getServletPathName();
|
||
|
} catch (Exception e) {
|
||
|
FineLoggerFactory.getLogger().error("[ENC]获取servletName失败");
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
ipWhite= PluginSimpleConfig.getInstance().getIpwhite();
|
||
|
|
||
|
String ip= IPUtils.getRealIp(req);
|
||
|
//内网标记
|
||
|
boolean isInnerIPFlag= false;
|
||
|
try {
|
||
|
isInnerIPFlag = IPUtils.isInnerIP(ip,ipWhite);
|
||
|
} catch (IOException e) {
|
||
|
FineLoggerFactory.getLogger().error("[ENC]判断IP失败");
|
||
|
}
|
||
|
|
||
|
//移动设备标记
|
||
|
boolean isMobileFlag=NetworkHelper.getDevice(req).isMobile();
|
||
|
|
||
|
//移动端原生登陆标记
|
||
|
boolean isMobileLoginFlag=req.getRequestURI().contains(servletName+"/login") && !isInnerIPFlag;
|
||
|
|
||
|
//微信登陆标记
|
||
|
boolean isDingLoginFlag=req.getRequestURI().contains("weixin/single/login") && isMobileFlag;
|
||
|
|
||
|
String token = TokenResource.COOKIE.getToken(req);
|
||
|
//是否登陆标记
|
||
|
boolean isHasTokenFlag=!StringUtils.isEmpty(token) && IPUtils.checkTokenValid(req, token);
|
||
|
|
||
|
//移动端原生登陆标记
|
||
|
boolean isResourcesFlag=req.getRequestURI().contains(servletName+"/resources");
|
||
|
|
||
|
boolean isHasDingCookie=WebUtils.getCookie(req, "LOGIN_TYPE") != null;
|
||
|
|
||
|
FineLoggerFactory.getLogger().debug("[ENC]内网[{}]|移动设备[{}]|移动原生登陆[{}]|微信登陆[{}]|是否登陆[{}]|请求[{}]",isInnerIPFlag,isMobileFlag,isMobileLoginFlag,isDingLoginFlag,isHasTokenFlag,req.getRequestURI());
|
||
|
|
||
|
if(isInnerIPFlag || isResourcesFlag || isHasDingCookie){
|
||
|
return true;
|
||
|
}
|
||
|
else if(isDingLoginFlag){
|
||
|
return true;
|
||
|
} else{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|