mattisonchao commented on a change in pull request #13970:
URL: https://github.com/apache/pulsar/pull/13970#discussion_r794985610



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
##########
@@ -906,24 +907,42 @@ public void validateNamespaceOperation(NamespaceName 
namespaceName, NamespaceOpe
         return CompletableFuture.completedFuture(null);
     }
 
-    public void validateNamespacePolicyOperation(NamespaceName namespaceName,
-                                                 PolicyName policy,
-                                                 PolicyOperation operation) {
+    public CompletableFuture<Void> 
validateNamespacePolicyOperationAsync(NamespaceName namespaceName,
+                                                      PolicyName policy,
+                                                      PolicyOperation 
operation) {
         if (pulsar().getConfiguration().isAuthenticationEnabled()
-            && pulsar().getBrokerService().isAuthorizationEnabled()) {
+                && pulsar().getBrokerService().isAuthorizationEnabled()) {
             if (!isClientAuthenticated(clientAppId())) {
-                throw new RestException(Status.FORBIDDEN, "Need to 
authenticate to perform the request");
+                return FutureUtil.failedFuture(
+                    new RestException(Status.FORBIDDEN, "Need to authenticate 
to perform the request"));
             }
+            return pulsar().getBrokerService().getAuthorizationService()
+                    .allowNamespacePolicyOperationAsync(namespaceName, policy, 
operation,
+                            originalPrincipal(), clientAppId(), 
clientAuthData())
+                    .thenAccept(isAuthorized -> {
+                        if (!isAuthorized) {
+                            throw new RestException(Status.FORBIDDEN,
+                                    String.format("Unauthorized to 
validateNamespacePolicyOperation for"
+                                                    + " operation [%s] on 
namespace [%s] on policy [%s]",
+                                            operation.toString(), 
namespaceName, policy.toString()));
+                        }
+                    });
+        }
+        return CompletableFuture.completedFuture(null);
+    }
 
-            boolean isAuthorized = 
pulsar().getBrokerService().getAuthorizationService()
-                    .allowNamespacePolicyOperation(namespaceName, policy, 
operation,
-                        originalPrincipal(), clientAppId(), clientAuthData());
-
-            if (!isAuthorized) {
-                throw new RestException(Status.FORBIDDEN,
-                        String.format("Unauthorized to 
validateNamespacePolicyOperation for"
-                                        + " operation [%s] on namespace [%s] 
on policy [%s]",
-                                operation.toString(), namespaceName, 
policy.toString()));
+    public void validateNamespacePolicyOperation(NamespaceName namespaceName,
+                                                 PolicyName policy,
+                                                 PolicyOperation operation) {
+        try {
+            validateNamespacePolicyOperationAsync(namespaceName, policy, 
operation)
+                    .get(namespaceResources().getOperationTimeoutSec(), 
SECONDS);
+        } catch (InterruptedException | ExecutionException | TimeoutException 
ex) {
+            Throwable realCause = FutureUtil.unwrapCompletionException(ex);
+            if (realCause instanceof WebApplicationException) {
+                throw (WebApplicationException) realCause;

Review comment:
       This change will cause a compile error.




-- 
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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to