Merge master into develop (#259)
This commit is contained in:
@@ -4,7 +4,7 @@ English | [简体中文](./README.md)
|
||||
<a href="https://www.fizzgate.com"><img src="https://raw.githubusercontent.com/wiki/wehotel/fizz-gateway-community/img/icon-color.png" width="70%"></a>
|
||||
</p>
|
||||
<p>
|
||||
<img alt="Version" src="https://img.shields.io/badge/version-2.2.0-blue.svg?cacheSeconds=2592000" />
|
||||
<img alt="Version" src="https://img.shields.io/badge/version-2.2.1-blue.svg?cacheSeconds=2592000" />
|
||||
<a href="http://www.fizzgate.com/fizz-gateway-community/" target="_blank">
|
||||
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
|
||||
</a>
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<a href="https://www.fizzgate.com"><img src="https://raw.githubusercontent.com/wiki/wehotel/fizz-gateway-community/img/icon-color.png" width="70%"></a>
|
||||
</p>
|
||||
<p>
|
||||
<img alt="Version" src="https://img.shields.io/badge/version-2.2.0-blue.svg?cacheSeconds=2592000" />
|
||||
<img alt="Version" src="https://img.shields.io/badge/version-2.2.1-blue.svg?cacheSeconds=2592000" />
|
||||
<a href="http://www.fizzgate.com/fizz-gateway-community/" target="_blank">
|
||||
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
|
||||
</a>
|
||||
@@ -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 |
|
||||
|
||||
请根据社区版的版本下载对应的管理后台版本
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<artifactId>fizz-bootstrap</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.1</version>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
65
fizz-common/src/main/java/we/util/TypeUtils.java
Normal file
65
fizz-common/src/main/java/we/util/TypeUtils.java
Normal file
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -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);
|
||||
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));
|
||||
@@ -378,9 +388,13 @@ public class RequestInput extends RPCInput implements IInput{
|
||||
body = BodyInserters.fromMultipartData(mpDataMap);
|
||||
} else if (CONTENT_TYPE_FORM_URLENCODED.equals(reqContentType)) {
|
||||
body = BodyInserters.fromFormData(MapUtil.toMultiValueMap((Map<String, Object>) request.get("body")));
|
||||
} else {
|
||||
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());
|
||||
String aggrPath = (String)inputContext.getStepContext().getInputReqAttr("path");
|
||||
|
||||
@@ -23,7 +23,6 @@ import we.util.Constants;
|
||||
import we.util.JacksonUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author hongqiaowei
|
||||
@@ -59,7 +58,7 @@ public class App {
|
||||
|
||||
public String config;
|
||||
|
||||
public Map<String, String[]> ips = new HashMap<>(8);
|
||||
public Map<String, List<String[]>> 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<String[]> 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<String, String[]> e : ips.entrySet()) {
|
||||
for (Map.Entry<String, List<String[]>> e : ips.entrySet()) {
|
||||
String subnet = e.getKey();
|
||||
int subnetLen = subnet.length();
|
||||
byte i = 0;
|
||||
@@ -113,7 +117,21 @@ public class App {
|
||||
}
|
||||
if (i == subnetLen) {
|
||||
int originAddrLen = ip.length() - originSubnetLen - 1;
|
||||
String[] addrSeg = e.getValue();
|
||||
boolean in = false;
|
||||
for (String[] addrSeg : e.getValue()) {
|
||||
in = inAddrSeg(ip, originSubnetLen, originAddrLen, addrSeg);
|
||||
if (in) {
|
||||
return in;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
@@ -149,10 +167,6 @@ public class App {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>fizz-gateway-community</artifactId>
|
||||
<groupId>com.fizzgate</groupId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.1</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
Reference in New Issue
Block a user