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 92c2197b1a websocket sync handshakes (#6386)
92c2197b1a is described below

commit 92c2197b1ab9451e0f0cf9a96e7534d908c7ba75
Author: aias00 <[email protected]>
AuthorDate: Thu Jul 23 00:08:14 2026 -0700

    websocket sync handshakes (#6386)
    
    * Require trusted bootstrap nodes for websocket sync
    
    WebSocket sync currently exposes the full bootstrap data stream after an 
anonymous upgrade, including APP_AUTH records needed by gateway bootstrap. This 
change keeps the sync payload shape intact and moves the trust decision to the 
handshake by requiring a shared sync token from bootstrap clients.
    
    Admin validates the X-Shenyu-Sync-Token header before copying session 
attributes into the endpoint context. Bootstrap clients read the same token 
from shenyu.sync.websocket.token and send it with each WebSocket connection. 
The token is masked from WebsocketConfig.toString() so operational logging does 
not reveal the secret.
    
    Constraint: APP_AUTH.appSecret must remain in sync payloads because 
bootstrap sign-plugin behavior depends on it
    
    Rejected: Remove appSecret from APP_AUTH sync data | breaks bootstrap 
consumers that need the secret to verify signed requests
    
    Rejected: Require admin-user JWT on websocket upgrade | couples bootstrap 
nodes to user login/session token lifecycle
    
    Confidence: high
    
    Scope-risk: moderate
    
    Directive: Do not remove /websocket from the Shiro whitelist unless 
bootstrap has a non-user auth path through that filter
    
    Tested: ./mvnw -pl 
shenyu-admin,shenyu-sync-data-center/shenyu-sync-data-websocket -am 
-DfailIfNoTests=false -Dskip.checkstyle=true -DskipLicense=true 
-Dspotless.check.skip=true -Djacoco.skip=true 
-Dtest=WebsocketConfiguratorTest,WebsocketSyncPropertiesTest,WebsocketConfigTest
 test
    
    Tested: ./mvnw -pl 
shenyu-admin,shenyu-sync-data-center/shenyu-sync-data-websocket -am -DskipTests 
-DfailIfNoTests=false -DskipLicense=true -Dspotless.check.skip=true 
-Djacoco.skip=true package
    
    Tested: git diff --check
    
    Not-tested: End-to-end admin/bootstrap websocket connection with a live 
shared token
    
    * Keep websocket sync auth usable in test runtimes
    
    Websocket endpoint configurators can be created by the JSR-356 container 
outside Spring autowiring, so handshake auth now resolves sync properties 
through the same SpringBeanUtils fallback already used by origin checks. The 
test and e2e runtimes also configure the same sync token on both admin and 
bootstrap sides so the new mandatory handshake token does not break CI 
scenarios.
    
    Constraint: WebSocket handshake configurator instances are not guaranteed 
to be Spring-autowired.
    
    Constraint: The token is mandatory when websocket sync is enabled, so test 
runtimes must configure both admin and bootstrap.
    
    Rejected: Make admin accept blank tokens in test runtimes | would weaken 
the security behavior being added by the PR.
    
    Confidence: high
    
    Scope-risk: moderate
    
    Directive: Keep admin and bootstrap websocket sync token values paired in 
compose, k8s, and local integration-test resources.
    
    Tested: ./mvnw -pl 
shenyu-admin,shenyu-sync-data-center/shenyu-sync-data-websocket -am 
-DfailIfNoTests=false -Dskip.checkstyle=true -DskipLicense=true 
-Dspotless.check.skip=true -Djacoco.skip=true 
-Dtest=WebsocketConfiguratorTest,WebsocketConfigTest test
    
    Tested: ../mvnw -pl shenyu-integrated-test-sdk-http -am -DskipTests 
-DfailIfNoTests=false -Dskip.checkstyle=true -DskipLicense=true 
-Dspotless.check.skip=true -Djacoco.skip=true package (from 
shenyu-integrated-test/)
    
    Tested: docker compose config for shenyu-integrated-test-sdk-http and 
shenyu-sync-websocket compose files
    
    Tested: ruby YAML parse for representative e2e k8s config files
    
    Tested: git diff --check
    
    Not-tested: Full Docker e2e/IT containers locally
    
    ---------
    
    Co-authored-by: xiaoyu <[email protected]>
    Co-authored-by: moremind <[email protected]>
---
 .../config/properties/WebsocketSyncProperties.java | 23 +++++++
 .../listener/websocket/WebsocketConfigurator.java  | 48 ++++++++++++-
 shenyu-admin/src/main/resources/application.yml    |  1 +
 .../properties/WebsocketSyncPropertiesTest.java    |  2 +
 .../websocket/WebsocketConfiguratorTest.java       | 61 +++++++++++++++++
 .../src/main/resources/application.yml             |  1 +
 .../apache/shenyu/common/constant/Constants.java   |  5 ++
 .../compose/storage/shenyu-storage-h2.yml          |  2 +
 .../compose/storage/shenyu-storage-mysql.yml       |  2 +
 .../compose/storage/shenyu-storage-opengauss.yml   |  2 +
 .../compose/storage/shenyu-storage-postgres.yml    |  2 +
 .../sync/shenyu-sync-websocket-cluster-jdbc.yml    |  3 +
 .../shenyu-sync-websocket-cluster-zookeeper.yml    |  3 +
 .../compose/sync/shenyu-sync-websocket-eureka.yml  |  2 +
 .../compose/sync/shenyu-sync-websocket.yml         |  2 +
 shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml  |  2 +
 .../docker-compose.yml                             |  2 +
 .../k8s/shenyu-cluster-jdbc.yml                    |  6 ++
 .../k8s/shenyu-cluster-zookeeper.yml               |  6 ++
 .../shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml |  2 +
 .../k8s/shenyu-deployment-h2.yml                   |  2 +
 .../k8s/shenyu-deployment-mysql.yml                |  2 +
 .../k8s/shenyu-deployment-opengauss.yml            |  2 +
 .../k8s/shenyu-deployment-postgres.yml             |  2 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application-local.yml       |  1 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application-local.yml       |  1 +
 .../shenyu-integrated-test-grpc/docker-compose.yml |  2 +
 .../src/main/resources/application-local.yml       |  1 +
 .../shenyu-integrated-test-http/docker-compose.yml |  2 +
 .../src/main/resources/application.yml             |  1 +
 .../docker-compose.yml                             |  1 +
 .../src/main/resources/application.yml             |  1 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application-local.yml       |  1 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application.yml             |  1 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application.yml             |  1 +
 .../shenyu-integrated-test-sofa/docker-compose.yml |  2 +
 .../src/main/resources/application-local.yml       |  1 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application-local.yml       |  1 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application.yaml            |  1 +
 .../docker-compose.yml                             |  2 +
 .../src/main/resources/application-local.yml       |  1 +
 .../data/websocket/WebsocketSyncDataService.java   | 80 +++++++---------------
 .../data/websocket/config/WebsocketConfig.java     | 29 +++++++-
 .../data/websocket/config/WebsocketConfigTest.java | 11 ++-
 51 files changed, 279 insertions(+), 61 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java
index e5b41302ed..4dc730ddbd 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/WebsocketSyncProperties.java
@@ -40,6 +40,11 @@ public class WebsocketSyncProperties {
      */
     private String allowOrigins;
 
+    /**
+     * WebSocket sync token.
+     */
+    private String token;
+
     /**
      * Gets the value of enabled.
      *
@@ -91,4 +96,22 @@ public class WebsocketSyncProperties {
     public void setAllowOrigins(final String allowOrigins) {
         this.allowOrigins = allowOrigins;
     }
+
+    /**
+     * get token.
+     *
+     * @return token
+     */
+    public String getToken() {
+        return token;
+    }
+
+    /**
+     * set token.
+     *
+     * @param token token
+     */
+    public void setToken(final String token) {
+        this.token = token;
+    }
 }
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java
index 2c020d6a4d..3dc33711da 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfigurator.java
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.admin.config.properties.WebsocketSyncProperties;
 import org.apache.shenyu.admin.spring.SpringBeanUtils;
 import org.apache.shenyu.common.constant.Constants;
+import org.apache.shenyu.common.exception.ShenyuException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +34,13 @@ import 
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.boot.web.servlet.ServletContextInitializer;
 import org.springframework.context.annotation.Configuration;
 
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
 import static 
org.apache.tomcat.websocket.server.Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM;
 import static 
org.apache.tomcat.websocket.server.Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM;
 
@@ -52,6 +60,7 @@ public class WebsocketConfigurator extends 
ServerEndpointConfig.Configurator imp
 
     @Override
     public void modifyHandshake(final ServerEndpointConfig sec, final 
HandshakeRequest request, final HandshakeResponse response) {
+        checkSyncToken(request);
         HttpSession httpSession = (HttpSession) request.getHttpSession();
         sec.getUserProperties().put(WebsocketListener.CLIENT_IP_NAME, 
httpSession.getAttribute(WebsocketListener.CLIENT_IP_NAME));
         sec.getUserProperties().put(Constants.CLIENT_PORT_NAME, 
httpSession.getAttribute(Constants.CLIENT_PORT_NAME));
@@ -61,7 +70,7 @@ public class WebsocketConfigurator extends 
ServerEndpointConfig.Configurator imp
 
     @Override
     public boolean checkOrigin(final String originHeaderValue) {
-        final WebsocketSyncProperties bean = 
SpringBeanUtils.getInstance().getBean(WebsocketSyncProperties.class);
+        final WebsocketSyncProperties bean = getWebsocketSyncProperties();
         if (StringUtils.isNotEmpty(bean.getAllowOrigins())) {
             String[] split = StringUtils.split(bean.getAllowOrigins(), ";");
             for (String configAllow : split) {
@@ -77,7 +86,7 @@ public class WebsocketConfigurator extends 
ServerEndpointConfig.Configurator imp
 
     @Override
     public void onStartup(final ServletContext servletContext) {
-        int messageMaxSize = websocketSyncProperties.getMessageMaxSize();
+        int messageMaxSize = getWebsocketSyncProperties().getMessageMaxSize();
         if (messageMaxSize > 0) {
             
servletContext.setInitParameter(TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM,
                     String.valueOf(messageMaxSize));
@@ -85,4 +94,39 @@ public class WebsocketConfigurator extends 
ServerEndpointConfig.Configurator imp
                     String.valueOf(messageMaxSize));
         }
     }
+
+    private void checkSyncToken(final HandshakeRequest request) {
+        String configuredToken = getWebsocketSyncProperties().getToken();
+        if (StringUtils.isBlank(configuredToken)) {
+            throw new ShenyuException("websocket sync token is not 
configured");
+        }
+        String requestToken = getHeader(request.getHeaders(), 
Constants.X_SHENYU_SYNC_TOKEN);
+        if (StringUtils.isBlank(requestToken) || !isSameToken(configuredToken, 
requestToken)) {
+            throw new ShenyuException("websocket sync token is invalid");
+        }
+    }
+
+    private WebsocketSyncProperties getWebsocketSyncProperties() {
+        return Optional.ofNullable(websocketSyncProperties)
+                .orElseGet(() -> 
SpringBeanUtils.getInstance().getBean(WebsocketSyncProperties.class));
+    }
+
+    private boolean isSameToken(final String configuredToken, final String 
requestToken) {
+        return MessageDigest.isEqual(
+                configuredToken.getBytes(StandardCharsets.UTF_8),
+                requestToken.getBytes(StandardCharsets.UTF_8));
+    }
+
+    private String getHeader(final Map<String, List<String>> headers, final 
String name) {
+        return Optional.ofNullable(headers)
+                .orElse(Collections.emptyMap())
+                .entrySet()
+                .stream()
+                .filter(entry -> StringUtils.equalsIgnoreCase(entry.getKey(), 
name))
+                .map(Map.Entry::getValue)
+                .filter(values -> !values.isEmpty())
+                .map(values -> values.get(0))
+                .findFirst()
+                .orElse(null);
+    }
 }
diff --git a/shenyu-admin/src/main/resources/application.yml 
b/shenyu-admin/src/main/resources/application.yml
index ecd6f4e077..068e23f698 100755
--- a/shenyu-admin/src/main/resources/application.yml
+++ b/shenyu-admin/src/main/resources/application.yml
@@ -70,6 +70,7 @@ shenyu:
     websocket:
       enabled: true
       messageMaxSize: 10240
+      token: ${SHENYU_SYNC_WEBSOCKET_TOKEN:}
       allowOrigins: ws://localhost:9095;ws://localhost:9195;
 #    apollo:
 #      meta: http://localhost:8080
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java
index 14abcceaa1..e6b7f844b6 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/config/properties/WebsocketSyncPropertiesTest.java
@@ -43,9 +43,11 @@ public final class WebsocketSyncPropertiesTest extends 
AbstractConfigurationTest
         WebsocketSyncProperties websocketSyncProperties = 
getContext().getBean(WebsocketSyncProperties.class);
         websocketSyncProperties.setMessageMaxSize(0);
         websocketSyncProperties.setAllowOrigins("allowOrigins");
+        websocketSyncProperties.setToken("token");
         assertThat(websocketSyncProperties.isEnabled(), 
comparesEqualTo(false));
         Assertions.assertEquals(websocketSyncProperties.getMessageMaxSize(), 
0);
         Assertions.assertEquals(websocketSyncProperties.getAllowOrigins(), 
"allowOrigins");
+        Assertions.assertEquals(websocketSyncProperties.getToken(), "token");
     }
 
     @Configuration
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java
index c802651e61..ddcc7262ab 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketConfiguratorTest.java
@@ -25,18 +25,22 @@ import jakarta.websocket.server.ServerEndpointConfig;
 import org.apache.shenyu.admin.config.properties.WebsocketSyncProperties;
 import org.apache.shenyu.admin.spring.SpringBeanUtils;
 import org.apache.shenyu.common.constant.Constants;
+import org.apache.shenyu.common.exception.ShenyuException;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.ApplicationContext;
 import org.springframework.test.util.ReflectionTestUtils;
 
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import static 
org.apache.tomcat.websocket.server.Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM;
 import static 
org.apache.tomcat.websocket.server.Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -64,11 +68,13 @@ public class WebsocketConfiguratorTest {
 
     @Test
     void testModifyHandshake() {
+        websocketSyncProperties.setToken("websocket-sync-token");
         ServerEndpointConfig sec = mock(ServerEndpointConfig.class);
         Map<String, Object> userProperties = new HashMap<>();
         when(sec.getUserProperties()).thenReturn(userProperties);
 
         HandshakeRequest request = mock(HandshakeRequest.class);
+        
when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN,
 List.of("websocket-sync-token")));
         HttpSession httpSession = mock(HttpSession.class);
         when(request.getHttpSession()).thenReturn(httpSession);
         
when(httpSession.getAttribute(WebsocketListener.CLIENT_IP_NAME)).thenReturn("192.168.1.1");
@@ -85,11 +91,13 @@ public class WebsocketConfiguratorTest {
 
     @Test
     void testModifyHandshakePutsAllAttributes() {
+        websocketSyncProperties.setToken("websocket-sync-token");
         ServerEndpointConfig sec = mock(ServerEndpointConfig.class);
         Map<String, Object> userProperties = new HashMap<>();
         when(sec.getUserProperties()).thenReturn(userProperties);
 
         HandshakeRequest request = mock(HandshakeRequest.class);
+        
when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN,
 List.of("websocket-sync-token")));
         HttpSession httpSession = mock(HttpSession.class);
         when(request.getHttpSession()).thenReturn(httpSession);
 
@@ -104,6 +112,59 @@ public class WebsocketConfiguratorTest {
         assertTrue(userProperties.containsKey(Constants.SHENYU_NAMESPACE_ID));
     }
 
+    @Test
+    void testModifyHandshakeUsesSpringBeanWhenConfiguratorIsNotAutowired() {
+        websocketSyncProperties.setToken("websocket-sync-token");
+        ReflectionTestUtils.setField(websocketConfigurator, 
"websocketSyncProperties", null);
+        ServerEndpointConfig sec = mock(ServerEndpointConfig.class);
+        Map<String, Object> userProperties = new HashMap<>();
+        when(sec.getUserProperties()).thenReturn(userProperties);
+
+        HandshakeRequest request = mock(HandshakeRequest.class);
+        
when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN,
 List.of("websocket-sync-token")));
+        when(request.getHttpSession()).thenReturn(mock(HttpSession.class));
+
+        HandshakeResponse response = mock(HandshakeResponse.class);
+        websocketConfigurator.modifyHandshake(sec, request, response);
+
+        
assertTrue(userProperties.containsKey(WebsocketListener.CLIENT_IP_NAME));
+        assertTrue(userProperties.containsKey(Constants.CLIENT_PORT_NAME));
+        assertTrue(userProperties.containsKey(Constants.SHENYU_NAMESPACE_ID));
+    }
+
+    @Test
+    void testModifyHandshakeRejectsMissingToken() {
+        websocketSyncProperties.setToken("websocket-sync-token");
+        ServerEndpointConfig sec = mock(ServerEndpointConfig.class);
+        HandshakeRequest request = mock(HandshakeRequest.class);
+        when(request.getHeaders()).thenReturn(Collections.emptyMap());
+        HandshakeResponse response = mock(HandshakeResponse.class);
+
+        assertThrows(ShenyuException.class, () -> 
websocketConfigurator.modifyHandshake(sec, request, response));
+    }
+
+    @Test
+    void testModifyHandshakeRejectsInvalidToken() {
+        websocketSyncProperties.setToken("websocket-sync-token");
+        ServerEndpointConfig sec = mock(ServerEndpointConfig.class);
+        HandshakeRequest request = mock(HandshakeRequest.class);
+        
when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN,
 List.of("invalid-token")));
+        HandshakeResponse response = mock(HandshakeResponse.class);
+
+        assertThrows(ShenyuException.class, () -> 
websocketConfigurator.modifyHandshake(sec, request, response));
+    }
+
+    @Test
+    void testModifyHandshakeRejectsBlankConfiguredToken() {
+        websocketSyncProperties.setToken("");
+        ServerEndpointConfig sec = mock(ServerEndpointConfig.class);
+        HandshakeRequest request = mock(HandshakeRequest.class);
+        
when(request.getHeaders()).thenReturn(Collections.singletonMap(Constants.X_SHENYU_SYNC_TOKEN,
 List.of("websocket-sync-token")));
+        HandshakeResponse response = mock(HandshakeResponse.class);
+
+        assertThrows(ShenyuException.class, () -> 
websocketConfigurator.modifyHandshake(sec, request, response));
+    }
+
     @Test
     void testCheckOriginAllowedWhenAllowOriginsEmpty() {
         websocketSyncProperties.setAllowOrigins("");
diff --git a/shenyu-bootstrap/src/main/resources/application.yml 
b/shenyu-bootstrap/src/main/resources/application.yml
index 9272726f69..4c1df632a4 100644
--- a/shenyu-bootstrap/src/main/resources/application.yml
+++ b/shenyu-bootstrap/src/main/resources/application.yml
@@ -223,6 +223,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: ${SHENYU_SYNC_WEBSOCKET_TOKEN:}
       allowOrigin: ws://localhost:9195
 #    apollo:
 #      appId: shenyu
diff --git 
a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java 
b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
index 5295c8552b..c852bfe5a9 100644
--- 
a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
+++ 
b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java
@@ -713,6 +713,11 @@ public interface Constants {
      */
     String X_ACCESS_TOKEN = "X-Access-Token";
 
+    /**
+     * X-Shenyu-Sync-Token.
+     */
+    String X_SHENYU_SYNC_TOKEN = "X-Shenyu-Sync-Token";
+
     /**
      * X-API-KEY; AI proxy key header.
      */
diff --git a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml 
b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml
index 463820317e..a54b97b9d0 100644
--- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml
+++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-h2.yml
@@ -31,6 +31,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -51,6 +52,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ]
diff --git 
a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml 
b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml
index 6f797f2530..e909e9dce4 100644
--- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml
+++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-mysql.yml
@@ -63,6 +63,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -86,6 +87,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ]
diff --git 
a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml 
b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml
index 9859e92fb1..4407a85e5c 100644
--- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml
+++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-opengauss.yml
@@ -62,6 +62,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/opengauss/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -85,6 +86,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ]
diff --git 
a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml 
b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml
index 956e07258d..884e36b6fb 100644
--- a/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml
+++ b/shenyu-e2e/shenyu-e2e-case/compose/storage/shenyu-storage-postgres.yml
@@ -62,6 +62,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/postgres/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -85,6 +86,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ]
diff --git 
a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml
 
