Skip to content

Commit 1a114e7

Browse files
yx9oRongtongJin
authored andcommitted
[ISSUE #9156] Use fastjson2 in AclUtils#getAclRPCHook (#9157)
1 parent 02d28c5 commit 1a114e7

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Map;
2424
import java.util.SortedMap;
2525

26-
import com.alibaba.fastjson.JSONObject;
26+
import com.alibaba.fastjson2.JSONObject;
2727
import org.apache.commons.lang3.StringUtils;
2828
import org.apache.rocketmq.common.constant.LoggerName;
2929
import org.apache.rocketmq.logging.org.slf4j.Logger;

acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.apache.rocketmq.acl.common;
1818

19-
import com.alibaba.fastjson.JSONObject;
19+
import com.alibaba.fastjson2.JSONObject;
2020
import org.apache.commons.lang3.StringUtils;
2121
import org.apache.rocketmq.acl.plain.PlainAccessData;
2222
import org.apache.rocketmq.common.PlainAccessConfig;
@@ -32,8 +32,13 @@
3232
import java.util.Collections;
3333
import java.util.List;
3434
import java.util.Map;
35+
import java.util.Objects;
3536
import java.util.UUID;
3637

38+
import static org.junit.Assert.assertEquals;
39+
import static org.junit.Assert.assertNotNull;
40+
import static org.junit.Assert.assertTrue;
41+
3742
public class AclUtilsTest {
3843

3944
@Test
@@ -296,4 +301,25 @@ public void getAclRPCHookTest() throws IOException {
296301
Assert.assertNull(incompleteContRPCHook);
297302
}
298303
}
304+
305+
@Test
306+
public void testGetAclRPCHookByFileName() {
307+
RPCHook actual = AclUtils.getAclRPCHook(Objects.requireNonNull(AclUtilsTest.class.getResource("/acl_hook/plain_acl.yml")).getPath());
308+
assertNotNull(actual);
309+
assertTrue(actual instanceof AclClientRPCHook);
310+
assertAclClientRPCHook((AclClientRPCHook) actual);
311+
}
312+
313+
@Test
314+
public void testGetAclRPCHookByInputStream() {
315+
RPCHook actual = AclUtils.getAclRPCHook(Objects.requireNonNull(AclUtilsTest.class.getResourceAsStream("/acl_hook/plain_acl.yml")));
316+
assertNotNull(actual);
317+
assertTrue(actual instanceof AclClientRPCHook);
318+
assertAclClientRPCHook((AclClientRPCHook) actual);
319+
}
320+
321+
private void assertAclClientRPCHook(final AclClientRPCHook actual) {
322+
assertEquals("rocketmq2", actual.getSessionCredentials().getAccessKey());
323+
assertEquals("12345678", actual.getSessionCredentials().getSecretKey());
324+
}
299325
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
## suggested format
17+
18+
- accessKey: rocketmq2
19+
secretKey: 12345678
20+
whiteRemoteAddress: 192.168.1.*
21+
admin: true

0 commit comments

Comments
 (0)