Search in sources :

Example 11 with AclBinding

use of org.apache.kafka.common.acl.AclBinding in project kafka by apache.

the class StandardAcl method toBinding.

public AclBinding toBinding() {
    ResourcePattern resourcePattern = new ResourcePattern(resourceType, resourceName, patternType);
    AccessControlEntry accessControlEntry = new AccessControlEntry(principal, host, operation, permissionType);
    return new AclBinding(resourcePattern, accessControlEntry);
}
Also used : ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) AclBinding(org.apache.kafka.common.acl.AclBinding)

Example 12 with AclBinding

use of org.apache.kafka.common.acl.AclBinding in project kafka by apache.

the class AclControlManager method deleteAclsForFilter.

AclDeleteResult deleteAclsForFilter(AclBindingFilter filter, List<ApiMessageAndVersion> records) {
    List<AclBindingDeleteResult> deleted = new ArrayList<>();
    for (Entry<Uuid, StandardAcl> entry : idToAcl.entrySet()) {
        Uuid id = entry.getKey();
        StandardAcl acl = entry.getValue();
        AclBinding binding = acl.toBinding();
        if (filter.matches(binding)) {
            deleted.add(new AclBindingDeleteResult(binding));
            records.add(new ApiMessageAndVersion(new RemoveAccessControlEntryRecord().setId(id), (short) 0));
        }
    }
    return new AclDeleteResult(deleted);
}
Also used : Uuid(org.apache.kafka.common.Uuid) AclBindingDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) StandardAcl(org.apache.kafka.metadata.authorizer.StandardAcl) AclBinding(org.apache.kafka.common.acl.AclBinding) RemoveAccessControlEntryRecord(org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord)

Example 13 with AclBinding

use of org.apache.kafka.common.acl.AclBinding in project apache-kafka-on-k8s by banzaicloud.

the class KafkaAdminClientTest method testDeleteAcls.

@Test
public void testDeleteAcls() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareMetadataUpdate(env.cluster(), Collections.<String>emptySet());
        env.kafkaClient().setNode(env.cluster().controller());
        // Test a call where one filter has an error.
        env.kafkaClient().prepareResponse(new DeleteAclsResponse(0, asList(new AclFilterResponse(asList(new AclDeletionResult(ACL1), new AclDeletionResult(ACL2))), new AclFilterResponse(new ApiError(Errors.SECURITY_DISABLED, "No security"), Collections.<AclDeletionResult>emptySet()))));
        DeleteAclsResult results = env.adminClient().deleteAcls(asList(FILTER1, FILTER2));
        Map<AclBindingFilter, KafkaFuture<FilterResults>> filterResults = results.values();
        FilterResults filter1Results = filterResults.get(FILTER1).get();
        assertEquals(null, filter1Results.values().get(0).exception());
        assertEquals(ACL1, filter1Results.values().get(0).binding());
        assertEquals(null, filter1Results.values().get(1).exception());
        assertEquals(ACL2, filter1Results.values().get(1).binding());
        assertFutureError(filterResults.get(FILTER2), SecurityDisabledException.class);
        assertFutureError(results.all(), SecurityDisabledException.class);
        // Test a call where one deletion result has an error.
        env.kafkaClient().prepareResponse(new DeleteAclsResponse(0, asList(new AclFilterResponse(asList(new AclDeletionResult(ACL1), new AclDeletionResult(new ApiError(Errors.SECURITY_DISABLED, "No security"), ACL2))), new AclFilterResponse(Collections.<AclDeletionResult>emptySet()))));
        results = env.adminClient().deleteAcls(asList(FILTER1, FILTER2));
        assertTrue(results.values().get(FILTER2).get().values().isEmpty());
        assertFutureError(results.all(), SecurityDisabledException.class);
        // Test a call where there are no errors.
        env.kafkaClient().prepareResponse(new DeleteAclsResponse(0, asList(new AclFilterResponse(asList(new AclDeletionResult(ACL1))), new AclFilterResponse(asList(new AclDeletionResult(ACL2))))));
        results = env.adminClient().deleteAcls(asList(FILTER1, FILTER2));
        Collection<AclBinding> deleted = results.all().get();
        assertCollectionIs(deleted, ACL1, ACL2);
    }
}
Also used : DeleteAclsResponse(org.apache.kafka.common.requests.DeleteAclsResponse) FilterResults(org.apache.kafka.clients.admin.DeleteAclsResult.FilterResults) AclBindingFilter(org.apache.kafka.common.acl.AclBindingFilter) KafkaFuture(org.apache.kafka.common.KafkaFuture) AclFilterResponse(org.apache.kafka.common.requests.DeleteAclsResponse.AclFilterResponse) AclDeletionResult(org.apache.kafka.common.requests.DeleteAclsResponse.AclDeletionResult) ApiError(org.apache.kafka.common.requests.ApiError) AclBinding(org.apache.kafka.common.acl.AclBinding) Test(org.junit.Test)

