This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 6925f00e4d perf(sign): avoid formatting default module names (#7073)
6925f00e4d is described below

commit 6925f00e4d29e7469bd4211ad9fc99eaeb84e784
Author: Liming Deng <[email protected]>
AuthorDate: Thu Oct 1 06:30:55 2026 +0800

    perf(sign): avoid formatting default module names (#7073)
---
 .../plugin/sign/service/ComposableSignService.java | 27 ++++++++++------------
 .../sign/service/ComposableSignServiceTest.java    | 14 +++++++++++
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/service/ComposableSignService.java
 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/service/ComposableSignService.java
index 96abc1cbaa..1de1a1bbce 100644
--- 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/service/ComposableSignService.java
+++ 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/service/ComposableSignService.java
@@ -43,8 +43,6 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.server.ServerWebExchange;
 
 import java.time.LocalDateTime;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
@@ -79,13 +77,6 @@ public class ComposableSignService implements SignService {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(ComposableSignService.class);
 
-    /**
-     * Plugins whose module attribute is built as {@code pluginName + "-" + 
rpcType};
-     * for these the app name is taken from the request context path instead 
of the module.
-     */
-    private static final List<String> SKIP_SIGN_PLUGIN_NAMES = 
Collections.unmodifiableList(Arrays.asList(
-            PluginEnum.SPRING_CLOUD.getName(), PluginEnum.DIVIDE.getName(), 
PluginEnum.WEB_SOCKET.getName()));
-
     @Value("${shenyu.sign.delay:5}")
     private int delay;
 
@@ -240,13 +231,19 @@ public class ComposableSignService implements SignService 
{
     }
 
     private boolean skipSignExchange(final ShenyuContext context) {
-        final String module = context.getModule();
-        final String rpcType = context.getRpcType();
-        if (StringUtils.isAnyBlank(module, rpcType)) {
+        return matchesDefaultModule(context.getModule(), context.getRpcType(), 
PluginEnum.SPRING_CLOUD.getName())
+                || matchesDefaultModule(context.getModule(), 
context.getRpcType(), PluginEnum.DIVIDE.getName())
+                || matchesDefaultModule(context.getModule(), 
context.getRpcType(), PluginEnum.WEB_SOCKET.getName());
+    }
+
+    static boolean matchesDefaultModule(final String module, final String 
rpcType, final String pluginName) {
+        if (StringUtils.isBlank(module) || StringUtils.isBlank(rpcType)) {
             return false;
         }
-        final String rpcTypeSuffix = "-" + rpcType;
-        return module.endsWith(rpcTypeSuffix)
-                && SKIP_SIGN_PLUGIN_NAMES.contains(module.substring(0, 
module.length() - rpcTypeSuffix.length()));
+        int separatorIndex = pluginName.length();
+        return module.length() == separatorIndex + rpcType.length() + 1
+                && module.startsWith(pluginName)
+                && module.charAt(separatorIndex) == '-'
+                && module.regionMatches(separatorIndex + 1, rpcType, 0, 
rpcType.length());
     }
 }
diff --git 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/ComposableSignServiceTest.java
 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/ComposableSignServiceTest.java
index 8303df163a..9b6081d557 100644
--- 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/ComposableSignServiceTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/test/java/org/apache/shenyu/plugin/sign/service/ComposableSignServiceTest.java
@@ -77,5 +77,19 @@ public final class ComposableSignServiceTest {
         assertFalse(skipSignExchange("divide-", ""));
         assertFalse(skipSignExchange("", "http"));
         assertFalse(skipSignExchange("divide-springCloud-http", "http"));
+        assertFalse(skipSignExchange("divide-null", null));
+        assertFalse(skipSignExchange("divide- ", " "));
+    }
+
+    @Test
+    public void testMatchesDefaultModule() {
+        assertTrue(ComposableSignService.matchesDefaultModule("divide-http", 
"http", "divide"));
+        
assertTrue(ComposableSignService.matchesDefaultModule("springCloud-springCloud",
 "springCloud", "springCloud"));
+        assertFalse(ComposableSignService.matchesDefaultModule("divide-", "", 
"divide"));
+        assertFalse(ComposableSignService.matchesDefaultModule("divide-null", 
null, "divide"));
+        assertFalse(ComposableSignService.matchesDefaultModule("divide- ", " 
", "divide"));
+        assertFalse(ComposableSignService.matchesDefaultModule("divide-http", 
"dubbo", "divide"));
+        assertFalse(ComposableSignService.matchesDefaultModule("custom-http", 
"http", "divide"));
+        assertFalse(ComposableSignService.matchesDefaultModule(null, "http", 
"divide"));
     }
 }

Reply via email to