Skip to content

Commit

Permalink
fix(topic): fix topic data copy authorization check (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisSouquiere authored Jan 24, 2025
1 parent c6b5df1 commit 7e5a54f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/akhq/controllers/TopicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,27 +608,27 @@ public List<RecordRepository.TimeOffset> offsetsStart(String cluster, String top


@AKHQSecured(resource = Role.Resource.TOPIC_DATA, action = Role.Action.CREATE)
@Post("api/{fromCluster}/topic/{fromTopicName}/copy/{toCluster}/topic/{toTopicName}")
@Post("api/{cluster}/topic/{fromTopicName}/copy/{toCluster}/topic/{toTopicName}")
@Operation(tags = {"topic data"}, summary = "Copy from a topic to another topic")
public RecordRepository.CopyResult copy(
HttpRequest<?> request,
String fromCluster,
String cluster,
String fromTopicName,
String toCluster,
String toTopicName,
@Body List<OffsetCopy> offsets
) throws ExecutionException, InterruptedException {
checkIfClusterAndResourceAllowed(fromCluster, fromTopicName);
checkIfClusterAndResourceAllowed(cluster, fromTopicName);
checkIfClusterAndResourceAllowed(toCluster, toTopicName);

Topic fromTopic = this.topicRepository.findByName(fromCluster, fromTopicName);
Topic fromTopic = this.topicRepository.findByName(cluster, fromTopicName);
Topic toTopic = this.topicRepository.findByName(toCluster, toTopicName);

if (!CollectionUtils.isNotEmpty(offsets)) {
throw new IllegalArgumentException("Empty collections");
}

if (fromCluster.equals(toCluster) && fromTopicName.equals(toTopicName)) {
if (cluster.equals(toCluster) && fromTopicName.equals(toTopicName)) {
// #745 Prevent endless loop when copying topic onto itself; Use intermediate copy topic for duplication
throw new IllegalArgumentException("Can not copy topic to itself");
}
Expand All @@ -641,7 +641,7 @@ public RecordRepository.CopyResult copy(
.collect(Collectors.joining("_"));

RecordRepository.Options options = dataSearchOptions(
fromCluster,
cluster,
fromTopicName,
Optional.ofNullable(StringUtils.isNotEmpty(offsetsList) ? offsetsList : null),
Optional.empty(),
Expand Down

0 comments on commit 7e5a54f

Please sign in to comment.