lasdf1234 commented on code in PR #10971:
URL: https://github.com/apache/gravitino/pull/10971#discussion_r3213110680


##########
server/src/main/java/org/apache/gravitino/server/web/rest/IdpGroupOperations.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.gravitino.server.web.rest;
+
+import com.codahale.metrics.annotation.ResponseMetered;
+import com.codahale.metrics.annotation.Timed;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+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.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import org.apache.gravitino.authorization.IdpGroupManager;
+import org.apache.gravitino.dto.requests.CreateGroupRequest;
+import org.apache.gravitino.dto.requests.UpdateGroupUsersRequest;
+import org.apache.gravitino.dto.responses.IdpGroupResponse;
+import org.apache.gravitino.dto.responses.RemoveResponse;
+import org.apache.gravitino.metrics.MetricNames;
+import org.apache.gravitino.server.web.Utils;
+
+@Path("/idp/groups")
+public class IdpGroupOperations {
+
+  private final IdpGroupManager groupManager;
+
+  @Context private HttpServletRequest httpRequest;
+
+  public IdpGroupOperations() {
+    this(IdpGroupManager.fromEnvironment());
+  }
+
+  IdpGroupOperations(IdpGroupManager groupManager) {
+    this.groupManager = groupManager;
+  }
+
+  @GET
+  @Path("{group}")
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "get-idp-group." + MetricNames.HTTP_PROCESS_DURATION, absolute 
= true)
+  @ResponseMetered(name = "get-idp-group", absolute = true)
+  public Response getGroup(@PathParam("group") String group) {
+    try {
+      return Utils.doAs(
+          httpRequest, () -> Utils.ok(new 
IdpGroupResponse(groupManager.getGroup(group))));
+    } catch (Exception e) {
+      return ExceptionHandlers.handleGroupException(OperationType.GET, group, 
"", e);
+    }
+  }
+
+  @POST
+  @Produces("application/vnd.gravitino.v1+json")
+  @Timed(name = "add-idp-group." + MetricNames.HTTP_PROCESS_DURATION, absolute 
= true)
+  @ResponseMetered(name = "add-idp-group", absolute = true)
+  public Response addGroup(CreateGroupRequest request) {
+    try {
+      return Utils.doAs(
+          httpRequest,
+          () -> {
+            request.validate();
+            return Utils.ok(new 
IdpGroupResponse(groupManager.createGroup(request.getGroup())));
+          });
+    } catch (Exception e) {
+      return ExceptionHandlers.handleGroupException(OperationType.ADD, 
request.getGroup(), "", e);
+    }

Review Comment:
   Fixed. `IdpGroupOperations#addGroup` now null-checks the request before 
reading it and uses a safe `group` value in the catch path, so deserialization 
failures no longer risk a secondary NPE.



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