From e396c2b19b75f03e3465fe9084fd41e9e1f2e83e Mon Sep 17 00:00:00 2001 From: Loong Wan Date: Sat, 31 Oct 2026 23:20:29 +0800 Subject: [PATCH 1/6] build: include Boot-managed Hazelcast client API --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index b471f66..14d46df 100644 --- a/pom.xml +++ b/pom.xml @@ -481,6 +481,12 @@ ${netty-socketio.version} + + + com.hazelcast + hazelcast + + org.redisson From 1ee325ba591c1ec081cc8fe9094b63576f148732 Mon Sep 17 00:00:00 2001 From: Loong Wan Date: Sat, 31 Oct 2026 23:22:40 +0800 Subject: [PATCH 2/6] fix: implement netty-socketio 2 authorization result contract --- .../spring/boot/listener/JWTAuthorizationListener.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java b/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java index 3a16f91..3f71421 100644 --- a/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java +++ b/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java @@ -17,7 +17,8 @@ import org.springframework.util.StringUtils; -import com.corundumstudio.socketio.AuthorizationListener; +import com.corundumstudio.socketio.AuthorizationListener; +import com.corundumstudio.socketio.AuthorizationResult; import com.corundumstudio.socketio.HandshakeData; /** @@ -53,6 +54,12 @@ public boolean isAuthorized(HandshakeData data) { return false; } + @Override + public AuthorizationResult getAuthorizationResult(HandshakeData data) { + return isAuthorized(data) ? AuthorizationResult.SUCCESSFUL_AUTHORIZATION + : AuthorizationResult.FAILED_AUTHORIZATION; + } + protected String obtainToken(HandshakeData data) { // 从header中获取token String token = data.getHttpHeaders().get(getAuthorizationHeaderName()); From bfd63632db7fa09bc1e4112f19f9b987593f477b Mon Sep 17 00:00:00 2001 From: Loong Wan Date: Sat, 31 Oct 2026 23:24:27 +0800 Subject: [PATCH 3/6] fix: retain compatibility helper without obsolete override --- .../socketio/spring/boot/listener/JWTAuthorizationListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java b/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java index 3f71421..f2003db 100644 --- a/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java +++ b/src/main/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListener.java @@ -36,7 +36,6 @@ public class JWTAuthorizationListener implements AuthorizationListener { private String authorizationHeaderName = AUTHORIZATION_HEADER; private String authorizationParamName = AUTHORIZATION_PARAM; - @Override public boolean isAuthorized(HandshakeData data) { String token = obtainToken(data); From 4be9d88dd8177fb7bf020b1b8d75da855eb73436 Mon Sep 17 00:00:00 2001 From: Loong Wan Date: Sun, 1 Nov 2026 00:25:07 +0800 Subject: [PATCH 4/6] test: exercise upstream Hazelcast map and topic ABI on all JDKs --- .github/workflows/ci.yml | 3 + pom.xml | 8 +- .../boot/HazelcastStoreCompatibilityTest.java | 91 +++++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9663666..435fe69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,9 @@ jobs: java-version: ${{ matrix.java }} cache: maven + - name: Record Hazelcast dependency tree + run: mvn -B --no-transfer-progress dependency:tree -Dincludes=com.hazelcast:* + - name: Build and verify run: mvn -B --no-transfer-progress clean verify diff --git a/pom.xml b/pom.xml index 14d46df..7341ff0 100644 --- a/pom.xml +++ b/pom.xml @@ -168,14 +168,14 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - - true - true + + false + false once - -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8 + -Xmx1024m -Dfile.encoding=UTF-8 ${basedir}/target/test-classes diff --git a/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java b/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java new file mode 100644 index 0000000..4b18e6c --- /dev/null +++ b/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java @@ -0,0 +1,91 @@ +package com.corundumstudio.socketio.spring.boot; + +import com.corundumstudio.socketio.store.HazelcastStoreFactory; +import com.corundumstudio.socketio.store.HazelcastPubSubStore; +import com.corundumstudio.socketio.store.Store; +import com.corundumstudio.socketio.store.pubsub.DispatchMessage; +import com.corundumstudio.socketio.store.pubsub.PubSubType; +import com.hazelcast.config.Config; +import com.hazelcast.config.JoinConfig; +import com.hazelcast.core.Hazelcast; +import com.hazelcast.core.HazelcastInstance; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import static org.junit.jupiter.api.Assertions.*; + +class HazelcastStoreCompatibilityTest { + private HazelcastInstance member; + + @BeforeEach + void startIsolatedMember() throws Exception { + Config config = new Config(); + config.setInstanceName("socketio-abi-" + UUID.randomUUID()); + config.setProperty("hazelcast.phone.home.enabled", "false"); + config.setProperty("hazelcast.operation.thread.count", "2"); + config.setProperty("hazelcast.operation.generic.thread.count", "2"); + config.setProperty("hazelcast.io.thread.count", "2"); + config.getNetworkConfig().setPort(0); + config.getNetworkConfig().getInterfaces().setEnabled(true).addInterface("127.0.0.1"); + JoinConfig join = config.getNetworkConfig().getJoin(); + join.getMulticastConfig().setEnabled(false); + join.getTcpIpConfig().setEnabled(false); + join.getAwsConfig().setEnabled(false); + // Hazelcast 4 introduced auto-detection; disable it when reproducing the ABI regression. + try { + Object autoDetection = join.getClass().getMethod("getAutoDetectionConfig").invoke(join); + autoDetection.getClass().getMethod("setEnabled", boolean.class).invoke(autoDetection, false); + } catch (NoSuchMethodException expectedOnHazelcast3) { + // Hazelcast 3 has no auto-detection. + } + member = Hazelcast.newHazelcastInstance(config); + } + + @AfterEach + void stopMember() { + if (member != null) { + member.shutdown(); + } + } + + @Test + void upstreamStoreCanUseIMap() { + HazelcastStoreFactory factory = new HazelcastStoreFactory(member); + Store store = factory.createStore(UUID.randomUUID()); + store.set("key", "value"); + assertEquals("value", store.get("key")); + assertTrue(store.has("key")); + store.del("key"); + assertFalse(store.has("key")); + assertNull(store.get("key")); + factory.createMap("factory-map").put("key", "factory-value"); + assertEquals("factory-value", factory.createMap("factory-map").get("key")); + } + + @Test + void upstreamPubSubCanUseITopic() throws InterruptedException { + HazelcastPubSubStore publisher = new HazelcastPubSubStore(member, member, 1L); + HazelcastPubSubStore subscriber = new HazelcastPubSubStore(member, member, 2L); + CountDownLatch received = new CountDownLatch(1); + AtomicReference delivered = new AtomicReference<>(); + subscriber.subscribe(PubSubType.DISPATCH, message -> { + delivered.set(message); + received.countDown(); + }, DispatchMessage.class); + try { + publisher.publish(PubSubType.DISPATCH, new DispatchMessage("test-room", null, "/test")); + assertTrue(received.await(10, TimeUnit.SECONDS), "Actual Hazelcast topic must deliver the message"); + assertEquals("test-room", delivered.get().getRoom()); + assertEquals("/test", delivered.get().getNamespace()); + assertEquals(Long.valueOf(1), delivered.get().getNodeId()); + } finally { + subscriber.unsubscribe(PubSubType.DISPATCH); + } + } +} From b2278e5f719b3bb50fd5be55e02981a9b0df0ed4 Mon Sep 17 00:00:00 2001 From: Loong Wan Date: Sun, 1 Nov 2026 00:26:26 +0800 Subject: [PATCH 5/6] fix: align Hazelcast client and core with netty-socketio 3.x ABI --- pom.xml | 11 ++- .../JWTAuthorizationListenerTest.java | 67 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListenerTest.java diff --git a/pom.xml b/pom.xml index 7341ff0..d46e290 100644 --- a/pom.xml +++ b/pom.xml @@ -416,6 +416,8 @@ 2.22.1 1.6.8 2.0.9 + + 3.12.12 3.17.7 @@ -481,10 +483,17 @@ ${netty-socketio.version} - + + + com.hazelcast + hazelcast-client + ${hazelcast.version} + com.hazelcast hazelcast + ${hazelcast.version} diff --git a/src/test/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListenerTest.java b/src/test/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListenerTest.java new file mode 100644 index 0000000..c51e9c4 --- /dev/null +++ b/src/test/java/com/corundumstudio/socketio/spring/boot/listener/JWTAuthorizationListenerTest.java @@ -0,0 +1,67 @@ +package com.corundumstudio.socketio.spring.boot.listener; + +import com.corundumstudio.socketio.AuthorizationResult; +import com.corundumstudio.socketio.HandshakeData; +import io.netty.handler.codec.http.DefaultHttpHeaders; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.*; + +class JWTAuthorizationListenerTest { + private final JWTAuthorizationListener listener = new JWTAuthorizationListener(); + + private HandshakeData handshake(String header, String parameter) { + DefaultHttpHeaders headers = new DefaultHttpHeaders(); + if (header != null) { + headers.set(JWTAuthorizationListener.AUTHORIZATION_HEADER, header); + } + return new HandshakeData(headers, + parameter == null ? Collections.emptyMap() + : Collections.singletonMap("token", Collections.singletonList(parameter)), + null, "/", false); + } + + @Test + void bridgePreservesExistingTokenDecisions() { + assertSame(AuthorizationResult.SUCCESSFUL_AUTHORIZATION, + listener.getAuthorizationResult(handshake(" token ", null))); + assertSame(AuthorizationResult.SUCCESSFUL_AUTHORIZATION, + listener.getAuthorizationResult(handshake(null, "query-token"))); + assertSame(AuthorizationResult.SUCCESSFUL_AUTHORIZATION, + listener.getAuthorizationResult(handshake("", "query-token"))); + assertSame(AuthorizationResult.FAILED_AUTHORIZATION, + listener.getAuthorizationResult(handshake(null, null))); + assertSame(AuthorizationResult.FAILED_AUTHORIZATION, + listener.getAuthorizationResult(handshake(null, " "))); + // A whitespace-only header takes precedence, as in the original boolean contract. + assertSame(AuthorizationResult.FAILED_AUTHORIZATION, + listener.getAuthorizationResult(handshake(" ", "query-token"))); + } + + @Test + void bridgeStillDispatchesToPublicBooleanOverride() { + JWTAuthorizationListener denying = new JWTAuthorizationListener() { + @Override + public boolean isAuthorized(HandshakeData data) { + return false; + } + }; + assertSame(AuthorizationResult.FAILED_AUTHORIZATION, + denying.getAuthorizationResult(handshake("token", null))); + } + + @Test + void bridgeDoesNotTurnExceptionsIntoSuccessfulAuthorization() { + IllegalStateException failure = new IllegalStateException("authorization failed"); + JWTAuthorizationListener throwing = new JWTAuthorizationListener() { + @Override + public boolean isAuthorized(HandshakeData data) { + throw failure; + } + }; + assertSame(failure, assertThrows(IllegalStateException.class, + () -> throwing.getAuthorizationResult(handshake("token", null)))); + } +} From 3308b1ee5d1ba0e94acea49edd411cb87e077e98 Mon Sep 17 00:00:00 2001 From: Loong Wan Date: Sun, 1 Nov 2026 00:43:06 +0800 Subject: [PATCH 6/6] test: bind isolated Hazelcast sockets only to loopback --- .../socketio/spring/boot/HazelcastStoreCompatibilityTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java b/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java index 4b18e6c..92a95ac 100644 --- a/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java +++ b/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java @@ -28,6 +28,8 @@ void startIsolatedMember() throws Exception { Config config = new Config(); config.setInstanceName("socketio-abi-" + UUID.randomUUID()); config.setProperty("hazelcast.phone.home.enabled", "false"); + // Interface selection alone does not prevent binding the wildcard address. + config.setProperty("hazelcast.socket.bind.any", "false"); config.setProperty("hazelcast.operation.thread.count", "2"); config.setProperty("hazelcast.operation.generic.thread.count", "2"); config.setProperty("hazelcast.io.thread.count", "2");