Search in sources :

Example 1 with AclBindingDeleteResult

use of org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult 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 2 with AclBindingDeleteResult

use of org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult in project kafka by apache.

the class ClusterMetadataAuthorizerTest method testDeleteAcls.

@Test
public void testDeleteAcls() throws Exception {
    MockAclMutator mutator = new MockAclMutator();
    MockClusterMetadataAuthorizer authorizer = new MockClusterMetadataAuthorizer();
    authorizer.setAclMutator(mutator);
    CompletableFuture<List<AclDeleteResult>> response = new CompletableFuture<>();
    response.complete(Arrays.asList(new AclDeleteResult(Collections.singleton(new AclBindingDeleteResult(TEST_BINDINGS.get(0)))), new AclDeleteResult(new InvalidRequestException("invalid"))));
    mutator.setDeleteAclsResponse(response);
    List<? extends CompletionStage<AclDeleteResult>> results = authorizer.deleteAcls(new MockAuthorizableRequestContext.Builder().build(), TEST_FILTERS);
    assertEquals(2, results.size());
    Collection<AclBindingDeleteResult> deleteResults0 = results.get(0).toCompletableFuture().get().aclBindingDeleteResults();
    assertEquals(1, deleteResults0.size());
    AclBindingDeleteResult deleteResult0 = deleteResults0.iterator().next();
    assertEquals(TEST_BINDINGS.get(0), deleteResult0.aclBinding());
    assertEquals(Optional.empty(), deleteResult0.exception());
    AclDeleteResult deleteResult1 = results.get(1).toCompletableFuture().get();
    assertEquals(0, deleteResult1.aclBindingDeleteResults().size());
    assertEquals(InvalidRequestException.class, deleteResult1.exception().get().getClass());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AclBindingDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult) List(java.util.List) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) InvalidRequestException(org.apache.kafka.common.errors.InvalidRequestException) Test(org.junit.jupiter.api.Test)

Aggregations

AclDeleteResult (org.apache.kafka.server.authorizer.AclDeleteResult)2 AclBindingDeleteResult (org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Uuid (org.apache.kafka.common.Uuid)1 AclBinding (org.apache.kafka.common.acl.AclBinding)1 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)1 RemoveAccessControlEntryRecord (org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord)1 StandardAcl (org.apache.kafka.metadata.authorizer.StandardAcl)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1 Test (org.junit.jupiter.api.Test)1