提交 3a23c934 编写于 作者: O o2sword

登录ip现在排除手机端

上级 fe0c69ab
package com.x.organization.assemble.authentication.jaxrs.authentication;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
......@@ -74,10 +71,12 @@ abstract class BaseAction extends StandardJaxrsAction {
EffectivePerson effectivePerson = new EffectivePerson(person.getDistinguishedName(), tokenType,
Config.token().getCipher());
if ((null != request) && (null != response)) {
String clientIp = HttpToken.remoteAddress(request);
logger.debug("{} client ip is : {}",person.getDistinguishedName(), clientIp);
if(!this.checkIp(clientIp, person.getIpAddress())){
throw new ExceptionInvalidIpAddress(clientIp);
if(!isMoaTerminal(request)) {
String clientIp = HttpToken.remoteAddress(request);
logger.debug("{} client ip is : {}", person.getDistinguishedName(), clientIp);
if (!this.checkIp(clientIp, person.getIpAddress())) {
throw new ExceptionInvalidIpAddress(clientIp);
}
}
httpToken.setToken(request, response, effectivePerson);
}
......@@ -311,4 +310,40 @@ abstract class BaseAction extends StandardJaxrsAction {
return returnValue;
}
protected boolean isMoaTerminal(HttpServletRequest request){
String xClient = request.getHeader("x-client");
if(StringUtils.isNotBlank(xClient)){
xClient = xClient.toLowerCase();
if (xClient.indexOf("android") != -1) {
//安卓
return true;
}
if (xClient.indexOf("ios") != -1) {
//安卓
return true;
}
}
String userAgent = request.getHeader("User-Agent");
if(StringUtils.isNotBlank(userAgent)) {
userAgent = userAgent.toLowerCase();
if (userAgent.indexOf("micromessenger") != -1) {
//微信
return true;
}
if (userAgent.indexOf("dingtalk") != -1) {
//钉钉
return true;
}
if (userAgent.indexOf("android") != -1) {
//安卓
return true;
}
if (userAgent.indexOf("iphone") != -1 || userAgent.indexOf("ipad") != -1 || userAgent.indexOf("ipod") != -1) {
//苹果
return true;
}
}
return false;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册