b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml
index e80b56f6b5..5060180345 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-jdbc.yml
@@ -64,6 +64,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -96,6 +97,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -119,6 +121,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - 
shenyu.sync.websocket.urls=ws://shenyu-admin-1:9095/websocket,ws://shenyu-admin-2:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ]
diff --git 
a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml
 
b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml
index 438371f8ad..d73aeb9e5e 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-cluster-zookeeper.yml
@@ -83,6 +83,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -119,6 +120,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -144,6 +146,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - 
shenyu.sync.websocket.urls=ws://shenyu-admin-1:9095/websocket,ws://shenyu-admin-2:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ]
diff --git 
a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml 
b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml
index f2e00ac65f..44a15873ed 100644
--- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml
+++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket-eureka.yml
@@ -63,6 +63,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -86,6 +87,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
       - spring.cloud.discovery.enabled=true
       - eureka.client.enabled=true
diff --git a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml 
b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml
index 6982c110f7..1da2a18e7e 100644
--- a/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml
+++ b/shenyu-e2e/shenyu-e2e-case/compose/sync/shenyu-sync-websocket.yml
@@ -63,6 +63,7 @@ services:
       - shenyu.sync.websocket.enabled=true
       - shenyu.sync.websocket.messageMaxSize=10240
       - 
