Search in sources :

Example 1 with RemoveAccessControlEntryRecord

use of org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord in project kafka by apache.

the class AclControlManagerTest method testAddAndDelete.

@Test
public void testAddAndDelete() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    AclControlManager manager = new AclControlManager(snapshotRegistry, Optional.empty());
    MockClusterMetadataAuthorizer authorizer = new MockClusterMetadataAuthorizer();
    authorizer.loadSnapshot(manager.idToAcl());
    manager.replay(StandardAclWithIdTest.TEST_ACLS.get(0).toRecord(), Optional.empty());
    assertEquals(new ApiMessageAndVersion(TEST_ACLS.get(0).toRecord(), (short) 0), manager.iterator(Long.MAX_VALUE).next().get(0));
    manager.replay(new RemoveAccessControlEntryRecord().setId(TEST_ACLS.get(0).id()), Optional.empty());
    assertFalse(manager.iterator(Long.MAX_VALUE).hasNext());
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) LogContext(org.apache.kafka.common.utils.LogContext) RemoveAccessControlEntryRecord(org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord) StandardAclWithIdTest(org.apache.kafka.metadata.authorizer.StandardAclWithIdTest) StandardAclTest(org.apache.kafka.metadata.authorizer.StandardAclTest) Test(org.junit.jupiter.api.Test)

Example 2 with RemoveAccessControlEntryRecord

use of org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord 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)

Aggregations

RemoveAccessControlEntryRecord (org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord)2 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)2 ArrayList (java.util.ArrayList)1 Uuid (org.apache.kafka.common.Uuid)1 AclBinding (org.apache.kafka.common.acl.AclBinding)1 LogContext (org.apache.kafka.common.utils.LogContext)1 StandardAcl (org.apache.kafka.metadata.authorizer.StandardAcl)1 StandardAclTest (org.apache.kafka.metadata.authorizer.StandardAclTest)1 StandardAclWithIdTest (org.apache.kafka.metadata.authorizer.StandardAclWithIdTest)1 AclDeleteResult (org.apache.kafka.server.authorizer.AclDeleteResult)1 AclBindingDeleteResult (org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult)1 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)1 Test (org.junit.jupiter.api.Test)1