Java Code Examples for org.apache.kafka.common.resource.ResourceType#GROUP
The following examples show how to use
org.apache.kafka.common.resource.ResourceType#GROUP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleAclRuleResourceTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testFromCrdToKafkaResourcePatternForGroupResource() { // Regular group AclRuleResource resource = new AclRuleGroupResourceBuilder() .withName("my-group") .withPatternType(AclResourcePatternType.LITERAL) .build(); ResourcePattern expectedKafkaGroupResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-group", PatternType.LITERAL); assertThat(SimpleAclRuleResource.fromCrd(resource).toKafkaResourcePattern(), is(expectedKafkaGroupResourcePattern)); // Prefixed group resource = new AclRuleGroupResourceBuilder() .withName("my-") .withPatternType(AclResourcePatternType.PREFIX) .build(); expectedKafkaGroupResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-", PatternType.PREFIXED); assertThat(SimpleAclRuleResource.fromCrd(resource).toKafkaResourcePattern(), is(expectedKafkaGroupResourcePattern)); }
Example 2
Source File: TopologyBuilderAdminClient.java From kafka-topology-builder with MIT License | 5 votes |
public List<AclBinding> setAclsForConnect( String principal, String topicPrefix, List<String> readTopics, List<String> writeTopics) throws IOException { List<AclBinding> acls = new ArrayList<>(); List<String> topics = Arrays.asList("connect-status", "connect-offsets", "connect-configs"); for (String topic : topics) { acls.add(buildTopicLevelAcl(principal, topic, PatternType.LITERAL, AclOperation.READ)); acls.add(buildTopicLevelAcl(principal, topic, PatternType.LITERAL, AclOperation.WRITE)); } ResourcePattern resourcePattern = new ResourcePattern(ResourceType.CLUSTER, "kafka-cluster", PatternType.LITERAL); AccessControlEntry entry = new AccessControlEntry(principal, "*", AclOperation.CREATE, AclPermissionType.ALLOW); acls.add(new AclBinding(resourcePattern, entry)); resourcePattern = new ResourcePattern(ResourceType.GROUP, "*", PatternType.LITERAL); entry = new AccessControlEntry(principal, "*", AclOperation.READ, AclPermissionType.ALLOW); acls.add(new AclBinding(resourcePattern, entry)); if (readTopics != null) { readTopics.forEach( topic -> { acls.add(buildTopicLevelAcl(principal, topic, PatternType.LITERAL, AclOperation.READ)); }); } if (writeTopics != null) { writeTopics.forEach( topic -> { acls.add(buildTopicLevelAcl(principal, topic, PatternType.LITERAL, AclOperation.WRITE)); }); } createAcls(acls); return acls; }
Example 3
Source File: SimpleAclOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testGetUsersFromAcls(VertxTestContext context) { Admin mockAdminClient = mock(AdminClient.class); SimpleAclOperator aclOp = new SimpleAclOperator(vertx, mockAdminClient); ResourcePattern res1 = new ResourcePattern(ResourceType.TOPIC, "my-topic", PatternType.LITERAL); ResourcePattern res2 = new ResourcePattern(ResourceType.GROUP, "my-group", PatternType.LITERAL); KafkaPrincipal foo = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "CN=foo"); AclBinding fooAclBinding = new AclBinding(res1, new AccessControlEntry(foo.toString(), "*", org.apache.kafka.common.acl.AclOperation.READ, AclPermissionType.ALLOW)); KafkaPrincipal bar = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "CN=bar"); AclBinding barAclBinding = new AclBinding(res1, new AccessControlEntry(bar.toString(), "*", org.apache.kafka.common.acl.AclOperation.READ, AclPermissionType.ALLOW)); KafkaPrincipal baz = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "baz"); AclBinding bazAclBinding = new AclBinding(res2, new AccessControlEntry(baz.toString(), "*", org.apache.kafka.common.acl.AclOperation.READ, AclPermissionType.ALLOW)); KafkaPrincipal all = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "*"); AclBinding allAclBinding = new AclBinding(res1, new AccessControlEntry(all.toString(), "*", org.apache.kafka.common.acl.AclOperation.READ, AclPermissionType.ALLOW)); KafkaPrincipal anonymous = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "ANONYMOUS"); AclBinding anonymousAclBinding = new AclBinding(res2, new AccessControlEntry(anonymous.toString(), "*", org.apache.kafka.common.acl.AclOperation.READ, AclPermissionType.ALLOW)); Collection<AclBinding> aclBindings = asList(fooAclBinding, barAclBinding, bazAclBinding, allAclBinding, anonymousAclBinding); assertDoesNotThrow(() -> mockDescribeAcls(mockAdminClient, AclBindingFilter.ANY, aclBindings)); assertThat(aclOp.getUsersWithAcls(), is(new HashSet<>(asList("foo", "bar", "baz")))); context.completeNow(); }
Example 4
Source File: SimpleAclRuleResourceTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testToKafkaResourcePatternForGroupResource() { // Regular group SimpleAclRuleResource groupResourceRules = new SimpleAclRuleResource("my-group", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.LITERAL); ResourcePattern expectedKafkaResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-group", PatternType.LITERAL); assertThat(groupResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); // Prefixed group groupResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.PREFIX); expectedKafkaResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-", PatternType.PREFIXED); assertThat(groupResourceRules.toKafkaResourcePattern(), is(expectedKafkaResourcePattern)); }
Example 5
Source File: SimpleAclRuleResourceTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testFromKafkaResourcePatternWithGroupResource() { // Regular group ResourcePattern kafkaGroupResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-group", PatternType.LITERAL); SimpleAclRuleResource expectedGroupResourceRules = new SimpleAclRuleResource("my-group", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.LITERAL); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaGroupResourcePattern), is(expectedGroupResourceRules)); // Prefixed group kafkaGroupResourcePattern = new ResourcePattern(ResourceType.GROUP, "my-", PatternType.PREFIXED); expectedGroupResourceRules = new SimpleAclRuleResource("my-", SimpleAclRuleResourceType.GROUP, AclResourcePatternType.PREFIX); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafkaGroupResourcePattern), is(expectedGroupResourceRules)); }
Example 6
Source File: SimpleAclRuleResourceTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testFromKafkaResourcePatternToKafkaResourcePatternRoundTripForGroupResource() { // Regular group ResourcePattern kafka = new ResourcePattern(ResourceType.GROUP, "my-group", PatternType.LITERAL); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafka).toKafkaResourcePattern(), is(kafka)); // Prefixed group kafka = new ResourcePattern(ResourceType.GROUP, "my-", PatternType.PREFIXED); assertThat(SimpleAclRuleResource.fromKafkaResourcePattern(kafka).toKafkaResourcePattern(), is(kafka)); }