use of org.apache.kafka.metadata.authorizer.StandardAclWithId in project kafka by apache.
the class AclsDelta method replay.
public void replay(AccessControlEntryRecord record) {
StandardAclWithId aclWithId = StandardAclWithId.fromRecord(record);
changes.put(aclWithId.id(), Optional.of(aclWithId.acl()));
}
use of org.apache.kafka.metadata.authorizer.StandardAclWithId in project kafka by apache.
the class AclControlManager method replay.
public void replay(AccessControlEntryRecord record, Optional<OffsetAndEpoch> snapshotId) {
StandardAclWithId aclWithId = StandardAclWithId.fromRecord(record);
idToAcl.put(aclWithId.id(), aclWithId.acl());
existingAcls.add(aclWithId.acl());
if (!snapshotId.isPresent()) {
authorizer.ifPresent(a -> {
a.addAcl(aclWithId.id(), aclWithId.acl());
});
}
}
use of org.apache.kafka.metadata.authorizer.StandardAclWithId 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());
}
use of org.apache.kafka.metadata.authorizer.StandardAclWithId 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);
}
use of org.apache.kafka.metadata.authorizer.StandardAclWithId in project kafka by apache.
the class AclsImage method write.
public void write(Consumer<List<ApiMessageAndVersion>> out) {
List<ApiMessageAndVersion> batch = new ArrayList<>();
for (Entry<Uuid, StandardAcl> entry : acls.entrySet()) {
StandardAclWithId aclWithId = new StandardAclWithId(entry.getKey(), entry.getValue());
batch.add(new ApiMessageAndVersion(aclWithId.toRecord(), (short) 0));
}
out.accept(batch);
}
Aggregations