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 b471f66..d46e290 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
@@ -416,6 +416,8 @@
2.22.1
1.6.8
2.0.9
+
+ 3.12.12
3.17.7
@@ -481,6 +483,19 @@
${netty-socketio.version}
+
+
+ com.hazelcast
+ hazelcast-client
+ ${hazelcast.version}
+
+
+ com.hazelcast
+ hazelcast
+ ${hazelcast.version}
+
+
org.redisson
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..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
@@ -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;
/**
@@ -35,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);
@@ -53,6 +53,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());
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..92a95ac
--- /dev/null
+++ b/src/test/java/com/corundumstudio/socketio/spring/boot/HazelcastStoreCompatibilityTest.java
@@ -0,0 +1,93 @@
+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");
+ // 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");
+ 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);
+ }
+ }
+}
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))));
+ }
+}