Search in sources :

Example 26 with AclBinding

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

the class AclControlManager method createAcls.

ControllerResult<List<AclCreateResult>> createAcls(List<AclBinding> acls) {
    List<AclCreateResult> results = new ArrayList<>(acls.size());
    List<ApiMessageAndVersion> records = new ArrayList<>(acls.size());
    for (AclBinding acl : acls) {
        try {
            validateNewAcl(acl);
        } catch (Throwable t) {
            ApiException e = (t instanceof ApiException) ? (ApiException) t : new UnknownServerException("Unknown error while trying to create ACL", t);
            results.add(new AclCreateResult(e));
            continue;
        }
        StandardAcl standardAcl = StandardAcl.fromAclBinding(acl);
        if (existingAcls.add(standardAcl)) {
            StandardAclWithId standardAclWithId = new StandardAclWithId(newAclId(), standardAcl);
            idToAcl.put(standardAclWithId.id(), standardAcl);
            records.add(new ApiMessageAndVersion(standardAclWithId.toRecord(), (short) 0));
        }
        results.add(AclCreateResult.SUCCESS);
    }
    return new ControllerResult<>(records, results, true);
}
Also used : StandardAclWithId(org.apache.kafka.metadata.authorizer.StandardAclWithId) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) AclBinding(org.apache.kafka.common.acl.AclBinding) StandardAcl(org.apache.kafka.metadata.authorizer.StandardAcl) AclCreateResult(org.apache.kafka.server.authorizer.AclCreateResult) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) ApiException(org.apache.kafka.common.errors.ApiException)

Example 27 with AclBinding

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

the class DeleteAclsResponse method aclBinding.

public static AclBinding aclBinding(DeleteAclsMatchingAcl matchingAcl) {
    ResourcePattern resourcePattern = new ResourcePattern(ResourceType.fromCode(matchingAcl.resourceType()), matchingAcl.resourceName(), PatternType.fromCode(matchingAcl.patternType()));
    AccessControlEntry accessControlEntry = new AccessControlEntry(matchingAcl.principal(), matchingAcl.host(), AclOperation.fromCode(matchingAcl.operation()), AclPermissionType.fromCode(matchingAcl.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 28 with AclBinding

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

the class DescribeAclsResponse method aclBindings.

private static Stream<AclBinding> aclBindings(DescribeAclsResource resource) {
    return resource.acls().stream().map(acl -> {
        ResourcePattern pattern = new ResourcePattern(ResourceType.fromCode(resource.resourceType()), resource.resourceName(), PatternType.fromCode(resource.patternType()));
        AccessControlEntry entry = new AccessControlEntry(acl.principal(), acl.host(), AclOperation.fromCode(acl.operation()), AclPermissionType.fromCode(acl.permissionType()));
        return new AclBinding(pattern, entry);
    });
}
Also used : ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) 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