Skip to content

Commit

Permalink
[ISSUE #9156] Use fastjson2 in AclUtils#getAclRPCHook (#9157)
Browse files Browse the repository at this point in the history
  • Loading branch information
yx9o authored Feb 10, 2025
1 parent faf494b commit c24f654
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,8 +32,13 @@
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
Expand Down Expand Up @@ -296,4 +301,25 @@ public void getAclRPCHookTest() throws IOException {
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());
}
}
21 changes: 21 additions & 0 deletions acl/src/test/resources/acl_hook/plain_acl.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c24f654

Please # to comment.