abhishekagarwal87 commented on code in PR #17564:
URL: https://github.com/apache/druid/pull/17564#discussion_r1905088393


##########
server/src/main/java/org/apache/druid/server/security/AuthorizationUtils.java:
##########
@@ -181,54 +179,64 @@ public static Access authorizeAllResourceActions(
           resourceAction.getAction()
       );
       if (!access.isAllowed()) {
-        return access;
+        return AuthorizationResult.deny(access.getMessage());
       } else {
         resultCache.add(resourceAction);
+        if (resourceAction.getAction().equals(Action.READ)
+            && 
RESTRICTION_APPLICABLE_RESOURCE_TYPES.contains(resourceAction.getResource().getType()))
 {
+          policyFilters.put(resourceAction.getResource().getName(), 
access.getPolicy());
+        } else if (access.getPolicy().isPresent()) {
+          throw DruidException.defensive(
+              "Policy should only present when reading a table, but was 
present for %s",

Review Comment:
   ```suggestion
                 "Policy should only present when reading a table, but was 
present for a different kind of resource [%s]",
   ```



##########
server/src/main/java/org/apache/druid/server/security/AuthorizationUtils.java:
##########
@@ -181,54 +179,64 @@ public static Access authorizeAllResourceActions(
           resourceAction.getAction()
       );
       if (!access.isAllowed()) {
-        return access;
+        return AuthorizationResult.deny(access.getMessage());
       } else {
         resultCache.add(resourceAction);
+        if (resourceAction.getAction().equals(Action.READ)

Review Comment:
   please add comments to the logic. e.g. here we are are just checking if 
there is a read access on a restricted resource such as table but its difficult 
to tell that from this line of code. 



##########
extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/http/CatalogResource.java:
##########
@@ -581,13 +580,13 @@ private void authorizeTable(
 
   private void authorize(String resource, String key, Action action, 
HttpServletRequest request)
   {
-    final Access authResult = authorizeAccess(resource, key, action, request);
-    if (!authResult.isAllowed()) {
-      throw new ForbiddenException(authResult.toString());
-    }
+    final AuthorizationResult authResult = authorizeAccess(resource, key, 
action, request);
+    authResult.getPermissionErrorMessage(true).ifPresent(error -> {

Review Comment:
   its weird that we throw a 401 if there is a permission error message. There 
should be a function available in AuthorizationResult to directly return a 
boolean indicating whether user is authorized or not. 



##########
server/src/main/java/org/apache/druid/server/security/AuthorizationResult.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.security;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.query.filter.DimFilter;
+import org.apache.druid.query.filter.TrueDimFilter;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Stream;
+
+public class AuthorizationResult

Review Comment:
   I just came to this comment and had already added a comment about 
`getPermissionErrorMessage`. This method can exist but shouldn't be a 
substitute of checking the access. It seems hackish and that's the reaction I 
had as I started going through the code at the top. 



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to