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);
}
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());
}
Aggregations