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


##########
server-common/src/main/java/org/apache/gravitino/server/authentication/AuthenticatorFactory.java:
##########
@@ -32,11 +32,12 @@
 public class AuthenticatorFactory {
 
   private static final Logger LOG = 
LoggerFactory.getLogger(AuthenticatorFactory.class);
-
   public static final ImmutableMap<String, String> AUTHENTICATORS =
       ImmutableMap.of(
           AuthenticatorType.SIMPLE.name().toLowerCase(),
           SimpleAuthenticator.class.getCanonicalName(),
+          AuthenticatorType.BASIC.name().toLowerCase(),
+          SimpleAuthenticator.class.getCanonicalName(),
           AuthenticatorType.OAUTH.name().toLowerCase(),

Review Comment:
   `AuthenticatorType.BASIC` is currently mapped to `SimpleAuthenticator`, 
which does not validate credentials and even allows missing/invalid Basic 
headers by returning the anonymous principal. This makes `basic` effectively 
equivalent to (or weaker than) `simple`. Map `basic` to an authenticator that 
verifies username/password (or at minimum rejects null/non-Basic tokens).



##########
common/src/main/java/org/apache/gravitino/dto/requests/CreateUserRequest.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.dto.requests;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.ToString;
+import lombok.extern.jackson.Jacksonized;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.rest.RESTRequest;
+
+/** Represents a request to create a built-in IdP user. */
+@Getter
+@EqualsAndHashCode
+@ToString
+@Builder
+@Jacksonized
+public class CreateUserRequest implements RESTRequest {
+
+  @JsonProperty("user")
+  private final String user;
+
+  @JsonProperty("password")
+  private final String password;
+
+  /** Default constructor for CreateUserRequest. (Used for Jackson 
deserialization.) */
+  public CreateUserRequest() {
+    this(null, null);
+  }
+
+  /**
+   * Creates a new CreateUserRequest.
+   *
+   * @param user The user name of the built-in IdP user.
+   * @param password The password of the built-in IdP user.
+   */
+  public CreateUserRequest(String user, String password) {
+    super();
+    this.user = user;
+    this.password = password;
+  }
+
+  /**
+   * Validates the {@link CreateUserRequest} request.
+   *
+   * @throws IllegalArgumentException If the request is invalid, this 
exception is thrown.
+   */
+  @Override
+  public void validate() throws IllegalArgumentException {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(user), "\"user\" field is required and cannot 
be empty");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(password), "\"password\" field is required and 
cannot be empty");

Review Comment:
   `CreateUserRequest.validate()` only checks non-blank values, but server-side 
`IdpUserManager` enforces additional constraints (e.g., username cannot contain 
':' and password length must be 12–64). Consider enforcing the same constraints 
here so invalid requests fail early and consistently at the REST layer.



##########
common/src/main/java/org/apache/gravitino/dto/requests/ResetPasswordRequest.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.dto.requests;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.ToString;
+import lombok.extern.jackson.Jacksonized;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.rest.RESTRequest;
+
+/** Represents a request to reset a built-in IdP user password. */
+@Getter
+@EqualsAndHashCode
+@ToString
+@Builder
+@Jacksonized
+public class ResetPasswordRequest implements RESTRequest {
+
+  @JsonProperty("password")
+  private final String password;
+
+  /** Default constructor for ResetPasswordRequest. (Used for Jackson 
deserialization.) */
+  public ResetPasswordRequest() {
+    this(null);
+  }
+
+  /**
+   * Creates a new ResetPasswordRequest.
+   *
+   * @param password The new password of the built-in IdP user.
+   */
+  public ResetPasswordRequest(String password) {
+    super();
+    this.password = password;
+  }
+
+  /**
+   * Validates the {@link ResetPasswordRequest} request.
+   *
+   * @throws IllegalArgumentException If the request is invalid, this 
exception is thrown.
+   */
+  @Override
+  public void validate() throws IllegalArgumentException {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(password), "\"password\" field is required and 
cannot be empty");
+  }

Review Comment:
   `ResetPasswordRequest.validate()` only checks non-blank, but 
`IdpUserManager` enforces password length constraints (12–64). Consider 
validating the same constraints here so malformed requests fail early and 
consistently at the REST layer.



##########
server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java:
##########
@@ -576,6 +584,74 @@ public Response handle(OperationType op, String group, 
String metalake, Exceptio
     }
   }
 
+  private static class IdpUserExceptionHandler extends BaseExceptionHandler {
+
+    private static final ExceptionHandler INSTANCE = new 
IdpUserExceptionHandler();
+
+    private static String getUserErrorMsg(String user, String operation, 
String reason) {
+      return String.format(
+          "Failed to operate built-in IdP user %s operation [%s], reason [%s]",
+          user, operation, reason);
+    }
+
+    @Override
+    public Response handle(OperationType op, String user, String ignored, 
Exception e) {
+      String formatted = StringUtil.isBlank(user) ? "" : " [" + user + "]";
+      String errorMsg = getUserErrorMsg(formatted, op.name(), getErrorMsg(e));
+      LOG.warn(errorMsg, e);
+
+      if (e instanceof IllegalArgumentException) {
+        return Utils.illegalArguments(errorMsg, e);
+
+      } else if (e instanceof NotFoundException) {
+        return Utils.notFound(errorMsg, e);

Review Comment:
   `IdpUserExceptionHandler` doesn’t map `ForbiddenException` (service-admin 
enforcement), so those cases will incorrectly return 500. Add an explicit 
`ForbiddenException` branch (using `Utils.forbidden(...)`) consistent with 
other handlers in this file.



##########
server/src/main/java/org/apache/gravitino/server/web/rest/ExceptionHandlers.java:
##########
@@ -576,6 +584,74 @@ public Response handle(OperationType op, String group, 
String metalake, Exceptio
     }
   }
 
+  private static class IdpUserExceptionHandler extends BaseExceptionHandler {
+
+    private static final ExceptionHandler INSTANCE = new 
IdpUserExceptionHandler();
+
+    private static String getUserErrorMsg(String user, String operation, 
String reason) {
+      return String.format(
+          "Failed to operate built-in IdP user %s operation [%s], reason [%s]",
+          user, operation, reason);
+    }
+
+    @Override
+    public Response handle(OperationType op, String user, String ignored, 
Exception e) {
+      String formatted = StringUtil.isBlank(user) ? "" : " [" + user + "]";
+      String errorMsg = getUserErrorMsg(formatted, op.name(), getErrorMsg(e));
+      LOG.warn(errorMsg, e);
+
+      if (e instanceof IllegalArgumentException) {
+        return Utils.illegalArguments(errorMsg, e);
+
+      } else if (e instanceof NotFoundException) {
+        return Utils.notFound(errorMsg, e);
+
+      } else if (e instanceof UserAlreadyExistsException) {
+        return Utils.alreadyExists(errorMsg, e);
+
+      } else if (e instanceof NotInUseException) {
+        return Utils.notInUse(errorMsg, e);
+
+      } else {
+        return Utils.internalError(errorMsg, e);
+      }
+    }
+  }
+
+  private static class IdpGroupExceptionHandler extends BaseExceptionHandler {
+
+    private static final ExceptionHandler INSTANCE = new 
IdpGroupExceptionHandler();
+
+    private static String getGroupErrorMsg(String group, String operation, 
String reason) {
+      return String.format(
+          "Failed to operate built-in IdP group %s operation [%s], reason 
[%s]",
+          group, operation, reason);
+    }
+
+    @Override
+    public Response handle(OperationType op, String group, String ignored, 
Exception e) {
+      String formatted = StringUtil.isBlank(group) ? "" : " [" + group + "]";
+      String errorMsg = getGroupErrorMsg(formatted, op.name(), getErrorMsg(e));
+      LOG.warn(errorMsg, e);
+
+      if (e instanceof IllegalArgumentException) {
+        return Utils.illegalArguments(errorMsg, e);
+
+      } else if (e instanceof NotFoundException) {
+        return Utils.notFound(errorMsg, e);

Review Comment:
   `IdpGroupExceptionHandler` doesn’t map `ForbiddenException` / 
`UnsupportedOperationException` (e.g., delete without force when group has 
users), so these cases will incorrectly return 500. Add explicit branches 
(e.g., `Utils.forbidden(...)` / `Utils.unsupportedOperation(...)`) consistent 
with other handlers in this file.



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