Search in sources :

Example 1 with AclDescription

use of org.apache.kafka.common.message.DescribeAclsResponseData.AclDescription in project kafka by apache.

the class DescribeAclsResponse method aclsResources.

public static List<DescribeAclsResource> aclsResources(Collection<AclBinding> acls) {
    Map<ResourcePattern, List<AccessControlEntry>> patternToEntries = new HashMap<>();
    for (AclBinding acl : acls) {
        patternToEntries.computeIfAbsent(acl.pattern(), v -> new ArrayList<>()).add(acl.entry());
    }
    List<DescribeAclsResource> resources = new ArrayList<>(patternToEntries.size());
    for (Entry<ResourcePattern, List<AccessControlEntry>> entry : patternToEntries.entrySet()) {
        ResourcePattern key = entry.getKey();
        List<AclDescription> aclDescriptions = new ArrayList<>();
        for (AccessControlEntry ace : entry.getValue()) {
            AclDescription ad = new AclDescription().setHost(ace.host()).setOperation(ace.operation().code()).setPermissionType(ace.permissionType().code()).setPrincipal(ace.principal());
            aclDescriptions.add(ad);
        }
        DescribeAclsResource dar = new DescribeAclsResource().setResourceName(key.name()).setPatternType(key.patternType().code()).setResourceType(key.resourceType().code()).setAcls(aclDescriptions);
        resources.add(dar);
    }
    return resources;
}
Also used : DescribeAclsResponseData(org.apache.kafka.common.message.DescribeAclsResponseData) Collection(java.util.Collection) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) AclPermissionType(org.apache.kafka.common.acl.AclPermissionType) HashMap(java.util.HashMap) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) AclOperation(org.apache.kafka.common.acl.AclOperation) DescribeAclsResource(org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) PatternType(org.apache.kafka.common.resource.PatternType) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) List(java.util.List) Stream(java.util.stream.Stream) ResourceType(org.apache.kafka.common.resource.ResourceType) AclDescription(org.apache.kafka.common.message.DescribeAclsResponseData.AclDescription) AclBinding(org.apache.kafka.common.acl.AclBinding) Map(java.util.Map) Entry(java.util.Map.Entry) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Errors(org.apache.kafka.common.protocol.Errors) Optional(java.util.Optional) DescribeAclsResource(org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource) HashMap(java.util.HashMap) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) ArrayList(java.util.ArrayList) AccessControlEntry(org.apache.kafka.common.acl.AccessControlEntry) ArrayList(java.util.ArrayList) List(java.util.List) AclBinding(org.apache.kafka.common.acl.AclBinding) AclDescription(org.apache.kafka.common.message.DescribeAclsResponseData.AclDescription)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 AccessControlEntry (org.apache.kafka.common.acl.AccessControlEntry)1 AclBinding (org.apache.kafka.common.acl.AclBinding)1 AclOperation (org.apache.kafka.common.acl.AclOperation)1 AclPermissionType (org.apache.kafka.common.acl.AclPermissionType)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 DescribeAclsResponseData (org.apache.kafka.common.message.DescribeAclsResponseData)1 AclDescription (org.apache.kafka.common.message.DescribeAclsResponseData.AclDescription)1 DescribeAclsResource (org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource)1 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1