frankjkelly commented on a change in pull request #7523:
URL: https://github.com/apache/pulsar/pull/7523#discussion_r479665361



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
##########
@@ -846,4 +847,36 @@ public void validateNamespacePolicyOperation(NamespaceName 
namespaceName,
             }
         }
     }
+
+    public void validateTopicPolicyOperation(TopicName topicName, PolicyName 
policy, PolicyOperation operation) {
+        if (pulsar().getConfiguration().isAuthenticationEnabled() && 
pulsar().getBrokerService().isAuthorizationEnabled()) {
+            if (!isClientAuthenticated(clientAppId())) {
+                throw new RestException(Status.FORBIDDEN, "Need to 
authenticate to perform the request");

Review comment:
       Probably should return `Status.UNAUTHORIZED` rather than 
`Status.FORBIDDEN` to avoid confusion?

##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
##########
@@ -846,4 +847,36 @@ public void validateNamespacePolicyOperation(NamespaceName 
namespaceName,
             }
         }
     }
+
+    public void validateTopicPolicyOperation(TopicName topicName, PolicyName 
policy, PolicyOperation operation) {
+        if (pulsar().getConfiguration().isAuthenticationEnabled() && 
pulsar().getBrokerService().isAuthorizationEnabled()) {
+            if (!isClientAuthenticated(clientAppId())) {
+                throw new RestException(Status.FORBIDDEN, "Need to 
authenticate to perform the request");
+            }
+
+            Boolean isAuthorized = 
pulsar().getBrokerService().getAuthorizationService()
+                    .allowTopicPolicyOperation(topicName, policy, operation, 
originalPrincipal(), clientAppId(), clientAuthData());
+
+            if (!isAuthorized) {
+                throw new RestException(Status.FORBIDDEN, 
String.format("Unauthorized to validateTopicPolicyOperation for" +
+                        " operation [%s] on topic [%s] on policy [%s]", 
operation.toString(), topicName, policy.toString()));
+            }
+        }
+    }
+
+    public void validateTopicOperation(TopicName topicName, TopicOperation 
operation) {
+        if (pulsar().getConfiguration().isAuthenticationEnabled() && 
pulsar().getBrokerService().isAuthorizationEnabled()) {
+            if (!isClientAuthenticated(clientAppId())) {
+                throw new RestException(Status.UNAUTHORIZED, "Need to 
authenticate to perform the request");

Review comment:
       Same as above?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to