shenyu.sync.websocket.allowOrigins=ws://localhost:9095;ws://localhost:9195;
+      - shenyu.sync.websocket.token=shenyu-sync-token
     volumes:
       - /tmp/shenyu-e2e/mysql/driver:/opt/shenyu-admin/ext-lib
     healthcheck:
@@ -86,6 +87,7 @@ services:
     environment:
       - TZ=Asia/Beijing
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.sync.websocket.allowOrigin=ws://localhost:9195
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-bootstrap:9195/actuator/health | grep UP || exit 1" ]
diff --git a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml 
b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml
index 69c469256e..275a4d2824 100644
--- a/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml
+++ b/shenyu-e2e/shenyu-e2e-case/k8s/sync/shenyu-cm.yml
@@ -480,6 +480,7 @@ data:
           enabled: true
           messageMaxSize: 10240
           allowOrigins: ws://localhost:9095;ws://localhost:9195;
+          token: shenyu-sync-token
 
   application-admin-sync-http.yml: |
     shenyu:
@@ -521,6 +522,7 @@ data:
       sync:
         websocket:
           urls: ws://shenyu-admin:9095/websocket
+          token: shenyu-sync-token
           allowOrigin: ws://localhost:9195
 
   application-bootstrap-sync-http.yml: |
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml
index 125b3c7a04..b6dbb438b1 100644
--- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml
+++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-apache-dubbo/docker-compose.yml
@@ -26,6 +26,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -68,6 +69,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml
 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml
