use of org.apache.kafka.server.authorizer.AclDeleteResult in project kafka by apache.
the class DeleteAclsResponse method filterResult.
public static DeleteAclsFilterResult filterResult(AclDeleteResult result) {
ApiError error = result.exception().map(e -> ApiError.fromThrowable(e)).orElse(ApiError.NONE);
List<DeleteAclsMatchingAcl> matchingAcls = result.aclBindingDeleteResults().stream().map(DeleteAclsResponse::matchingAcl).collect(Collectors.toList());
return new DeleteAclsFilterResult().setErrorCode(error.error().code()).setErrorMessage(error.message()).setMatchingAcls(matchingAcls);
}
use of org.apache.kafka.server.authorizer.AclDeleteResult in project kafka by apache.
the class ClusterMetadataAuthorizer method deleteAcls.
/**
* Delete ACLs based on filters. This function must be called on the active
* controller, or else the futures will fail with NOT_CONTROLLER.
*
* @param requestContext The request context.
* @param filters The ACL filters.
*
* @return a list of futures, one per input acl filter. Each future will be completed
* once the relevant deleteAcls have been called on the controller (if any), and th
* ACL deletions have been persisted to the cluster metadata log (if any).
*/
default List<? extends CompletionStage<AclDeleteResult>> deleteAcls(AuthorizableRequestContext requestContext, List<AclBindingFilter> filters) {
List<CompletableFuture<AclDeleteResult>> futures = new ArrayList<>(filters.size());
AclMutator aclMutator = aclMutatorOrException();
filters.forEach(b -> futures.add(new CompletableFuture<>()));
aclMutator.deleteAcls(filters).whenComplete((results, throwable) -> {
if (throwable == null && results.size() != futures.size()) {
throwable = new UnknownServerException("Invalid size " + "of result set from controller. Expected " + futures.size() + "; got " + results.size());
}
if (throwable == null) {
for (int i = 0; i < futures.size(); i++) {
futures.get(i).complete(results.get(i));
}
} else {
for (CompletableFuture<AclDeleteResult> future : futures) {
ApiException e = (throwable instanceof ApiException) ? (ApiException) throwable : ApiError.fromThrowable(throwable).exception();
future.complete(new AclDeleteResult(e));
}
}
});
return futures;
}
use of org.apache.kafka.server.authorizer.AclDeleteResult 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 in project kafka by apache.
the class AclControlManager method deleteAcls.
ControllerResult<List<AclDeleteResult>> deleteAcls(List<AclBindingFilter> filters) {
List<AclDeleteResult> results = new ArrayList<>();
List<ApiMessageAndVersion> records = new ArrayList<>();
for (AclBindingFilter filter : filters) {
try {
validateFilter(filter);
AclDeleteResult result = deleteAclsForFilter(filter, records);
results.add(result);
} catch (Throwable e) {
results.add(new AclDeleteResult(ApiError.fromThrowable(e).exception()));
}
}
return ControllerResult.atomicOf(records, results);
}
use of org.apache.kafka.server.authorizer.AclDeleteResult 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