Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][broker] fix can not revoke permission after update topic partition #17393

Merged
merged 2 commits into from
Sep 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix revoke permission of partition
  • Loading branch information
fanjianye committed Sep 1, 2022
commit e9842e03c0eb58d2aa9b01f10901405da024a8d2
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ protected void internalGrantPermissionsOnTopic(final AsyncResponse asyncResponse
});
}

private CompletableFuture<Void> revokePermissionsAsync(String topicUri, String role) {
private CompletableFuture<Void> revokePermissionsAsync(String topicUri, String role, boolean force) {
return namespaceResources().getPoliciesAsync(namespaceName).thenCompose(
policiesOptional -> {
Policies policies = policiesOptional.orElseThrow(() ->
Expand All @@ -354,8 +354,12 @@ private CompletableFuture<Void> revokePermissionsAsync(String topicUri, String r
|| !policies.auth_policies.getTopicAuthentication().get(topicUri).containsKey(role)) {
log.warn("[{}] Failed to revoke permission from role {} on topic: Not set at topic level {}",
clientAppId(), role, topicUri);
return FutureUtil.failedFuture(new RestException(Status.PRECONDITION_FAILED,
"Permissions are not set at the topic level"));
if (force) {
nodece marked this conversation as resolved.
Show resolved Hide resolved
return CompletableFuture.completedFuture(null);
} else {
return FutureUtil.failedFuture(new RestException(Status.PRECONDITION_FAILED,
"Permissions are not set at the topic level"));
}
}
// Write the new policies to metadata store
return namespaceResources().setPoliciesAsync(namespaceName, p -> {
Expand All @@ -381,10 +385,10 @@ protected void internalRevokePermissionsOnTopic(AsyncResponse asyncResponse, Str
for (int i = 0; i < numPartitions; i++) {
TopicName topicNamePartition = topicName.getPartition(i);
future = future.thenComposeAsync(unused ->
revokePermissionsAsync(topicNamePartition.toString(), role));
revokePermissionsAsync(topicNamePartition.toString(), role, true));
}
}
return future.thenComposeAsync(unused -> revokePermissionsAsync(topicName.toString(), role))
return future.thenComposeAsync(unused -> revokePermissionsAsync(topicName.toString(), role, false))
.thenAccept(unused -> asyncResponse.resume(Response.noContent().build()));
}))
).exceptionally(ex -> {
Expand Down