index 25e3468fdf..fd74744516 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-jdbc.yml
@@ -47,6 +47,8 @@ spec:
               value: "true"
             - name: shenyu.sync.websocket.allowOrigins
               value: ws://localhost:9095;ws://localhost:9195;
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
             - name: spring.datasource.username
               value: root
             - name: spring.datasource.password
@@ -116,6 +118,8 @@ spec:
               value: "true"
             - name: shenyu.sync.websocket.allowOrigins
               value: ws://localhost:9096;ws://localhost:9195;
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
             - name: spring.datasource.username
               value: root
             - name: spring.datasource.password
@@ -178,6 +182,8 @@ spec:
           env:
             - name: shenyu.sync.websocket.urls
               value: 
ws://shenyu-admin-master:9095/websocket,ws://shenyu-admin-slave:9096/websocket
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
           ports:
             - containerPort: 9195
           livenessProbe:
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml
 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml
index bb7f4a4510..0184341755 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-cluster/k8s/shenyu-cluster-zookeeper.yml
@@ -46,6 +46,8 @@ spec:
               value: "true"
             - name: shenyu.sync.websocket.allowOrigins
               value: ws://localhost:9095;ws://localhost:9195;
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
             - name: shenyu.cluster.type
               value: "zookeeper"
             - name: shenyu.cluster.zookeeper.url
