You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "lasdf1234 (via GitHub)" <gi...@apache.org> on 2026/06/08 08:20:41 UTC

[PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

lasdf1234 opened a new pull request, #11493:
URL: https://github.com/apache/gravitino/pull/11493

   ### What changes were proposed in this pull request?
   
   - Add 128-character length validation for IDP usernames and group names in `IdpCredentialValidator` before persistence.
   - Route group name validation through `AddGroupRequest.validate()` via `validateGroupName()`.
   - Add unit and integration tests for over-length username/group name requests (HTTP 400, `ILLEGAL_ARGUMENTS_CODE`).
   - Align IDP OpenAPI examples and responses with actual REST behavior (403, per-operation examples, descriptions).
   
   ### Why are the changes needed?
   
   When creating an IDP user or group with a name longer than 128 characters, the server previously hit the database constraint and returned HTTP 500 with internal DB error details exposed. Validation at the API layer returns HTTP 400 with a clear message instead.
   
   Fix: #11434
   
   ### Does this PR introduce _any_ user-facing change?
   
   1. `POST /api/idp/users` and `POST /api/idp/groups` now return HTTP 400 with `code: 1001` when the name exceeds 128 characters, instead of HTTP 500.
   2. IDP OpenAPI documentation updated for error/success examples and 403 responses.
   
   ### How was this patch tested?
   
   - `./gradlew spotlessApply`
   - `./gradlew :plugins:idp-basic:test -PskipITs -PskipDockerTests=true`
   - `./gradlew :docs:lintIdpOpenAPI`
   
   
   Made with [Cursor](https://cursor.com)


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on code in PR #11493:
URL: https://github.com/apache/gravitino/pull/11493#discussion_r3373007897


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/web/IdpRESTUtils.java:
##########
@@ -69,11 +69,10 @@ public static Response doAs(
 
   public static Response handleException(
       String resourceType, IdpOperationType op, String name, Exception e) {
-    String formatted = StringUtils.isBlank(name) ? "" : " [" + name + "]";
     String errorMsg =
         String.format(
-            "Failed to operate built-in IdP %s %s operation [%s], reason [%s]",
-            resourceType, formatted, op.name(), e.getMessage());
+            "Failed to operate built-in IdP %s [%s] operation [%s], reason [%s]",
+            resourceType, StringUtils.defaultString(name), op.name(), e.getMessage());

Review Comment:
   behaviour:
   null -> ""
   Other String -> Return as is.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11493:
URL: https://github.com/apache/gravitino/pull/11493#discussion_r3373141561


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/web/IdpRESTUtils.java:
##########
@@ -69,11 +69,10 @@ public static Response doAs(
 
   public static Response handleException(
       String resourceType, IdpOperationType op, String name, Exception e) {
-    String formatted = StringUtils.isBlank(name) ? "" : " [" + name + "]";
     String errorMsg =
         String.format(
-            "Failed to operate built-in IdP %s %s operation [%s], reason [%s]",
-            resourceType, formatted, op.name(), e.getMessage());
+            "Failed to operate built-in IdP %s [%s] operation [%s], reason [%s]",
+            resourceType, StringUtils.defaultString(name), op.name(), e.getMessage());

Review Comment:
   Thanks. Nice to know this point. We can use this to optimize our code.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11493:
URL: https://github.com/apache/gravitino/pull/11493#discussion_r3372793143


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/web/IdpRESTUtils.java:
##########
@@ -69,11 +69,10 @@ public static Response doAs(
 
   public static Response handleException(
       String resourceType, IdpOperationType op, String name, Exception e) {
-    String formatted = StringUtils.isBlank(name) ? "" : " [" + name + "]";
     String errorMsg =
         String.format(
-            "Failed to operate built-in IdP %s %s operation [%s], reason [%s]",
-            resourceType, formatted, op.name(), e.getMessage());
+            "Failed to operate built-in IdP %s [%s] operation [%s], reason [%s]",
+            resourceType, StringUtils.defaultString(name), op.name(), e.getMessage());

Review Comment:
   What's the behaviour of `StringUtils.defaultString`?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi merged PR #11493:
URL: https://github.com/apache/gravitino/pull/11493


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on PR #11493:
URL: https://github.com/apache/gravitino/pull/11493#issuecomment-4646749915

   @roryqi Could you help me to review.THX.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #11493:
URL: https://github.com/apache/gravitino/pull/11493#discussion_r3372770551


##########
docs/open-api/idp/idp.yaml:
##########
@@ -465,7 +490,16 @@ components:
         "usersToRemove": ["carol"]
       }
 
-    IdpUserResponse:
+    IdpUserAddResponse:

Review Comment:
   Why do we return the response? Is it aligned to your implementation?Doest it meet our API design convention?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11493:
URL: https://github.com/apache/gravitino/pull/11493#issuecomment-4648023658

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|67.04% **`+0.01%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|86.36%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.8%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.42%|:red_circle:|
   |catalog-fileset|80.35%|:green_circle:|
   |catalog-glue|67.46%|:green_circle:|
   |catalog-hive|79.35%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|45.31%|:green_circle:|
   |catalog-jdbc-doris|80.28%|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|58.53%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.86%|:green_circle:|
   |catalog-lakehouse-paimon|79.29%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|77.91%|:green_circle:|
   |common|50.17%|:green_circle:|
   |core|82.51%|:green_circle:|
   |filesystem-hadoop3|76.97%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|46.3%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.39%|:red_circle:|
   |hive-metastore-common|53.9%|:green_circle:|
   |iceberg-common|57.41%|:green_circle:|
   |iceberg-rest-server|73.8%|:green_circle:|
   |idp-basic|86.07% **`+0.02%`**|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.81%|:red_circle:|
   |lance-rest-server|60.54%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.95%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.73%|:green_circle:|
   |server-common|73.28%|:green_circle:|
   |spark|29.85%|:red_circle:|
   |spark-common|41.01%|:green_circle:|
   |trino-connector|39.97%|:red_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |idp-basic|[IdpCredentialValidator.java](https://github.com/lasdf1234/gravitino/blob/28f07c04802f318a7ee4a89488b2190178c7bfc2/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/basic/IdpCredentialValidator.java)|100.0%|:green_circle:|
   ||[AddGroupRequest.java](https://github.com/lasdf1234/gravitino/blob/28f07c04802f318a7ee4a89488b2190178c7bfc2/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/dto/requests/AddGroupRequest.java)|90.91%|:green_circle:|
   ||[IdpRESTUtils.java](https://github.com/lasdf1234/gravitino/blob/28f07c04802f318a7ee4a89488b2190178c7bfc2/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/web/IdpRESTUtils.java)|79.49%|:green_circle:|
   
   </details>


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11434] fix(idp): Validate name length at API layer before DB persist [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on code in PR #11493:
URL: https://github.com/apache/gravitino/pull/11493#discussion_r3373015537


##########
docs/open-api/idp/idp.yaml:
##########
@@ -465,7 +490,16 @@ components:
         "usersToRemove": ["carol"]
       }
 
-    IdpUserResponse:
+    IdpUserAddResponse:

Review Comment:
   IdpUserAddResponse is only an OpenAPI example name; the response schema is still IdpUserResponse.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org