Copilot commented on code in PR #19234:
URL: https://github.com/apache/pinot/pull/19234#discussion_r3791394375


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/access/BaseBasicAuthAccessControl.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * 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.pinot.controller.api.access;
+
+import java.util.Objects;
+import java.util.Optional;
+import javax.ws.rs.NotAuthorizedException;
+import javax.ws.rs.core.HttpHeaders;
+import org.apache.pinot.core.auth.BasicAuthPrincipal;
+import org.apache.pinot.core.auth.TargetType;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+
+
+/// Shared controller BasicAuth policy, independent of how principals are 
loaded and credentials are verified.
+/// This class is stateless and thread-safe; subclass principal resolution 
must also be thread-safe.
+abstract class BaseBasicAuthAccessControl<P extends BasicAuthPrincipal> 
implements AccessControl {
+  @Override
+  public final boolean protectAnnotatedOnly() {
+    return false;
+  }
+
+  @Override
+  public final boolean hasAccess(String tableName, AccessType accessType, 
HttpHeaders httpHeaders,
+      String endpointUrl) {
+    String rawTableName = TableNameBuilder.extractRawTableName(tableName);
+    return getPrincipal(httpHeaders)
+        .filter(p -> p.hasTable(rawTableName) && 
p.hasPermission(Objects.toString(accessType))).isPresent();

Review Comment:
   Unauthenticated table-scoped requests still return `false` here, so 
`AccessControlUtils.validatePermission` converts missing, malformed, or 
incorrect credentials into 403. Cluster-scoped requests throw 
`NotAuthorizedException` and return 401, contradicting the PR's stated 401/403 
contract. Resolve the principal first and throw 
`NotAuthorizedException("Basic")` when absent, then evaluate table and CRUD 
permissions; update the table-status regression assertions for both BasicAuth 
implementations.



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