Copilot commented on code in PR #10982:
URL: https://github.com/apache/gravitino/pull/10982#discussion_r3201758479


##########
server/src/main/java/org/apache/gravitino/server/web/rest/ViewOperations.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.gravitino.server.web.rest;
+
+import static org.apache.gravitino.dto.util.DTOConverters.fromDTOs;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.catalog.ViewDispatcher;
+import org.apache.gravitino.dto.requests.ViewCreateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdatesRequest;
+import org.apache.gravitino.dto.responses.DropResponse;
+import org.apache.gravitino.dto.responses.EntityListResponse;
+import org.apache.gravitino.dto.responses.ViewResponse;
+import org.apache.gravitino.dto.util.DTOConverters;
+import org.apache.gravitino.metrics.MetricNames;
+import org.apache.gravitino.rel.View;
+import org.apache.gravitino.rel.ViewChange;
+import org.apache.gravitino.server.web.Utils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/views")
+public class ViewOperations {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ViewOperations.class);
+
+  private final ViewDispatcher dispatcher;
+
+  @Context private HttpServletRequest httpRequest;
+
+  @Inject
+  public ViewOperations(ViewDispatcher dispatcher) {
+    this.dispatcher = dispatcher;
+  }
+
+  @GET
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "list-view." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "list-view", absolute = true)
+  public Response listViews(
+      @PathParam("metalake") String metalake,
+      @PathParam("catalog") String catalog,
+      @PathParam("schema") String schema) {
+    LOG.info("Received list views request for schema: {}.{}.{}", metalake, 
catalog, schema);
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            Namespace viewNS = NamespaceUtil.ofView(metalake, catalog, schema);
+            NameIdentifier[] idents = dispatcher.listViews(viewNS);
+            Response response = Utils.ok(new EntityListResponse(idents));
+            LOG.info(
+                "List {} views under schema: {}.{}.{}", idents.length, 
metalake, catalog, schema);
+            return response;
+          });

Review Comment:
   ViewOperations currently has no authorization enforcement on this endpoint 
(no `@AuthorizationExpression` / @AuthorizationMetadata) and it returns the 
full dispatcher.listViews() result without filtering. Other REST resources 
(e.g., TableOperations.listTables) enforce LOAD_SCHEMA_AUTHORIZATION_EXPRESSION 
and then filter the returned identifiers with MetadataAuthzHelper + 
AuthorizationExpressionConstants.FILTER_VIEW_AUTHORIZATION_EXPRESSION; views 
should follow the same pattern to avoid leaking view names when authorization 
is enabled.



##########
server/src/main/java/org/apache/gravitino/server/web/rest/ViewOperations.java:
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.gravitino.server.web.rest;
+
+import static org.apache.gravitino.dto.util.DTOConverters.fromDTOs;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
+import org.apache.gravitino.catalog.ViewDispatcher;
+import org.apache.gravitino.dto.requests.ViewCreateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdatesRequest;
+import org.apache.gravitino.dto.responses.DropResponse;
+import org.apache.gravitino.dto.responses.EntityListResponse;
+import org.apache.gravitino.dto.responses.ViewResponse;
+import org.apache.gravitino.dto.util.DTOConverters;
+import org.apache.gravitino.metrics.MetricNames;
+import org.apache.gravitino.rel.View;
+import org.apache.gravitino.rel.ViewChange;
+import org.apache.gravitino.server.web.Utils;
+import org.apache.gravitino.utils.NameIdentifierUtil;
+import org.apache.gravitino.utils.NamespaceUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/views")
+public class ViewOperations {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ViewOperations.class);
+
+  private final ViewDispatcher dispatcher;
+
+  @Context private HttpServletRequest httpRequest;
+
+  @Inject
+  public ViewOperations(ViewDispatcher dispatcher) {
+    this.dispatcher = dispatcher;
+  }
+
+  @GET
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "list-view." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "list-view", absolute = true)
+  public Response listViews(
+      @PathParam("metalake") String metalake,
+      @PathParam("catalog") String catalog,
+      @PathParam("schema") String schema) {
+    LOG.info("Received list views request for schema: {}.{}.{}", metalake, 
catalog, schema);
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            Namespace viewNS = NamespaceUtil.ofView(metalake, catalog, schema);
+            NameIdentifier[] idents = dispatcher.listViews(viewNS);
+            Response response = Utils.ok(new EntityListResponse(idents));
+            LOG.info(
+                "List {} views under schema: {}.{}.{}", idents.length, 
metalake, catalog, schema);
+            return response;
+          });
+
+    } catch (Exception e) {
+      return ExceptionHandlers.handleViewException(OperationType.LIST, "", 
schema, e);
+    }
+  }
+
+  @POST
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "create-view." + MetricNames.HTTP_PROCESS_DURATION, absolute = 
true)
+  @ResponseMetered(name = "create-view", absolute = true)
+  public Response createView(
+      @PathParam("metalake") String metalake,
+      @PathParam("catalog") String catalog,
+      @PathParam("schema") String schema,
+      ViewCreateRequest request) {
+    LOG.info(
+        "Received create view request: {}.{}.{}.{}", metalake, catalog, 
schema, request.getName());
+    try {
+      return Utils.doAs(

Review Comment:
   All mutating/view-specific endpoints here (create/load/alter/drop) are 
missing the authorization annotations used elsewhere in the REST layer (e.g., 
`@AuthorizationExpression` plus `@AuthorizationMetadata` on path params). 
Without them, authorization will be bypassed when ENABLE_AUTHORIZATION=true. 
Please add the appropriate expressions (e.g., 
LOAD_VIEW_AUTHORIZATION_EXPRESSION for load, CREATE_VIEW/owner-based checks for 
create/alter/drop) and annotate metalake/catalog/schema/view path params with 
the corresponding EntityType metadata.



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