Sfoglia il codice sorgente

登录ip现在排除手机端

o2sword 5 anni fa
parent
commit
3a23c934d6

+ 43 - 8
o2server/x_organization_assemble_authentication/src/main/java/com/x/organization/assemble/authentication/jaxrs/authentication/BaseAction.java

@@ -1,9 +1,6 @@
 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;
+	}
+
 }