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.
80 lines
2.8 KiB
80 lines
2.8 KiB
3 years ago
|
package com.fr.plugin.ipsso.utils;
|
||
|
|
||
|
import com.fr.data.NetworkHelper;
|
||
|
import com.fr.decision.webservice.v10.config.ConfigService;
|
||
|
import com.fr.decision.webservice.v10.login.TokenResource;
|
||
|
import com.fr.io.utils.ResourceIOUtils;
|
||
|
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;
|
||
|
import java.util.Properties;
|
||
|
|
||
|
@FunctionRecorder
|
||
|
public class IPWhiteUtils{
|
||
|
|
||
|
private static String ipWhite;
|
||
|
private static String servletName="decision";
|
||
|
|
||
|
|
||
|
|
||
|
public static boolean inWhite(HttpServletRequest req) {
|
||
|
try {
|
||
|
servletName = ConfigService.getInstance().getBasicParam().getServletPathName();
|
||
|
} catch (Exception e) {
|
||
|
FineLoggerFactory.getLogger().error("[ENC]获取servletName失败");
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
|
||
|
Properties pro = new Properties();
|
||
|
try {
|
||
|
pro.load(ResourceIOUtils.read("/resources/ip4enc.properties"));
|
||
|
FineLoggerFactory.getLogger().error("[ENC]IP白名单获取失败");
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
ipWhite= pro.getProperty("ipWhite",StringUtils.EMPTY);
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|