@@ -119,6 +121,8 @@ spec:
               value: "true"
             - name: shenyu.sync.websocket.allowOrigins
               value: ws://localhost:9096;ws://localhost:9195;
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
             - name: shenyu.cluster.type
               value: "zookeeper"
             - name: shenyu.cluster.zookeeper.url
@@ -185,6 +189,8 @@ spec:
           env:
             - name: shenyu.sync.websocket.urls
               value: 
ws://shenyu-admin-master:9095/websocket,ws://shenyu-admin-slave:9096/websocket
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
           ports:
             - containerPort: 9195
           livenessProbe:
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml
index 4211981aa2..9cde385a08 100644
--- a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml
+++ b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-spring-cloud/k8s/shenyu-cm.yml
@@ -448,6 +448,7 @@ data:
           enabled: true
           messageMaxSize: 10240
           allowOrigins: ws://localhost:9095;ws://localhost:9195;
+          token: shenyu-sync-token
 
   application-admin-sync-http.yml: |
     shenyu:
@@ -489,6 +490,7 @@ data:
       sync:
         websocket:
           urls: ws://shenyu-admin:9095/websocket
+          token: shenyu-sync-token
           allowOrigin: ws://localhost:9195
 
   application-bootstrap-sync-http.yml: |
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml
 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml
