diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java b/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java index 34bb1b439e53bddfecb5b86f601704750611e868..bd50e1292ad4e1682bc0dcd547b343a47d4c9d04 100644 --- a/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java +++ b/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java @@ -52,6 +52,11 @@ public class PlainAccessValidator implements AccessValidator { } else { accessResource.setWhiteRemoteAddress(remoteAddr); } + + if (request.getExtFields() == null) { + throw new AclException("request's extFields value is null"); + } + accessResource.setRequestCode(request.getCode()); accessResource.setAccessKey(request.getExtFields().get(SessionCredentials.ACCESS_KEY)); accessResource.setSignature(request.getExtFields().get(SessionCredentials.SIGNATURE)); diff --git a/acl/src/test/java/org/apache/rocketmq/acl/plain/PlainAccessValidatorTest.java b/acl/src/test/java/org/apache/rocketmq/acl/plain/PlainAccessValidatorTest.java index 16e770206cb8cc35f62d91bb0c6bc043df4798c3..e7b6f2d68af27cbfe1879175e3ead04dd63de86b 100644 --- a/acl/src/test/java/org/apache/rocketmq/acl/plain/PlainAccessValidatorTest.java +++ b/acl/src/test/java/org/apache/rocketmq/acl/plain/PlainAccessValidatorTest.java @@ -43,6 +43,7 @@ public class PlainAccessValidatorTest { @Before public void init() { System.setProperty("rocketmq.home.dir", "src/test/resources"); + System.setProperty("rocketmq.acl.plain.file", "/conf/plain_acl.yml"); plainAccessValidator = new PlainAccessValidator(); sessionCredentials = new SessionCredentials(); sessionCredentials.setAccessKey("RocketMQ"); @@ -115,6 +116,22 @@ public class PlainAccessValidatorTest { plainAccessValidator.validate(accessResource); } + @Test(expected = AclException.class) + public void validateForAdminCommandWithOutAclRPCHook() { + RemotingCommand consumerOffsetAdminRequest = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_CONSUMER_OFFSET, null); + plainAccessValidator.parse(consumerOffsetAdminRequest, "192.168.0.1:9876"); + + RemotingCommand subscriptionGroupAdminRequest = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null); + plainAccessValidator.parse(subscriptionGroupAdminRequest, "192.168.0.1:9876"); + + RemotingCommand delayOffsetAdminRequest = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_DELAY_OFFSET, null); + plainAccessValidator.parse(delayOffsetAdminRequest, "192.168.0.1:9876"); + + RemotingCommand allTopicConfigAdminRequest = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null); + plainAccessValidator.parse(allTopicConfigAdminRequest, "192.168.0.1:9876"); + + } + @Test public void validatePullMessageTest() { PullMessageRequestHeader pullMessageRequestHeader=new PullMessageRequestHeader();