diff --git a/README.en-us.md b/README.en-us.md index 37046f5..a2ff76d 100644 --- a/README.en-us.md +++ b/README.en-us.md @@ -4,7 +4,7 @@ English | [简体中文](./README.md)

- Version + Version Documentation @@ -105,6 +105,7 @@ Starting from v1.3.0, the frontend and backend of the management backend are mer | v2.0.0 | v2.0.0 | | v2.1.0 | v2.1.0 | | v2.2.0 | v2.2.0 | +| v2.2.1 | v2.2.1 | Please download the corresponding management backend version according to the version of the community version diff --git a/README.md b/README.md index 5bcc96a..e4cc9f5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

- Version + Version Documentation @@ -105,6 +105,7 @@ API地址:http://demo.fizzgate.com/proxy/[服务名]/[API_Path] | v2.0.0 | v2.0.0 | | v2.1.0 | v2.1.0 | | v2.2.0 | v2.2.0 | +| v2.2.1 | v2.2.1 | 请根据社区版的版本下载对应的管理后台版本 diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index 6a4ca5a..c9bc84e 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -12,7 +12,7 @@ com.fizzgate fizz-bootstrap - 2.2.0 + 2.2.1 1.8 diff --git a/fizz-common/pom.xml b/fizz-common/pom.xml index 2b4d5cb..a563857 100644 --- a/fizz-common/pom.xml +++ b/fizz-common/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0 + 2.2.1 ../pom.xml 4.0.0 diff --git a/fizz-common/src/main/java/we/util/TypeUtils.java b/fizz-common/src/main/java/we/util/TypeUtils.java new file mode 100644 index 0000000..104e4d7 --- /dev/null +++ b/fizz-common/src/main/java/we/util/TypeUtils.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2021 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package we.util; + +import java.math.BigDecimal; + +/** + * @author Francis Dong + */ + +public abstract class TypeUtils { + + public static boolean isBasicType(Object obj) { + if (obj == null) { + return false; + } + if (obj instanceof String) { + return true; + } + if (obj instanceof Integer) { + return true; + } + if (obj instanceof Long) { + return true; + } + if (obj instanceof Double) { + return true; + } + if (obj instanceof Float) { + return true; + } + if (obj instanceof Boolean) { + return true; + } + if (obj instanceof Byte) { + return true; + } + if (obj instanceof Short) { + return true; + } + if (obj instanceof Character) { + return true; + } + if (obj instanceof BigDecimal) { + return true; + } + return false; + } + +} diff --git a/fizz-core/pom.xml b/fizz-core/pom.xml index f8b75ec..9f041dc 100644 --- a/fizz-core/pom.xml +++ b/fizz-core/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0 + 2.2.1 ../pom.xml 4.0.0 diff --git a/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java b/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java index 762714b..932fa1b 100644 --- a/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java +++ b/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java @@ -59,6 +59,7 @@ import we.proxy.FizzWebClient; import we.proxy.http.HttpInstanceService; import we.util.JacksonUtils; import we.util.MapUtil; +import we.util.TypeUtils; import we.xml.JsonToXml; import we.xml.XmlToJson; import we.xml.XmlToJson.Builder; @@ -363,10 +364,19 @@ public class RequestInput extends RPCInput implements IInput{ if (CONTENT_TYPE_XML.equals(reqContentType) || CONTENT_TYPE_TEXT_XML.equals(reqContentType)) { // convert JSON to XML if it is XML content type request.put("jsonBody", request.get("body")); - String jsonStr = JSON.toJSONString(request.get("body")); + String jsonStr = null; + if (TypeUtils.isBasicType(request.get("body"))) { + jsonStr = request.get("body").toString(); + } else { + jsonStr = JSON.toJSONString(request.get("body")); + } LOGGER.info("jsonBody={}", jsonStr); - JsonToXml jsonToXml = new JsonToXml.Builder(jsonStr).build(); - body = jsonToXml.toString(); + if (jsonStr.startsWith("{") || jsonStr.startsWith("[")) { + JsonToXml jsonToXml = new JsonToXml.Builder(jsonStr).build(); + body = jsonToXml.toString(); + } else { + body = jsonStr; + } request.put("body", body); LOGGER.info("body={}", body); LOGGER.info("headers={}", JSON.toJSONString(headers)); @@ -379,7 +389,11 @@ public class RequestInput extends RPCInput implements IInput{ } else if (CONTENT_TYPE_FORM_URLENCODED.equals(reqContentType)) { body = BodyInserters.fromFormData(MapUtil.toMultiValueMap((Map) request.get("body"))); } else { - body = JSON.toJSONString(request.get("body")); + if (TypeUtils.isBasicType(request.get("body"))) { + body = request.get("body").toString(); + } else { + body = JSON.toJSONString(request.get("body")); + } } HttpMethod aggrMethod = HttpMethod.valueOf(inputContext.getStepContext().getInputReqAttr("method").toString()); diff --git a/fizz-core/src/main/java/we/plugin/auth/App.java b/fizz-core/src/main/java/we/plugin/auth/App.java index ab7763a..3d89a84 100644 --- a/fizz-core/src/main/java/we/plugin/auth/App.java +++ b/fizz-core/src/main/java/we/plugin/auth/App.java @@ -23,7 +23,6 @@ import we.util.Constants; import we.util.JacksonUtils; import java.util.*; -import java.util.stream.Collectors; /** * @author hongqiaowei @@ -41,25 +40,25 @@ public class App { static final int SECRETKEY = 3; } - public int isDeleted = 0; // tb_app_auth.is_deleted + public int isDeleted = 0; // tb_app_auth.is_deleted - public int id; // tb_app_auth.id + public int id; // tb_app_auth.id - public String app; // tb_app_auth.app + public String app; // tb_app_auth.app - public String name; // tb_app_auth.app_name + public String name; // tb_app_auth.app_name - public boolean useAuth = false; // 0:false, 1:true + public boolean useAuth = false; // 0:false, 1:true - public int authType; + public int authType; - public String secretkey; + public String secretkey; - public boolean useWhiteList = false; + public boolean useWhiteList = false; - public String config; + public String config; - public Map ips = new HashMap<>(8); + public Map> ips = new HashMap<>(); public void setUseAuth(int i) { if (i == AUTH_TYPE.SIGN || i == AUTH_TYPE.SECRETKEY || i == AUTH_TYPE.CUSTOM) { @@ -82,12 +81,17 @@ public class App { String subnet = ip.substring(0, i).trim(); String addrSeg = ip.substring(i + 1).trim(); if ("*".equals(addrSeg)) { - this.ips.put(subnet, new String[]{"2", "254"}); + this.ips.put(subnet, Collections.singletonList(new String[]{"1", "255"})); } else if (addrSeg.indexOf('-') > 0) { String[] a = StringUtils.split(addrSeg, '-'); String beg = a[0].trim(); String end = a[1].trim(); - this.ips.put(subnet, new String[]{beg, end}); + List lst = this.ips.get(subnet); + if (lst == null) { + lst = new ArrayList<>(); + this.ips.put(subnet, lst); + } + lst.add(new String[]{beg, end}); } else { this.ips.put(ip, null); } @@ -101,7 +105,7 @@ public class App { return true; } int originSubnetLen = ip.lastIndexOf(Constants.Symbol.DOT); - for (Map.Entry e : ips.entrySet()) { + for (Map.Entry> e : ips.entrySet()) { String subnet = e.getKey(); int subnetLen = subnet.length(); byte i = 0; @@ -113,47 +117,57 @@ public class App { } if (i == subnetLen) { int originAddrLen = ip.length() - originSubnetLen - 1; - String[] addrSeg = e.getValue(); - String addrSegBeg = addrSeg[0]; - String addrSegEnd = addrSeg[1]; - if (originAddrLen < addrSegBeg.length() || addrSegEnd.length() < originAddrLen) { - return false; - } else { - boolean b = true; - if (originAddrLen == addrSegBeg.length()) { - for (byte j = 0; j < addrSegBeg.length(); j++) { - char o = ip.charAt(originSubnetLen + 1 + j); - char a = addrSegBeg.charAt(j); - if (o < a) { - b = false; - break; - } else if (o > a) { - break; - } - } + boolean in = false; + for (String[] addrSeg : e.getValue()) { + in = inAddrSeg(ip, originSubnetLen, originAddrLen, addrSeg); + if (in) { + return in; } - if (b) { - if (originAddrLen == addrSegEnd.length()) { - for (byte j = 0; j < addrSegEnd.length(); j++) { - char a = addrSegEnd.charAt(j); - char o = ip.charAt(originSubnetLen + 1 + j); - if (a < o) { - b = false; - break; - } else if (a > o) { - break; - } - } - } - } - return b; } + return in; } } } return false; } + private boolean inAddrSeg(String ip, int originSubnetLen, int originAddrLen, String[] addrSeg) { + String addrSegBeg = addrSeg[0]; + String addrSegEnd = addrSeg[1]; + if (originAddrLen < addrSegBeg.length() || addrSegEnd.length() < originAddrLen) { + return false; + } else { + boolean b = true; + if (originAddrLen == addrSegBeg.length()) { + for (byte j = 0; j < addrSegBeg.length(); j++) { + char o = ip.charAt(originSubnetLen + 1 + j); + char a = addrSegBeg.charAt(j); + if (o < a) { + b = false; + break; + } else if (o > a) { + break; + } + } + } + if (b) { + if (originAddrLen == addrSegEnd.length()) { + for (byte j = 0; j < addrSegEnd.length(); j++) { + char a = addrSegEnd.charAt(j); + char o = ip.charAt(originSubnetLen + 1 + j); + if (a < o) { + b = false; + break; + } else if (a > o) { + break; + } + } + } + } + return b; + } + } + @Override public String toString() { return JacksonUtils.writeValueAsString(this); diff --git a/fizz-core/src/test/java/we/plugin/auth/AppTests.java b/fizz-core/src/test/java/we/plugin/auth/AppTests.java index 4a4527c..6f07a41 100644 --- a/fizz-core/src/test/java/we/plugin/auth/AppTests.java +++ b/fizz-core/src/test/java/we/plugin/auth/AppTests.java @@ -13,23 +13,53 @@ public class AppTests { @Test void ipWhiteListTest() { App app = new App(); - app.setIps("10.237.148.107,10.237.148.134,172.25.33.*,172.25.63.*,172.25.102.*,172.25.104.136-138"); + app.setIps("10.237.148.107,10.237.148.134,172.25.33.*,172.25.63.*,172.25.102.*,172.25.104.136-138," + + "101.236.11.34-37," + + "101.236.11.50-53"); System.out.println("app: " + app); boolean allow = app.allow("10.237.148.107"); + assertTrue(allow); allow = app.allow("10.237.148.134"); + assertTrue(allow); - allow = app.allow("172.25.102.2"); - allow = app.allow("172.25.102.254"); + allow = app.allow("172.25.102.1"); + assertTrue(allow); + allow = app.allow("172.25.102.255"); + assertTrue(allow); allow = app.allow("172.25.102.3"); + assertTrue(allow); allow = app.allow("172.25.102.251"); + assertTrue(allow); allow = app.allow("172.25.102.249"); + assertTrue(allow); allow = app.allow("172.25.102.138"); + assertTrue(allow); allow = app.allow("172.25.102.22"); + assertTrue(allow); allow = app.allow("172.25.104.136"); + assertTrue(allow); allow = app.allow("172.25.104.137"); + assertTrue(allow); allow = app.allow("172.25.104.138"); + assertTrue(allow); - assertTrue(allow); + allow = app.allow("101.236.11.34"); + assertTrue(allow); + allow = app.allow("101.236.11.35"); + assertTrue(allow); + allow = app.allow("101.236.11.36"); + assertTrue(allow); + allow = app.allow("101.236.11.37"); + assertTrue(allow); + + allow = app.allow("101.236.11.50"); + assertTrue(allow); + allow = app.allow("101.236.11.51"); + assertTrue(allow); + allow = app.allow("101.236.11.52"); + assertTrue(allow); + allow = app.allow("101.236.11.53"); + assertTrue(allow); } } diff --git a/fizz-plugin/pom.xml b/fizz-plugin/pom.xml index 034e277..c05b8d6 100644 --- a/fizz-plugin/pom.xml +++ b/fizz-plugin/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0 + 2.2.1 ../pom.xml 4.0.0 diff --git a/fizz-spring-boot-starter/pom.xml b/fizz-spring-boot-starter/pom.xml index 1f11bdd..600d841 100644 --- a/fizz-spring-boot-starter/pom.xml +++ b/fizz-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.2.0 + 2.2.1 ../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 4c21b68..a987c78 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ fizz-gateway-community ${project.artifactId} fizz gateway community - 2.2.0 + 2.2.1 pom fizz-common