index 9791bd1c0e..bc1d163efc 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-h2.yml
@@ -97,6 +97,8 @@ spec:
           env:
             - name: shenyu.sync.websocket.urls
               value: ws://shenyu-admin-h2:9095/websocket
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
           ports:
             - containerPort: 9195
           imagePullPolicy: IfNotPresent
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml
 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml
index 57f64e8286..034a18931f 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-mysql.yml
@@ -102,6 +102,8 @@ spec:
           env:
             - name: shenyu.sync.websocket.urls
               value: ws://shenyu-admin-mysql:9095/websocket
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
           ports:
             - containerPort: 9195
           livenessProbe:
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml
 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml
index 3c2b9371a2..c50d64c71a 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-opengauss.yml
@@ -99,6 +99,8 @@ spec:
           env:
             - name: shenyu.sync.websocket.urls
               value: ws://shenyu-admin-opengauss:9095/websocket
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
           ports:
             - containerPort: 9195
           livenessProbe:
diff --git 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml
 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml
index b168085d0c..f5dbf68428 100644
--- 
a/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml
+++ 
b/shenyu-e2e/shenyu-e2e-case/shenyu-e2e-case-storage/k8s/shenyu-deployment-postgres.yml
@@ -99,6 +99,8 @@ spec:
           env:
             - name: shenyu.sync.websocket.urls
               value: ws://shenyu-admin-postgres:9095/websocket
+            - name: shenyu.sync.websocket.token
+              value: shenyu-sync-token
           ports:
             - containerPort: 9195
           livenessProbe:
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml
index f4f32f1a37..76a0a32c6a 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/docker-compose.yml
@@ -34,6 +34,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -76,6 +77,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml
index 8c41677851..5f4df44ced 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-apache-dubbo/src/main/resources/application-local.yml
@@ -36,6 +36,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml
index 0e55c199a9..fb4b4a8ea0 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-combination/docker-compose.yml
@@ -150,6 +150,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -166,6 +167,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-zk:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml
index 8c41677851..5f4df44ced 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-combination/src/main/resources/application-local.yml
@@ -36,6 +36,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml
index aee2e037ff..01b4bf18c4 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-grpc/docker-compose.yml
@@ -25,6 +25,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -66,6 +67,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml
index 945b939961..a479f34dfd 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-grpc/src/main/resources/application-local.yml
@@ -52,6 +52,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
index 7faa567123..0e001d67c2 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-http/docker-compose.yml
@@ -66,6 +66,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -82,6 +83,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml
index a31615a329..a7fbeb0ac8 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-http/src/main/resources/application.yml
@@ -52,6 +52,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   #    zookeeper:
   #      url: localhost:2181
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml
index 8da015aecd..1950b8bbc0 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-https/docker-compose.yml
@@ -25,6 +25,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ]
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml
index cfb3f24bfc..3b1695efa5 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-https/src/main/resources/application.yml
@@ -45,6 +45,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml
index 02394a5fb8..e2591f3cab 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-rewrite/docker-compose.yml
@@ -100,6 +100,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -116,6 +117,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-zk:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml
index 8c41677851..5f4df44ced 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-rewrite/src/main/resources/application-local.yml
@@ -36,6 +36,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml
index bcb1ce255e..962fde2187 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/docker-compose.yml
@@ -34,6 +34,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -93,6 +94,7 @@ services:
     environment:
       - dubbo.registry.address=zookeeper://shenyu-zk:2181
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml
index 031a7d8eef..225d1793b8 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-sdk-apache-dubbo/src/main/resources/application.yml
@@ -92,6 +92,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml
index 45ea7d2639..3e71791833 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/docker-compose.yml
@@ -37,6 +37,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -103,6 +104,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.register.registerType=zookeeper
       - shenyu.register.serverLists=shenyu-zk:2181
     depends_on:
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml
index ea8e73bba6..27100bbc12 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-sdk-http/src/main/resources/application.yml
@@ -92,6 +92,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml
index f8b736a07b..3dfffdc35d 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-sofa/docker-compose.yml
@@ -37,6 +37,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -79,6 +80,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml
index c74a79c76d..e7c33aa98b 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-sofa/src/main/resources/application-local.yml
@@ -36,6 +36,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://shenyu-admin:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml
index 6259f995f2..d79e1f852c 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/docker-compose.yml
@@ -25,6 +25,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ]
@@ -87,6 +88,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - 
eureka.client.serviceUrl.defaultZone=http://shenyu-examples-eureka:8761/eureka/
     depends_on:
       shenyu-admin:
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml
index 342277a654..9344bbc56b 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-spring-cloud/src/main/resources/application-local.yml
@@ -48,6 +48,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml
index 5f44f3dd1b..2280adb313 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/docker-compose.yml
@@ -25,6 +25,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: [ "CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1" ]
@@ -42,6 +43,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml
 
