Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ protected void internalDeleteTopicForcefully(boolean authoritative, boolean dele
}
}

private void revokePermissions(String topicUri, String role) {
private void revokePermissions(String topicUri, String role, boolean force) {
Policies policies;
try {
policies = namespaceResources().getPolicies(namespaceName)
Expand All @@ -323,7 +323,11 @@ private void revokePermissions(String topicUri, String role) {
|| !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);
throw new RestException(Status.PRECONDITION_FAILED, "Permissions are not set at the topic level");
if (force) {
return;
} else {
throw new RestException(Status.PRECONDITION_FAILED, "Permissions are not set at the topic level");
}
}
try {
// Write the new policies to metadata store
Expand All @@ -349,10 +353,10 @@ protected void internalRevokePermissionsOnTopic(String role) {
if (numPartitions > 0) {
for (int i = 0; i < numPartitions; i++) {
TopicName topicNamePartition = topicName.getPartition(i);
revokePermissions(topicNamePartition.toString(), role);
revokePermissions(topicNamePartition.toString(), role, true);
}
}
revokePermissions(topicName.toString(), role);
revokePermissions(topicName.toString(), role, false);
}

protected void internalCreateNonPartitionedTopic(boolean authoritative) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public void testProxyAuthorization() throws Exception {
* 2. Update the topic partition number to 4.
* 3. Use new producer/consumer with client role to process the topic.
* 4. Broker should authorize producer/consumer normally.
* 5. revoke produce/consumer permission of topic
* 6. new producer/consumer should not be authorized
* </pre>
*/
@Test
Expand Down Expand Up @@ -291,6 +293,26 @@ public void testUpdatePartitionNumAndReconnect() throws Exception {
Assert.assertEquals(messageSet, receivedMessageSet);
consumer.close();
producer.close();

// revoke produce/consume permission
admin.topics().revokePermissions(topicName, CLIENT_ROLE);

// produce/consume the topic should fail
try {
consumer = proxyClient.newConsumer()
.topic(topicName)
.subscriptionName(subscriptionName).subscribe();
Assert.fail("Should not pass");
} catch (PulsarClientException.AuthorizationException ex) {
// ok
}
try {
producer = proxyClient.newProducer(Schema.BYTES)
.topic(topicName).create();
Assert.fail("Should not pass");
} catch (PulsarClientException.AuthorizationException ex) {
// ok
}
log.info("-- Exiting {} test --", methodName);
}

Expand Down