From a05e1a2277c30bacf656dcf1ff9a5e9fc8f2097d Mon Sep 17 00:00:00 2001 From: linwaiwai Date: Thu, 19 Nov 2020 18:16:45 +0800 Subject: [PATCH 1/7] Create codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..63a127d --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '15 13 * * 4' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'java', 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From d5a24753557250481d12a73e74d11baa02c67d12 Mon Sep 17 00:00:00 2001 From: linwaiwai Date: Tue, 29 Jun 2021 17:50:09 +0800 Subject: [PATCH 2/7] add dynamic input support --- .gitignore | 1 + fizz-bootstrap/pom.xml | 8 +++- fizz-core/pom.xml | 14 +++++++ .../src/main/java/we/fizz/ConfigLoader.java | 19 +++------ fizz-core/src/main/java/we/fizz/Step.java | 1 + .../src/main/java/we/fizz/input/IInput.java | 1 + .../src/main/java/we/fizz/input/Input.java | 13 +++++++ .../main/java/we/fizz/input/InputFactory.java | 16 +++++++- .../input/extension/mysql/MySQLInput.java | 39 ------------------- .../extension/mysql/MySQLInputConfig.java | 35 ----------------- pom.xml | 3 ++ 11 files changed, 59 insertions(+), 91 deletions(-) delete mode 100644 fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInput.java delete mode 100644 fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInputConfig.java diff --git a/.gitignore b/.gitignore index 44e637c..17427be 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .factorypath .idea /fizz-gateway-community.iml +*.iml diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index 8db531c..a01fa2a 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -46,7 +46,13 @@ fizz-spring-boot-starter ${project.version} - + + + + + org.reflections + reflections + ${reflections.version} + + org.apache.curator curator-client @@ -279,5 +285,13 @@ repo file://${project.basedir}/../repo + + sonatype-snapshots + SonaType Snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + \ No newline at end of file diff --git a/fizz-core/src/main/java/we/fizz/ConfigLoader.java b/fizz-core/src/main/java/we/fizz/ConfigLoader.java index 632d6bd..86598ea 100644 --- a/fizz-core/src/main/java/we/fizz/ConfigLoader.java +++ b/fizz-core/src/main/java/we/fizz/ConfigLoader.java @@ -31,15 +31,10 @@ import org.apache.commons.io.FileUtils; import org.noear.snack.ONode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import we.fizz.input.extension.grpc.GrpcInput; -import we.fizz.input.extension.dubbo.DubboInput; -import we.fizz.input.extension.mysql.MySQLInput; -import we.fizz.input.extension.request.RequestInput; import we.flume.clients.log4j2appender.LogService; import we.util.Constants; import we.util.ReactorUtils; @@ -55,11 +50,7 @@ import java.io.IOException; import java.io.Serializable; import java.lang.ref.SoftReference; import java.nio.charset.StandardCharsets; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; /** @@ -147,10 +138,6 @@ public class ConfigLoader { public Pipeline createPipeline(String configStr) throws IOException { ONode cfgNode = ONode.loadStr(configStr); - InputFactory.registerInput(RequestInput.TYPE, RequestInput.class); - InputFactory.registerInput(MySQLInput.TYPE, MySQLInput.class); - InputFactory.registerInput(GrpcInput.TYPE, GrpcInput.class); - InputFactory.registerInput(DubboInput.TYPE, DubboInput.class); Pipeline pipeline = new Pipeline(); pipeline.setApplicationContext(appContext); @@ -213,8 +200,10 @@ public class ConfigLoader { @PostConstruct public synchronized void init() throws Exception { this.refreshLocalCache(); + InputFactory.loadInputClasses(); } + public synchronized void refreshLocalCache() throws Exception { if (formalPathPrefix == null) { formalPathPrefix = appContext.getEnvironment().getProperty("gateway.prefix", "/proxy"); @@ -372,6 +361,8 @@ public class ConfigLoader { } } String key = method.toUpperCase() + ":" + path; + // config file entry ,if you want modify the aggregate config json but not use the interface of fizz, + // you can just read the config ,transform to json format and modify it if (aggregateResources.containsKey(key) && aggregateResources.get(key) != null) { String configStr = aggregateResources.get(key); Input input = null; diff --git a/fizz-core/src/main/java/we/fizz/Step.java b/fizz-core/src/main/java/we/fizz/Step.java index 2a7e9e0..bb85c26 100644 --- a/fizz-core/src/main/java/we/fizz/Step.java +++ b/fizz-core/src/main/java/we/fizz/Step.java @@ -44,6 +44,7 @@ import we.fizz.component.IComponent; import we.fizz.component.StepContextPosition; import we.fizz.component.circle.Circle; import we.fizz.component.condition.Condition; +import we.fizz.exception.FizzRuntimeException; import we.fizz.input.Input; import we.fizz.input.InputConfig; import we.fizz.input.InputContext; diff --git a/fizz-core/src/main/java/we/fizz/input/IInput.java b/fizz-core/src/main/java/we/fizz/input/IInput.java index 5709c0f..5b02c74 100644 --- a/fizz-core/src/main/java/we/fizz/input/IInput.java +++ b/fizz-core/src/main/java/we/fizz/input/IInput.java @@ -7,6 +7,7 @@ import we.fizz.StepContext; import we.fizz.StepResponse; import java.lang.ref.SoftReference; +import java.lang.reflect.Field; import java.util.Map; public interface IInput { diff --git a/fizz-core/src/main/java/we/fizz/input/Input.java b/fizz-core/src/main/java/we/fizz/input/Input.java index a5c8ec1..f8e3952 100644 --- a/fizz-core/src/main/java/we/fizz/input/Input.java +++ b/fizz-core/src/main/java/we/fizz/input/Input.java @@ -17,8 +17,11 @@ package we.fizz.input; import java.lang.ref.SoftReference; +import java.lang.reflect.Field; import java.util.Map; + +import org.reflections.Reflections; import org.springframework.context.ConfigurableApplicationContext; import reactor.core.publisher.Mono; import we.fizz.Step; @@ -95,4 +98,14 @@ public class Input { return InputConfig.class; } + public static void initialize(Classclazz) throws IllegalAccessException { + Field field = null; + try { + field = clazz.getDeclaredField("TYPE"); + InputFactory.registerInput((InputType) field.get(null), clazz); + } catch (NoSuchFieldException e) { + // doing nothing is right + } + } + } diff --git a/fizz-core/src/main/java/we/fizz/input/InputFactory.java b/fizz-core/src/main/java/we/fizz/input/InputFactory.java index c0b611b..4a269b1 100644 --- a/fizz-core/src/main/java/we/fizz/input/InputFactory.java +++ b/fizz-core/src/main/java/we/fizz/input/InputFactory.java @@ -18,6 +18,7 @@ package we.fizz.input; import we.fizz.component.ComponentHelper; +import org.reflections.Reflections; import we.fizz.exception.FizzRuntimeException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -25,6 +26,7 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; /** * @@ -61,8 +63,9 @@ public class InputFactory { inputConfig.setComponents(ComponentHelper.buildComponents((List>) config.get("components"))); inputConfig.parse(); return inputConfig; + } else { + throw new FizzRuntimeException("can't find input config type:" + type); } - return null; } public static Input createInput(String type) { @@ -79,8 +82,17 @@ public class InputFactory { } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new FizzRuntimeException(e.getMessage()); } + } else { + throw new FizzRuntimeException("can't find input type:" + type); } - return null; } + public static void loadInputClasses() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Reflections reflections = new Reflections("we.fizz.input"); + Set> subTypes = reflections.getSubTypesOf(Input.class); + for (ClassinputType : subTypes){ + Method initializeMethod = inputType.getMethod("initialize", Class.class); + initializeMethod.invoke(null, inputType); + } + } } diff --git a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInput.java b/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInput.java deleted file mode 100644 index bb64ff8..0000000 --- a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInput.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 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.fizz.input.extension.mysql; - -import we.fizz.input.IInput; -import we.fizz.input.Input; -import we.fizz.input.InputType; - - - - - -/** - * - * @author linwaiwai - * - */ - -public class MySQLInput extends Input implements IInput { - static public InputType TYPE = new InputType("MYSQL"); - public static Class inputConfigClass (){ - return MySQLInputConfig.class; - } - -} diff --git a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInputConfig.java b/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInputConfig.java deleted file mode 100644 index 129a925..0000000 --- a/fizz-core/src/main/java/we/fizz/input/extension/mysql/MySQLInputConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2020 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.fizz.input.extension.mysql; - -import we.fizz.input.InputConfig; - -import java.util.Map; - -/** - * - * @author linwaiwai - * - */ -public class MySQLInputConfig extends InputConfig { - - public MySQLInputConfig(Map configBody) { - super(configBody); - } - -} diff --git a/pom.xml b/pom.xml index be1fb34..01afc1c 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,8 @@ 3.4.6 4.0.1 3.5.9 + 0.8.2 + 0.9.12 @@ -39,6 +41,7 @@ fizz-plugin fizz-spring-boot-starter + From 6483ff54c2f6db7681771d6c030ede4d4f83e4f1 Mon Sep 17 00:00:00 2001 From: linwaiwai Date: Fri, 9 Jul 2021 17:10:20 +0800 Subject: [PATCH 3/7] avoid compile error --- fizz-core/src/main/java/we/fizz/component/circle/Circle.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fizz-core/src/main/java/we/fizz/component/circle/Circle.java b/fizz-core/src/main/java/we/fizz/component/circle/Circle.java index 85e3e3b..3eec6db 100644 --- a/fizz-core/src/main/java/we/fizz/component/circle/Circle.java +++ b/fizz-core/src/main/java/we/fizz/component/circle/Circle.java @@ -225,7 +225,7 @@ public class Circle implements IComponent { ONode ctxNode = ComponentHelper.toONode(stepContext); CircleItem nextItem = this.next(ctxNode); if (nextItem != null) { - return Mono.just(new CircleItemResult(nextItem, null)).expand(circleItemResult -> { + Mono> colloctList = Mono.just(new CircleItemResult(nextItem, null)).expand(circleItemResult -> { // put nextItem to step context and ctxNode for further JSON path mapping CircleItem cItem = circleItemResult.nextItem; if (stepCtxPos.getRequestName() != null) { @@ -250,7 +250,8 @@ public class Circle implements IComponent { } return Mono.just(new CircleItemResult(nextItem2, r)); }); - }).flatMap(circleItemResult -> Flux.just(circleItemResult)).collectList().flatMap(list -> { + }).flatMap(circleItemResult -> Flux.just(circleItemResult)).collectList(); + return colloctList.flatMap(list -> { if (list != null && list.size() > 0) { Collections.reverse(list); for (int i = 0; i < list.size(); i++) { From 1f3ce167ce78157c61181746af421213b4f2c9a9 Mon Sep 17 00:00:00 2001 From: Francis Dong Date: Tue, 20 Jul 2021 14:34:38 +0800 Subject: [PATCH 4/7] Fix the issue that circle result is null when looping #252 --- fizz-core/src/main/java/we/fizz/component/circle/Circle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fizz-core/src/main/java/we/fizz/component/circle/Circle.java b/fizz-core/src/main/java/we/fizz/component/circle/Circle.java index db1be11..14b6c70 100644 --- a/fizz-core/src/main/java/we/fizz/component/circle/Circle.java +++ b/fizz-core/src/main/java/we/fizz/component/circle/Circle.java @@ -284,7 +284,7 @@ public class Circle implements IComponent { } return f.apply(stepContext, stepCtxPos).flatMap(r -> { ONode ctxNode2 = ComponentHelper.toONode(stepContext); - if (this.breakCircle(cItem.getIndex(), ctxNode, stepContext, stepCtxPos)) { + if (this.breakCircle(cItem.getIndex(), ctxNode2, stepContext, stepCtxPos)) { return Mono.empty(); } CircleItem nextItem2 = this.next(ctxNode2); From 82cf2fbb740eb9f95e949d044daca2b8c5b3badd Mon Sep 17 00:00:00 2001 From: linwaiwai Date: Wed, 21 Jul 2021 09:53:26 +0800 Subject: [PATCH 5/7] avoid compile issue --- .../main/java/we/fizz/component/circle/Circle.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fizz-core/src/main/java/we/fizz/component/circle/Circle.java b/fizz-core/src/main/java/we/fizz/component/circle/Circle.java index 988b800..7094439 100644 --- a/fizz-core/src/main/java/we/fizz/component/circle/Circle.java +++ b/fizz-core/src/main/java/we/fizz/component/circle/Circle.java @@ -266,8 +266,8 @@ public class Circle implements IComponent { ONode ctxNode1 = ComponentHelper.toONode(stepContext); CircleItem nextItem = this.next(ctxNode1); if (nextItem != null) { - Mono> colloctList = Mono.just(new CircleItemResult(nextItem, null)).expand(circleItemResult -> { - // put nextItem to step context and ctxNode for further JSON path mapping + return Mono.just(new CircleItemResult(ctxNode1, nextItem, null)).expand(circleItemResult -> { + // put nextItem to step context CircleItem cItem = circleItemResult.nextItem; if (stepCtxPos.getRequestName() != null) { stepContext.setRequestCircleItem(stepCtxPos.getStepName(), stepCtxPos.getRequestName(), @@ -278,13 +278,13 @@ public class Circle implements IComponent { ONode ctxNode = circleItemResult.ctxNode; PathMapping.setByPath(ctxNode, stepCtxPos.getPath() + ".item", cItem.getItem(), true); PathMapping.setByPath(ctxNode, stepCtxPos.getPath() + ".index", cItem.getIndex(), true); - + if (!this.canExec(cItem.getIndex(), ctxNode, stepContext, stepCtxPos)) { return Mono.just(new CircleItemResult(ctxNode, this.next(ctxNode), null)); } return f.apply(stepContext, stepCtxPos).flatMap(r -> { ONode ctxNode2 = ComponentHelper.toONode(stepContext); - if (this.breakCircle(cItem.getIndex(), ctxNode, stepContext, stepCtxPos)) { + if (this.breakCircle(cItem.getIndex(), ctxNode2, stepContext, stepCtxPos)) { return Mono.empty(); } CircleItem nextItem2 = this.next(ctxNode2); @@ -293,8 +293,8 @@ public class Circle implements IComponent { } return Mono.just(new CircleItemResult(ctxNode2, nextItem2, r)); }); - }).flatMap(circleItemResult -> Flux.just(circleItemResult)).collectList(); - return colloctList.flatMap(list -> { + }).flatMap(circleItemResult -> Flux.just(circleItemResult)).collectList().flatMap(r -> { + List list = (List) r; if (list != null && list.size() > 0) { Collections.reverse(list); for (int i = 0; i < list.size(); i++) { From 1444e0f4f9d02fb619ddb50d323d543df016c9e1 Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Tue, 27 Jul 2021 17:57:40 +0800 Subject: [PATCH 6/7] Merge master into develop (#259) --- README.en-us.md | 3 +- README.md | 3 +- fizz-bootstrap/pom.xml | 2 +- fizz-common/pom.xml | 2 +- .../src/main/java/we/util/TypeUtils.java | 65 +++++++++++ fizz-core/pom.xml | 2 +- .../input/extension/request/RequestInput.java | 22 +++- .../src/main/java/we/plugin/auth/App.java | 108 ++++++++++-------- .../test/java/we/plugin/auth/AppTests.java | 38 +++++- fizz-plugin/pom.xml | 2 +- fizz-spring-boot-starter/pom.xml | 2 +- pom.xml | 2 +- 12 files changed, 188 insertions(+), 63 deletions(-) create mode 100644 fizz-common/src/main/java/we/util/TypeUtils.java 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 From 2df9b586d1fceb8ddc11b5c792d13d6f4ac67d68 Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Tue, 27 Jul 2021 18:33:01 +0800 Subject: [PATCH 7/7] Upgrade slf4j netty commons-io dependencies #260 --- fizz-bootstrap/pom.xml | 4 ++-- pom.xml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index c9bc84e..d339393 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -20,10 +20,10 @@ Dragonfruit-SR3 Dysprosium-SR21 5.3.7.RELEASE - 4.1.65.Final + 4.1.66.Final 4.4.14 2.14.1 - 1.7.31 + 1.7.32 3.12.0 1.18.20 2.7.5 diff --git a/pom.xml b/pom.xml index a987c78..4434210 100644 --- a/pom.xml +++ b/pom.xml @@ -10,10 +10,10 @@ Dysprosium-SR21 5.3.7.RELEASE 2.2.5.RELEASE - 4.1.65.Final + 4.1.66.Final 4.4.14 2.14.1 - 1.7.31 + 1.7.32 2.7.5 1.16.1 3.4.6 @@ -188,7 +188,7 @@ commons-io commons-io - 2.8.0 + 2.11.0