Search in sources :

Example 1 with AclDeleteResult

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);
}
Also used : Logger(org.slf4j.Logger) DeleteAclsMatchingAcl(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) LoggerFactory(org.slf4j.LoggerFactory) DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) AclOperation(org.apache.kafka.common.acl.AclOperation) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) DeleteAclsResponseData(org.apache.kafka.common.message.DeleteAclsResponseData) PatternType(org.apache.kafka.common.resource.PatternType) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) List(java.util.List) ResourceType(org.apache.kafka.common.resource.ResourceType) AclBinding(org.apache.kafka.common.acl.AclBinding) Map(java.util.Map) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Errors(org.apache.kafka.common.protocol.Errors) DeleteAclsFilterResult(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsFilterResult) DeleteAclsMatchingAcl(org.apache.kafka.common.message.DeleteAclsResponseData.DeleteAclsMatchingAcl)

Example 2 with AclDeleteResult

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) ApiException(org.apache.kafka.common.errors.ApiException)

Example 3 with AclDeleteResult

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);
}
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 4 with AclDeleteResult

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);
}
Also used : AclBindingFilter(org.apache.kafka.common.acl.AclBindingFilter) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult)

Example 5 with AclDeleteResult

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());
}
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)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 AclBinding (org.apache.kafka.common.acl.AclBinding)3 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)3 Test (org.junit.jupiter.api.Test)3 Endpoint (org.apache.kafka.common.Endpoint)2 AccessControlEntry (org.apache.kafka.common.acl.AccessControlEntry)2 AclBindingFilter (org.apache.kafka.common.acl.AclBindingFilter)2 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)2 ResourcePattern (org.apache.kafka.common.resource.ResourcePattern)2 AclBindingDeleteResult (org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult)2 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Uuid (org.apache.kafka.common.Uuid)1 AclOperation (org.apache.kafka.common.acl.AclOperation)1 AclPermissionType (org.apache.kafka.common.acl.AclPermissionType)1