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


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/access/QueryAccessControlFactory.java:
##########
@@ -0,0 +1,64 @@
+/**
+ * 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.query.access;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.annotations.InterfaceAudience;
+import org.apache.pinot.spi.annotations.InterfaceStability;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.pinot.spi.utils.CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;
+import static 
org.apache.pinot.spi.utils.CommonConstants.Helix.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;
+
+
[email protected]
[email protected]
+public abstract class QueryAccessControlFactory {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(QueryAccessControlFactory.class);
+  void init(PinotConfiguration configuration) {

Review Comment:
   [nitpick] The 'init' method has package-private visibility, which may not be 
intended for an abstract factory class. Consider making it protected to allow 
subclasses to override it, or document the intended visibility.
   ```suggestion
     protected void init(PinotConfiguration configuration) {
   ```



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/access/QueryAccessControlFactory.java:
##########
@@ -0,0 +1,64 @@
+/**
+ * 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.query.access;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.annotations.InterfaceAudience;
+import org.apache.pinot.spi.annotations.InterfaceStability;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.pinot.spi.utils.CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;
+import static 
org.apache.pinot.spi.utils.CommonConstants.Helix.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;

Review Comment:
   The import references 'CommonConstants.Helix' but the constants are defined 
in 'CommonConstants.Instance'. This will cause a compilation error.
   ```suggestion
   import static 
org.apache.pinot.spi.utils.CommonConstants.Instance.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;
   import static 
org.apache.pinot.spi.utils.CommonConstants.Instance.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;
   ```



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/access/QueryAccessControlFactory.java:
##########
@@ -0,0 +1,64 @@
+/**
+ * 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.query.access;
+
+import javax.annotation.Nullable;
+import org.apache.pinot.spi.annotations.InterfaceAudience;
+import org.apache.pinot.spi.annotations.InterfaceStability;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.pinot.spi.utils.CommonConstants.Helix.CONFIG_OF_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;
+import static 
org.apache.pinot.spi.utils.CommonConstants.Helix.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;

Review Comment:
   The import references 'CommonConstants.Helix' but the constants are defined 
in 'CommonConstants.Instance'. This will cause a compilation error.
   ```suggestion
   import static 
org.apache.pinot.spi.utils.CommonConstants.Instance.DEFAULT_MULTI_STAGE_CHANNEL_ACCESS_CONTROL_FACTORY_CLASS;
   ```



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/access/AuthorizationInterceptor.java:
##########
@@ -0,0 +1,45 @@
+/**
+ * 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.query.access;
+
+import io.grpc.Metadata;
+import io.grpc.ServerCall;
+import io.grpc.ServerCallHandler;
+import io.grpc.ServerInterceptor;
+import io.grpc.Status;
+
+public class AuthorizationInterceptor implements ServerInterceptor {
+  private final QueryAccessControlFactory _accessControlFactory;
+
+  public AuthorizationInterceptor(QueryAccessControlFactory 
accessControlFactory) {
+    _accessControlFactory = accessControlFactory;
+  }
+
+  @Override
+  public <T, R> ServerCall.Listener<T> interceptCall(ServerCall<T, R> call, 
Metadata headers,
+      ServerCallHandler<T, R> next) {
+    if (!_accessControlFactory.create().hasAccess(call.getAttributes(), 
headers)) {

Review Comment:
   The access control instance is created on every request. Consider caching 
the instance if it's stateless, or creating it once in the constructor to avoid 
unnecessary object creation overhead.
   ```suggestion
     private final QueryAccessControl _accessControl;
   
     public AuthorizationInterceptor(QueryAccessControlFactory 
accessControlFactory) {
       _accessControlFactory = accessControlFactory;
       _accessControl = _accessControlFactory.create();
     }
   
     @Override
     public <T, R> ServerCall.Listener<T> interceptCall(ServerCall<T, R> call, 
Metadata headers,
         ServerCallHandler<T, R> next) {
       if (!_accessControl.hasAccess(call.getAttributes(), headers)) {
   ```



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