This is an automated email from the ASF dual-hosted git repository.
lizhimin pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new c24f654909 [ISSUE #9156] Use fastjson2 in AclUtils#getAclRPCHook
(#9157)
c24f654909 is described below
commit c24f654909db0a60bf365b6c6950c8b8cc5d023e
Author: yx9o <[email protected]>
AuthorDate: Mon Feb 10 10:40:59 2025 +0800
[ISSUE #9156] Use fastjson2 in AclUtils#getAclRPCHook (#9157)
---
.../org/apache/rocketmq/acl/common/AclUtils.java | 2 +-
.../apache/rocketmq/acl/common/AclUtilsTest.java | 28 +++++++++++++++++++++-
acl/src/test/resources/acl_hook/plain_acl.yml | 21 ++++++++++++++++
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
b/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
index f32acaf2f7..d13c0362be 100644
--- a/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
+++ b/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java
@@ -23,7 +23,7 @@ import java.io.PrintWriter;
import java.util.Map;
import java.util.SortedMap;
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.common.constant.LoggerName;
import org.apache.rocketmq.logging.org.slf4j.Logger;
diff --git a/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
b/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
index 03bceade77..be74e54ed3 100644
--- a/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
+++ b/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.rocketmq.acl.common;
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.acl.plain.PlainAccessData;
import org.apache.rocketmq.common.PlainAccessConfig;
@@ -32,8 +32,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.UUID;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
public class AclUtilsTest {
@Test
@@ -296,4 +301,25 @@ public class AclUtilsTest {
Assert.assertNull(incompleteContRPCHook);
}
}
+
+ @Test
+ public void testGetAclRPCHookByFileName() {
+ RPCHook actual =
AclUtils.getAclRPCHook(Objects.requireNonNull(AclUtilsTest.class.getResource("/acl_hook/plain_acl.yml")).getPath());
+ assertNotNull(actual);
+ assertTrue(actual instanceof AclClientRPCHook);
+ assertAclClientRPCHook((AclClientRPCHook) actual);
+ }
+
+ @Test
+ public void testGetAclRPCHookByInputStream() {
+ RPCHook actual =
AclUtils.getAclRPCHook(Objects.requireNonNull(AclUtilsTest.class.getResourceAsStream("/acl_hook/plain_acl.yml")));
+ assertNotNull(actual);
+ assertTrue(actual instanceof AclClientRPCHook);
+ assertAclClientRPCHook((AclClientRPCHook) actual);
+ }
+
+ private void assertAclClientRPCHook(final AclClientRPCHook actual) {
+ assertEquals("rocketmq2",
actual.getSessionCredentials().getAccessKey());
+ assertEquals("12345678",
actual.getSessionCredentials().getSecretKey());
+ }
}
diff --git a/acl/src/test/resources/acl_hook/plain_acl.yml
b/acl/src/test/resources/acl_hook/plain_acl.yml
new file mode 100644
index 0000000000..66bf576227
--- /dev/null
+++ b/acl/src/test/resources/acl_hook/plain_acl.yml
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+## suggested format
+
+- accessKey: rocketmq2
+ secretKey: 12345678
+ whiteRemoteAddress: 192.168.1.*
+ admin: true