@Test public void createAndUpdateAccessAclYamlConfigNormalTest() { System.setProperty("rocketmq.home.dir", "src/test/resources"); System.setProperty("rocketmq.acl.plain.file", "/conf/plain_acl_update_create.yml"); String targetFileName = "src/test/resources/conf/plain_acl_update_create.yml"; Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class); PlainAccessConfig plainAccessConfig = new PlainAccessConfig(); plainAccessConfig.setAccessKey("RocketMQ33"); plainAccessConfig.setSecretKey("123456789111"); plainAccessConfig.setDefaultGroupPerm("PUB"); plainAccessConfig.setDefaultTopicPerm("DENY"); List<String> topicPerms = new ArrayList<String>(); topicPerms.add("topicC=PUB|SUB"); topicPerms.add("topicB=PUB"); plainAccessConfig.setTopicPerms(topicPerms); List<String> groupPerms = new ArrayList<String>(); groupPerms.add("groupB=PUB|SUB"); groupPerms.add("groupC=DENY"); plainAccessConfig.setGroupPerms(groupPerms); PlainAccessValidator plainAccessValidator = new PlainAccessValidator(); plainAccessValidator.updateAccessConfig(plainAccessConfig); Map<String, Object> readableMap = AclUtils.getYamlDataObject(targetFileName, Map.class); List<Map<String, Object>> accounts = (List<Map<String, Object>>)readableMap.get(AclConstants.CONFIG_ACCOUNTS); Map<String, Object> verifyMap = null; for (Map<String, Object> account : accounts) { if (account.get(AclConstants.CONFIG_ACCESS_KEY).equals(plainAccessConfig.getAccessKey())) { verifyMap = account; break; } } Assert.assertEquals(verifyMap.get(AclConstants.CONFIG_SECRET_KEY),"123456789111"); Assert.assertEquals(verifyMap.get(AclConstants.CONFIG_DEFAULT_TOPIC_PERM),"DENY"); Assert.assertEquals(verifyMap.get(AclConstants.CONFIG_DEFAULT_GROUP_PERM),"PUB"); Assert.assertEquals(((List)verifyMap.get(AclConstants.CONFIG_TOPIC_PERMS)).size(),2); Assert.assertEquals(((List)verifyMap.get(AclConstants.CONFIG_GROUP_PERMS)).size(),2); Assert.assertTrue(((List)verifyMap.get(AclConstants.CONFIG_TOPIC_PERMS)).contains("topicC=PUB|SUB")); Assert.assertTrue(((List)verifyMap.get(AclConstants.CONFIG_TOPIC_PERMS)).contains("topicB=PUB")); Assert.assertTrue(((List)verifyMap.get(AclConstants.CONFIG_GROUP_PERMS)).contains("groupB=PUB|SUB")); Assert.assertTrue(((List)verifyMap.get(AclConstants.CONFIG_GROUP_PERMS)).contains("groupC=DENY")); List<Map<String, Object>> dataVersions = (List<Map<String, Object>>) readableMap.get(AclConstants.CONFIG_DATA_VERSION); Assert.assertEquals(1,dataVersions.get(0).get(AclConstants.CONFIG_COUNTER)); PlainAccessConfig plainAccessConfig2 = new PlainAccessConfig(); plainAccessConfig2.setAccessKey("rocketmq2"); plainAccessConfig2.setSecretKey("1234567890123"); plainAccessValidator.updateAccessConfig(plainAccessConfig2); Map<String, Object> readableMap2 = AclUtils.getYamlDataObject(targetFileName, Map.class); List<Map<String, Object>> accounts2 = (List<Map<String, Object>>)readableMap2.get(AclConstants.CONFIG_ACCOUNTS); Map<String, Object> verifyMap2 = null; for (Map<String, Object> account : accounts2) { if (account.get(AclConstants.CONFIG_ACCESS_KEY).equals(plainAccessConfig2.getAccessKey())) { verifyMap2 = account; break; } } List<Map<String, Object>> dataVersions2 = (List<Map<String, Object>>) readableMap2.get(AclConstants.CONFIG_DATA_VERSION); Assert.assertEquals(2,dataVersions2.get(0).get(AclConstants.CONFIG_COUNTER)); Assert.assertEquals(verifyMap2.get(AclConstants.CONFIG_SECRET_KEY),"1234567890123"); AclUtils.writeDataObject(targetFileName, backUpAclConfigMap); }
@Override public boolean updateAccessConfig(PlainAccessConfig plainAccessConfig) { return aclPlugEngine.updateAccessConfig(plainAccessConfig); }
PlainAccessValidator implements AccessValidator { @Override public boolean updateAccessConfig(PlainAccessConfig plainAccessConfig) { return aclPlugEngine.updateAccessConfig(plainAccessConfig); } }
PlainAccessValidator implements AccessValidator { @Override public boolean updateAccessConfig(PlainAccessConfig plainAccessConfig) { return aclPlugEngine.updateAccessConfig(plainAccessConfig); } PlainAccessValidator(); }
PlainAccessValidator implements AccessValidator { @Override public boolean updateAccessConfig(PlainAccessConfig plainAccessConfig) { return aclPlugEngine.updateAccessConfig(plainAccessConfig); } PlainAccessValidator(); @Override AccessResource parse(RemotingCommand request, String remoteAddr); @Override void validate(AccessResource accessResource); @Override boolean updateAccessConfig(PlainAccessConfig plainAccessConfig); @Override boolean deleteAccessConfig(String accesskey); @Override String getAclConfigVersion(); @Override boolean updateGlobalWhiteAddrsConfig(List<String> globalWhiteAddrsList); @Override AclConfig getAllAclConfig(); }
PlainAccessValidator implements AccessValidator { @Override public boolean updateAccessConfig(PlainAccessConfig plainAccessConfig) { return aclPlugEngine.updateAccessConfig(plainAccessConfig); } PlainAccessValidator(); @Override AccessResource parse(RemotingCommand request, String remoteAddr); @Override void validate(AccessResource accessResource); @Override boolean updateAccessConfig(PlainAccessConfig plainAccessConfig); @Override boolean deleteAccessConfig(String accesskey); @Override String getAclConfigVersion(); @Override boolean updateGlobalWhiteAddrsConfig(List<String> globalWhiteAddrsList); @Override AclConfig getAllAclConfig();  }