Example 14 with AclBinding

use of org.apache.kafka.common.acl.AclBinding in project apache-kafka-on-k8s by banzaicloud.

the class RequestResponseTest method createDeleteAclsResponse.

private DeleteAclsResponse createDeleteAclsResponse() {
    List<AclFilterResponse> responses = new ArrayList<>();
    responses.add(new AclFilterResponse(Utils.mkSet(new AclDeletionResult(new AclBinding(new Resource(ResourceType.TOPIC, "mytopic3"), new AccessControlEntry("User:ANONYMOUS", "*", AclOperation.DESCRIBE, AclPermissionType.ALLOW))), new AclDeletionResult(new AclBinding(new Resource(ResourceType.TOPIC, "mytopic4"), new AccessControlEntry("User:ANONYMOUS", "*", AclOperation.DESCRIBE, AclPermissionType.DENY))))));
    responses.add(new AclFilterResponse(new ApiError(Errors.SECURITY_DISABLED, "No security"), Collections.<AclDeletionResult>emptySet()));
    return new DeleteAclsResponse(0, responses);
}
Also used : AclFilterResponse(org.apache.kafka.common.requests.DeleteAclsResponse.AclFilterResponse) ArrayList(java.util.ArrayList) AclDeletionResult(org.apache.kafka.common.requests.DeleteAclsResponse.AclDeletionResult) Resource(org.apache.kafka.common.resource.Resource) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) AclBinding(org.apache.kafka.common.acl.AclBinding)

Example 15 with AclBinding

use of org.apache.kafka.common.acl.AclBinding in project apache-kafka-on-k8s by banzaicloud.

the class RequestResponseTest method createCreateAclsRequest.

private CreateAclsRequest createCreateAclsRequest() {
    List<AclCreation> creations = new ArrayList<>();
    creations.add(new AclCreation(new AclBinding(new Resource(ResourceType.TOPIC, "mytopic"), new AccessControlEntry("User:ANONYMOUS", "127.0.0.1", AclOperation.READ, AclPermissionType.ALLOW))));
    creations.add(new AclCreation(new AclBinding(new Resource(ResourceType.GROUP, "mygroup"), new AccessControlEntry("User:ANONYMOUS", "*", AclOperation.WRITE, AclPermissionType.DENY))));
    return new CreateAclsRequest.Builder(creations).build();
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.kafka.common.resource.Resource) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) AclCreation(org.apache.kafka.common.requests.CreateAclsRequest.AclCreation) AclBinding(org.apache.kafka.common.acl.AclBinding)

Aggregations

AclBinding (org.apache.kafka.common.acl.AclBinding)28 AccessControlEntry (org.apache.kafka.common.acl.AccessControlEntry)16 ResourcePattern (org.apache.kafka.common.resource.ResourcePattern)14 ArrayList (java.util.ArrayList)11 List (java.util.List)7 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)5 AclBindingFilter (org.apache.kafka.common.acl.AclBindingFilter)5 Map (java.util.Map)4 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)4 ApiError (org.apache.kafka.common.requests.ApiError)4 Iterator (java.util.Iterator)3 LinkedList (java.util.LinkedList)3 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)3 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)3 DeleteAclsResponseData (org.apache.kafka.common.message.DeleteAclsResponseData)3 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)3 Errors (org.apache.kafka.common.protocol.Errors)3 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)3 PatternType (org.apache.kafka.common.resource.PatternType)3