@Test(expected = AclException.class) public void setTopicPermTest() { PlainAccessResource plainAccessResource = new PlainAccessResource(); Map<String, Byte> resourcePermMap = plainAccessResource.getResourcePermMap(); Permission.parseResourcePerms(plainAccessResource, false, null); Assert.assertNull(resourcePermMap); List<String> groups = new ArrayList<>(); Permission.parseResourcePerms(plainAccessResource, false, groups); Assert.assertNull(resourcePermMap); groups.add("groupA=DENY"); groups.add("groupB=PUB|SUB"); groups.add("groupC=PUB"); Permission.parseResourcePerms(plainAccessResource, false, groups); resourcePermMap = plainAccessResource.getResourcePermMap(); byte perm = resourcePermMap.get(PlainAccessResource.getRetryTopic("groupA")); Assert.assertEquals(perm, Permission.DENY); perm = resourcePermMap.get(PlainAccessResource.getRetryTopic("groupB")); Assert.assertEquals(perm,Permission.PUB|Permission.SUB); perm = resourcePermMap.get(PlainAccessResource.getRetryTopic("groupC")); Assert.assertEquals(perm, Permission.PUB); List<String> topics = new ArrayList<>(); topics.add("topicA=DENY"); topics.add("topicB=PUB|SUB"); topics.add("topicC=PUB"); Permission.parseResourcePerms(plainAccessResource, true, topics); perm = resourcePermMap.get("topicA"); Assert.assertEquals(perm, Permission.DENY); perm = resourcePermMap.get("topicB"); Assert.assertEquals(perm, Permission.PUB|Permission.SUB); perm = resourcePermMap.get("topicC"); Assert.assertEquals(perm, Permission.PUB); List<String> erron = new ArrayList<>(); erron.add(""); Permission.parseResourcePerms(plainAccessResource, false, erron); }
public static void parseResourcePerms(PlainAccessResource plainAccessResource, Boolean isTopic, List<String> resources) { if (resources == null || resources.isEmpty()) { return; } for (String resource : resources) { String[] items = StringUtils.split(resource, "="); if (items.length == 2) { plainAccessResource.addResourceAndPerm(isTopic ? items[0].trim() : PlainAccessResource.getRetryTopic(items[0].trim()), parsePermFromString(items[1].trim())); } else { throw new AclException(String.format("Parse resource permission failed for %s:%s", isTopic ? "topic" : "group", resource)); } } }
Permission { public static void parseResourcePerms(PlainAccessResource plainAccessResource, Boolean isTopic, List<String> resources) { if (resources == null || resources.isEmpty()) { return; } for (String resource : resources) { String[] items = StringUtils.split(resource, "="); if (items.length == 2) { plainAccessResource.addResourceAndPerm(isTopic ? items[0].trim() : PlainAccessResource.getRetryTopic(items[0].trim()), parsePermFromString(items[1].trim())); } else { throw new AclException(String.format("Parse resource permission failed for %s:%s", isTopic ? "topic" : "group", resource)); } } } }
Permission { public static void parseResourcePerms(PlainAccessResource plainAccessResource, Boolean isTopic, List<String> resources) { if (resources == null || resources.isEmpty()) { return; } for (String resource : resources) { String[] items = StringUtils.split(resource, "="); if (items.length == 2) { plainAccessResource.addResourceAndPerm(isTopic ? items[0].trim() : PlainAccessResource.getRetryTopic(items[0].trim()), parsePermFromString(items[1].trim())); } else { throw new AclException(String.format("Parse resource permission failed for %s:%s", isTopic ? "topic" : "group", resource)); } } }  }
Permission { public static void parseResourcePerms(PlainAccessResource plainAccessResource, Boolean isTopic, List<String> resources) { if (resources == null || resources.isEmpty()) { return; } for (String resource : resources) { String[] items = StringUtils.split(resource, "="); if (items.length == 2) { plainAccessResource.addResourceAndPerm(isTopic ? items[0].trim() : PlainAccessResource.getRetryTopic(items[0].trim()), parsePermFromString(items[1].trim())); } else { throw new AclException(String.format("Parse resource permission failed for %s:%s", isTopic ? "topic" : "group", resource)); } } }  static boolean checkPermission(byte neededPerm, byte ownedPerm); static byte parsePermFromString(String permString); static void parseResourcePerms(PlainAccessResource plainAccessResource, Boolean isTopic,
        List<String> resources); static boolean needAdminPerm(Integer code); }
Permission { public static void parseResourcePerms(PlainAccessResource plainAccessResource, Boolean isTopic, List<String> resources) { if (resources == null || resources.isEmpty()) { return; } for (String resource : resources) { String[] items = StringUtils.split(resource, "="); if (items.length == 2) { plainAccessResource.addResourceAndPerm(isTopic ? items[0].trim() : PlainAccessResource.getRetryTopic(items[0].trim()), parsePermFromString(items[1].trim())); } else { throw new AclException(String.format("Parse resource permission failed for %s:%s", isTopic ? "topic" : "group", resource)); } } }  static boolean checkPermission(byte neededPerm, byte ownedPerm); static byte parsePermFromString(String permString); static void parseResourcePerms(PlainAccessResource plainAccessResource, Boolean isTopic,
        List<String> resources); static boolean needAdminPerm(Integer code); static final byte DENY; static final byte ANY; static final byte PUB; static final byte SUB; static final Set<Integer> ADMIN_CODE; }