use of org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource in project kafka by apache.
the class DescribeAclsResponseTest method shouldRoundTripV0.
@Test
public void shouldRoundTripV0() {
List<DescribeAclsResource> resources = Arrays.asList(LITERAL_ACL1, LITERAL_ACL2);
final DescribeAclsResponse original = buildResponse(10, Errors.NONE, resources);
final ByteBuffer buffer = original.serialize(V0);
final DescribeAclsResponse result = DescribeAclsResponse.parse(buffer, V0);
assertResponseEquals(original, result);
final DescribeAclsResponse result2 = buildResponse(10, Errors.NONE, DescribeAclsResponse.aclsResources(DescribeAclsResponse.aclBindings(resources)));
assertResponseEquals(original, result2);
}
use of org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource 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;
}
use of org.apache.kafka.common.message.DescribeAclsResponseData.DescribeAclsResource in project kafka by apache.
the class DescribeAclsResponseTest method shouldRoundTripV1.
@Test
public void shouldRoundTripV1() {
List<DescribeAclsResource> resources = Arrays.asList(LITERAL_ACL1, PREFIXED_ACL1);
final DescribeAclsResponse original = buildResponse(100, Errors.NONE, resources);
final ByteBuffer buffer = original.serialize(V1);
final DescribeAclsResponse result = DescribeAclsResponse.parse(buffer, V1);
assertResponseEquals(original, result);
final DescribeAclsResponse result2 = buildResponse(100, Errors.NONE, DescribeAclsResponse.aclsResources(DescribeAclsResponse.aclBindings(resources)));
assertResponseEquals(original, result2);
}
Aggregations