b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml
index 27963a3764..2dbd831028 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-upload-plugin/shenyu-integrated-test-upload-plugin-case/src/main/resources/application.yaml
@@ -36,6 +36,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://localhost:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml 
b/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml
index d3468dee0e..6f1585d2cd 100644
--- a/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml
+++ b/shenyu-integrated-test/shenyu-integrated-test-websocket/docker-compose.yml
@@ -26,6 +26,7 @@ services:
       - "9095:9095"
     environment:
       - SPRING_PROFILES_ACTIVE=h2
+      - shenyu.sync.websocket.token=shenyu-sync-token
       - shenyu.database.init_script=sql-script/h2/schema.sql
     healthcheck:
       test: ["CMD-SHELL", "wget -q -O - 
http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
@@ -67,6 +68,7 @@ services:
           memory: 2048M
     environment:
       - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+      - shenyu.sync.websocket.token=shenyu-sync-token
     depends_on:
       shenyu-admin:
         condition: service_healthy
diff --git 
a/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml
 
b/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml
index d61c6fe3e9..b3f60e7348 100644
--- 
a/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml
+++ 
b/shenyu-integrated-test/shenyu-integrated-test-websocket/src/main/resources/application-local.yml
@@ -36,6 +36,7 @@ shenyu:
   sync:
     websocket:
       urls: ws://shenyu-admin:9095/websocket
+      token: shenyu-sync-token
       allowOrigin: ws://localhost:9195
   exclude:
     enabled: true
diff --git 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java
 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java
index 4afa7de319..c85fa83a35 100644
--- 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java
+++ 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/WebsocketSyncDataService.java
@@ -17,12 +17,12 @@
 
 package org.apache.shenyu.plugin.sync.data.websocket;
 
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.common.config.ShenyuConfig;
+import org.apache.shenyu.common.constant.Constants;
 import org.apache.shenyu.common.enums.RunningModeEnum;
 import org.apache.shenyu.common.timer.AbstractRoundTask;
 import org.apache.shenyu.common.timer.Timer;
@@ -41,6 +41,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.boot.autoconfigure.web.ServerProperties;
 
 import java.net.URI;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -119,34 +120,7 @@ public class WebsocketSyncDataService implements 
SyncDataService {
         LOG.info("start init connecting...");
         List<String> urls = websocketConfig.getUrls();
         for (String url : urls) {
-            if (StringUtils.isNotEmpty(websocketConfig.getAllowOrigin())) {
-                Map<String, String> headers =
-                        ImmutableMap.of(ORIGIN_HEADER_NAME, 
websocketConfig.getAllowOrigin());
-                clients.add(
-                        new ShenyuWebsocketClient(
-                                URI.create(url),
-                        headers,
-                        Objects.requireNonNull(pluginDataSubscriber),
-                        metaDataSubscribers,
-                        authDataSubscribers,
-                        proxySelectorDataSubscribers,
-                        discoveryUpstreamDataSubscribers,
-                                this.aiProxyApiKeyDataSubscribers,
-                        namespaceId,
-                        serverProperties.getPort()));
-            } else {
-                clients.add(
-                        new ShenyuWebsocketClient(
-                                URI.create(url),
-                        Objects.requireNonNull(pluginDataSubscriber),
-                        metaDataSubscribers,
-                        authDataSubscribers,
-                        proxySelectorDataSubscribers,
-                        discoveryUpstreamDataSubscribers,
-                                this.aiProxyApiKeyDataSubscribers,
-                        namespaceId,
-                        serverProperties.getPort()));
-            }
+            clients.add(createClient(url));
         }
         LOG.info("start check task...");
         this.timer.add(timerTask = new AbstractRoundTask(null, 
TimeUnit.SECONDS.toMillis(60)) {
@@ -164,32 +138,7 @@ public class WebsocketSyncDataService implements 
SyncDataService {
         if (CollectionUtils.isEmpty(clients)) {
             List<String> urls = websocketConfig.getUrls();
             for (String url : urls) {
-                if (StringUtils.isNotEmpty(websocketConfig.getAllowOrigin())) {
-                    Map<String, String> headers =
-                            ImmutableMap.of(ORIGIN_HEADER_NAME, 
websocketConfig.getAllowOrigin());
-                    clients.add(
-                            new ShenyuWebsocketClient(
-                                    URI.create(url),
-                                    headers,
-                                    
Objects.requireNonNull(pluginDataSubscriber),
-                                    metaDataSubscribers,
-                                    authDataSubscribers,
-                                    proxySelectorDataSubscribers,
-                                    discoveryUpstreamDataSubscribers,
-                                    this.aiProxyApiKeyDataSubscribers,
-                                    namespaceId, serverProperties.getPort()));
-                } else {
-                    clients.add(
-                            new ShenyuWebsocketClient(
-                                    URI.create(url),
-                                    
Objects.requireNonNull(pluginDataSubscriber),
-                                    metaDataSubscribers,
-                                    authDataSubscribers,
-                                    proxySelectorDataSubscribers,
-                                    discoveryUpstreamDataSubscribers,
-                                    this.aiProxyApiKeyDataSubscribers,
-                                    namespaceId, serverProperties.getPort()));
-                }
+                clients.add(createClient(url));
             }
         }
         Iterator<ShenyuWebsocketClient> iterator = clients.iterator();
@@ -228,6 +177,27 @@ public class WebsocketSyncDataService implements 
SyncDataService {
         }
         timer.shutdown();
     }
+
+    private ShenyuWebsocketClient createClient(final String url) {
+        Map<String, String> headers = new HashMap<>();
+        if (StringUtils.isNotEmpty(websocketConfig.getAllowOrigin())) {
+            headers.put(ORIGIN_HEADER_NAME, websocketConfig.getAllowOrigin());
+        }
+        if (StringUtils.isNotBlank(websocketConfig.getToken())) {
+            headers.put(Constants.X_SHENYU_SYNC_TOKEN, 
websocketConfig.getToken());
+        }
+        return new ShenyuWebsocketClient(
+                URI.create(url),
+                headers,
+                Objects.requireNonNull(pluginDataSubscriber),
+                metaDataSubscribers,
+                authDataSubscribers,
+                proxySelectorDataSubscribers,
+                discoveryUpstreamDataSubscribers,
+                this.aiProxyApiKeyDataSubscribers,
+                namespaceId,
+                serverProperties.getPort());
+    }
     
     /**
      * get websocket config.
diff --git 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java
 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java
index 10f0ba0573..602dc5f23b 100644
--- 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java
+++ 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/main/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfig.java
@@ -33,6 +33,11 @@ public class WebsocketConfig {
      */
     private String allowOrigin;
 
+    /**
+     * WebSocket sync token.
+     */
+    private String token;
+
     /**
      * get urls.
      *
@@ -66,6 +71,22 @@ public class WebsocketConfig {
     public void setAllowOrigin(final String allowOrigin) {
         this.allowOrigin = allowOrigin;
     }
+
+    /**
+     * get token.
+     * @return token
+     */
+    public String getToken() {
+        return token;
+    }
+
+    /**
+     * set token.
+     * @param token token
+     */
+    public void setToken(final String token) {
+        this.token = token;
+    }
     
     @Override
     public boolean equals(final Object o) {
@@ -77,12 +98,13 @@ public class WebsocketConfig {
         }
         WebsocketConfig that = (WebsocketConfig) o;
         return Objects.equals(urls, that.urls)
-                && Objects.equals(allowOrigin, that.allowOrigin);
+                && Objects.equals(allowOrigin, that.allowOrigin)
+                && Objects.equals(token, that.token);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(urls, allowOrigin);
+        return Objects.hash(urls, allowOrigin, token);
     }
 
     @Override
@@ -90,8 +112,11 @@ public class WebsocketConfig {
         return "WebsocketConfig{"
                 + "urls='"
                 + urls
+                + '\''
                 + ", allowOrigin='"
                 + allowOrigin
+                + '\''
+                + ", token='******'"
                 + '}';
     }
 }
diff --git 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java
 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java
index 713ccce556..c5f9bf2782 100644
--- 
a/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java
+++ 
b/shenyu-sync-data-center/shenyu-sync-data-websocket/src/test/java/org/apache/shenyu/plugin/sync/data/websocket/config/WebsocketConfigTest.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Objects;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 
 /**
@@ -36,6 +37,8 @@ public class WebsocketConfigTest {
 
     private static final String ALLOW_ORIGIN = "ws://localhost:9095";
 
+    private static final String TOKEN = "websocket-sync-token";
+
     private WebsocketConfig websocketConfig;
 
     @BeforeEach
@@ -43,12 +46,14 @@ public class WebsocketConfigTest {
         websocketConfig = new WebsocketConfig();
         websocketConfig.setUrls(URLS);
         websocketConfig.setAllowOrigin(ALLOW_ORIGIN);
+        websocketConfig.setToken(TOKEN);
     }
 
     @Test
     public void testGetterSetter() {
         assertEquals(URLS, websocketConfig.getUrls());
         assertEquals(ALLOW_ORIGIN, websocketConfig.getAllowOrigin());
+        assertEquals(TOKEN, websocketConfig.getToken());
     }
 
     @Test
@@ -56,6 +61,7 @@ public class WebsocketConfigTest {
         WebsocketConfig that = new WebsocketConfig();
         that.setUrls(URLS);
         that.setAllowOrigin(ALLOW_ORIGIN);
+        that.setToken(TOKEN);
         assertEquals(websocketConfig, websocketConfig);
         assertEquals(websocketConfig, that);
         assertNotEquals(websocketConfig, null);
@@ -64,13 +70,14 @@ public class WebsocketConfigTest {
 
     @Test
     public void testHashCode() {
-        assertEquals(Objects.hash(websocketConfig.getUrls(), 
websocketConfig.getAllowOrigin()), websocketConfig.hashCode());
+        assertEquals(Objects.hash(websocketConfig.getUrls(), 
websocketConfig.getAllowOrigin(), websocketConfig.getToken()), 
websocketConfig.hashCode());
     }
 
     @Test
     public void testToString() {
-        String toString = "WebsocketConfig{urls='%s, allowOrigin='%s}";
+        String toString = "WebsocketConfig{urls='%s', allowOrigin='%s', 
token='******'}";
         String expected = String.format(toString, URLS, ALLOW_ORIGIN);
         assertEquals(expected, websocketConfig.toString());
+        assertFalse(websocketConfig.toString().contains(TOKEN));
     }
 }

Reply via email to