[ISSUE #9156] Use fastjson2 in AclUtils#getAclRPCHook (#9157)

This commit is contained in:
yx9o
2025-07-19 18:17:55 +08:00
committed by RongtongJin
parent 02d28c5f43
commit 1a114e77f0
3 changed files with 49 additions and 2 deletions
@@ -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;
@@ -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());
}
}
@@ -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