From e8cf276fce4ffe6787857f821ae395abf4bfd729 Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Mon, 20 Feb 2023 18:18:15 +0800 Subject: [PATCH] Support request path end with or without / --- .../fizzgate/plugin/auth/ServiceConfig.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/fizz-core/src/main/java/com/fizzgate/plugin/auth/ServiceConfig.java b/fizz-core/src/main/java/com/fizzgate/plugin/auth/ServiceConfig.java index 292522e..1396879 100644 --- a/fizz-core/src/main/java/com/fizzgate/plugin/auth/ServiceConfig.java +++ b/fizz-core/src/main/java/com/fizzgate/plugin/auth/ServiceConfig.java @@ -18,6 +18,7 @@ package com.fizzgate.plugin.auth; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fizzgate.util.Consts; import com.fizzgate.util.ThreadContext; import com.fizzgate.util.UrlTransformUtils; @@ -124,18 +125,22 @@ public class ServiceConfig { } private void checkPathPattern(Map> pathPattern2apiConfigMap, boolean dedicatedLineRequest, String path, ArrayList result) { + String path0 = path; + if (!path.equals(Consts.S.FORWARD_SLASH_STR)) { + int lastCharPos = path.length() - 1; + char c = path.charAt(lastCharPos); + if (c == Consts.S.FORWARD_SLASH) { + path0 = path.substring(0, lastCharPos); + } else { + path0 = path + Consts.S.FORWARD_SLASH; + } + } Set>> entries = pathPattern2apiConfigMap.entrySet(); - // boolean clear = false; for (Map.Entry> entry : entries) { String pathPattern = entry.getKey(); Set apiConfigs = entry.getValue(); - if (pathPattern.equals(path)) { + if (pathPattern.equals(path) || pathPattern.equals(path0)) { for (ApiConfig ac : apiConfigs) { -// if (ac.allowAccess) { - /*if (!clear && !result.isEmpty()) { - result.clear(); - clear = true; - }*/ if (dedicatedLineRequest) { if (ac.dedicatedLine) { result.add(ac); @@ -145,14 +150,9 @@ public class ServiceConfig { result.add(ac); } } -// } } - /*if (clear && !result.isEmpty()) { - return; - }*/ - } else if (UrlTransformUtils.ANT_PATH_MATCHER.match(pathPattern, path)) { + } else if (UrlTransformUtils.ANT_PATH_MATCHER.match(pathPattern, path) || UrlTransformUtils.ANT_PATH_MATCHER.match(pathPattern, path0)) { for (ApiConfig ac : apiConfigs) { -// if (ac.allowAccess) { if (dedicatedLineRequest) { if (ac.dedicatedLine) { result.add(ac); @@ -162,9 +162,8 @@ public class ServiceConfig { result.add(ac); } } -// } } } - } // end for + } } }