Search in sources :

Example 1 with AccessControlEntryRecord

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

the class StandardAclWithIdTest method testToRecordRoundTrips.

@Test
public void testToRecordRoundTrips() {
    for (StandardAclWithId acl : TEST_ACLS) {
        AccessControlEntryRecord record = acl.toRecord();
        StandardAclWithId acl2 = StandardAclWithId.fromRecord(record);
        assertEquals(acl2, acl);
    }
}
Also used : AccessControlEntryRecord(org.apache.kafka.common.metadata.AccessControlEntryRecord) Test(org.junit.jupiter.api.Test)

Example 2 with AccessControlEntryRecord

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

the class AclControlManagerTest method testLoadSnapshot.

@Test
public void testLoadSnapshot() {
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    snapshotRegistry.getOrCreateSnapshot(0);
    AclControlManager manager = new AclControlManager(snapshotRegistry, Optional.empty());
    // Load TEST_ACLS into the AclControlManager.
    Set<ApiMessageAndVersion> loadedAcls = new HashSet<>();
    for (StandardAclWithId acl : TEST_ACLS) {
        AccessControlEntryRecord record = acl.toRecord();
        assertTrue(loadedAcls.add(new ApiMessageAndVersion(record, (short) 0)));
        manager.replay(acl.toRecord(), Optional.empty());
    }
    // Verify that the ACLs stored in the AclControlManager match the ones we expect.
    Set<ApiMessageAndVersion> foundAcls = new HashSet<>();
    for (Iterator<List<ApiMessageAndVersion>> iterator = manager.iterator(Long.MAX_VALUE); iterator.hasNext(); ) {
        for (ApiMessageAndVersion apiMessageAndVersion : iterator.next()) {
            assertTrue(foundAcls.add(apiMessageAndVersion));
        }
    }
    assertEquals(loadedAcls, foundAcls);
    // Once we complete the snapshot load, the ACLs should be reflected in the authorizer.
    MockClusterMetadataAuthorizer authorizer = new MockClusterMetadataAuthorizer();
    authorizer.loadSnapshot(manager.idToAcl());
    assertEquals(new HashSet<>(StandardAclTest.TEST_ACLS), new HashSet<>(authorizer.acls.values()));
    // Test reverting to an empty state and then completing the snapshot load without
    // setting an authorizer. This simulates the case where the user didn't configure
    // a cluster metadata authorizer.
    snapshotRegistry.revertToSnapshot(0);
    authorizer.loadSnapshot(manager.idToAcl());
    assertFalse(manager.iterator(Long.MAX_VALUE).hasNext());
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) StandardAclWithId(org.apache.kafka.metadata.authorizer.StandardAclWithId) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) RemoveAccessControlEntryRecord(org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord) AccessControlEntryRecord(org.apache.kafka.common.metadata.AccessControlEntryRecord) LogContext(org.apache.kafka.common.utils.LogContext) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StandardAclWithIdTest(org.apache.kafka.metadata.authorizer.StandardAclWithIdTest) StandardAclTest(org.apache.kafka.metadata.authorizer.StandardAclTest) Test(org.junit.jupiter.api.Test)

Aggregations

AccessControlEntryRecord (org.apache.kafka.common.metadata.AccessControlEntryRecord)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 RemoveAccessControlEntryRecord (org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord)1 LogContext (org.apache.kafka.common.utils.LogContext)1 StandardAclTest (org.apache.kafka.metadata.authorizer.StandardAclTest)1 StandardAclWithId (org.apache.kafka.metadata.authorizer.StandardAclWithId)1 StandardAclWithIdTest (org.apache.kafka.metadata.authorizer.StandardAclWithIdTest)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)1