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/08/03 09:16:59 UTC

[PR] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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

   ### What changes were proposed in this pull request?
   
   - Expose `id()` on `User` and align DTO / listener info
   - Add relational lookup/update/delete by metalake + gravitino user id
   - Add `SupportsIdOperations` and wire JDBC / in-memory entity stores for USER
   - Add AccessControlDispatcher by-id user APIs (get/remove/enable/disable;
     updateUserExternalId) plus hook/event dispatchers
   
   ### Why are the changes needed?
   
   SCIM push needs a stable server-assigned id as the user resource key, separate
   from optional mutable `externalId`. Core currently only keys users by name or
   externalId.
   
   Fix: #12330
   
   ### Does this PR introduce _any_ user-facing change?
   
   - New `User.id()` on the public API
   - New AccessControlDispatcher user methods keyed by gravitino id
   - Existing by-name and by-externalId APIs unchanged
   
   ### How was this patch tested?
   
   - `TestAccessControlManager.testUserById`
   - Existing access-control unit tests
   
   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] [#12330] feat(core): Add user by-id lookup, enable/disable, delete, and update-external-id APIs [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/Entity.java:
##########
@@ -41,6 +41,17 @@ public interface Entity extends Serializable {
   /** The user schema name in the system catalog. */
   String USER_SCHEMA_NAME = "user";
 
+  /**
+   * A virtual schema name used only for {@link org.apache.gravitino.lock.TreeLockUtils} lock paths
+   * when operating on users by Gravitino-assigned id (for example,
+   * get/enable/disable/delete-by-id).
+   *
+   * <p>This is not a real metadata schema and does not store entities. It forms part of a synthetic
+   * {@link org.apache.gravitino.NameIdentifier} such as {@code {metalake, system, user-id, <id>}}
+   * so that concurrent operations on the same user id are serialized.
+   */
+  String USER_ID_SCHEMA_NAME = "user-id";

Review Comment:
   OK.



-- 
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] [#12330] feat(core): Add user by-id APIs and alterUserById via UserChange [gravitino]

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


-- 
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] [#12330] feat(core): Add user by-id lookup, enable/disable, delete, and update-external-id APIs [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/authorization/UserGroupIdManager.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.authorization;
+
+import java.io.IOException;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.exceptions.NoSuchUserException;
+import org.apache.gravitino.meta.UserEntity;
+import org.apache.gravitino.storage.IdGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Manages user and group operations keyed by Gravitino-assigned id within a metalake. */
+class UserGroupIdManager extends UserGroupManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(UserGroupIdManager.class);
+
+  /**
+   * Creates a {@link UserGroupIdManager} instance.
+   *
+   * @param store the entity store
+   * @param idGenerator the id generator
+   */
+  UserGroupIdManager(EntityStore store, IdGenerator idGenerator) {
+    super(store, idGenerator);
+  }
+
+  boolean removeUserById(String metalake, long userId) {
+    try {
+      return store
+          .idOperations()
+          .deleteById(AuthorizationUtils.ofUserId(metalake, userId), Entity.EntityType.USER);
+    } catch (IOException ioe) {
+      LOG.error(
+          "Removing user with id {} in the metalake {} failed due to storage issues",
+          userId,
+          metalake,
+          ioe);
+      throw new RuntimeException(ioe);
+    }
+  }
+
+  User getUserById(String metalake, long userId) throws NoSuchUserException {
+    try {
+      return store
+          .idOperations()
+          .getById(
+              AuthorizationUtils.ofUserId(metalake, userId),
+              Entity.EntityType.USER,
+              UserEntity.class);
+    } catch (NoSuchEntityException e) {
+      LOG.warn("User with id {} does not exist in the metalake {}", userId, metalake, e);
+      throw new NoSuchUserException(
+          AuthorizationUtils.USER_WITH_ID_DOES_NOT_EXIST_MSG, userId, metalake);
+    } catch (IOException ioe) {
+      LOG.error("Getting user with id {} failed due to storage issues", userId, ioe);
+      throw new RuntimeException(ioe);
+    }
+  }
+
+  User enableUserById(String metalake, long userId) throws NoSuchUserException {
+    return updateEnabledById(metalake, userId, true);
+  }
+
+  User disableUserById(String metalake, long userId) throws NoSuchUserException {
+    return updateEnabledById(metalake, userId, false);
+  }
+
+  User updateUserExternalIdById(String metalake, long userId, String newExternalId)

Review Comment:
   Do we need this api? External id should be immutable in my view.



-- 
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] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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

   Could u remove external id operations?


-- 
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] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/Entity.java:
##########
@@ -41,6 +41,17 @@ public interface Entity extends Serializable {
   /** The user schema name in the system catalog. */
   String USER_SCHEMA_NAME = "user";
 
+  /**
+   * A virtual schema name used only for {@link org.apache.gravitino.lock.TreeLockUtils} lock paths
+   * when operating on users by Gravitino-assigned id (for example,
+   * get/enable/disable/delete-by-id).
+   *
+   * <p>This is not a real metadata schema and does not store entities. It forms part of a synthetic
+   * {@link org.apache.gravitino.NameIdentifier} such as {@code {metalake, system, user-id, <id>}}
+   * so that concurrent operations on the same user id are serialized.
+   */
+  String USER_ID_SCHEMA_NAME = "user-id";

Review Comment:
   You can reuse `USER_SCHEMA`.



-- 
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] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/listener/api/info/UserInfo.java:
##########
@@ -27,6 +27,7 @@
 /** Provides read-only access to user information for event listeners. */
 @DeveloperApi
 public class UserInfo {
+  private final Optional<Long> id;

Review Comment:
   Why is id optional?



-- 
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] [#12330] feat(core): Add user by-id APIs and alterUserById via UserChange [gravitino]

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

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|68.09% **`-0.1%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|64.45%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|49.32% **`+0.1%`**|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|42.04%|:green_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|9.92%|:red_circle:|
   |catalog-fileset|79.74%|:green_circle:|
   |catalog-glue|66.91%|:green_circle:|
   |catalog-hive|79.4%|:green_circle:|
   |catalog-jdbc-common|45.7%|:green_circle:|
   |catalog-jdbc-doris|81.8%|:green_circle:|
   |catalog-jdbc-mysql|79.33%|:green_circle:|
   |catalog-jdbc-postgresql|83.39%|:green_circle:|
   |catalog-jdbc-starrocks|79.16%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|59.18%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.93%|:green_circle:|
   |catalog-lakehouse-paimon|84.23%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.49% **`-0.17%`**|:green_circle:|
   |client-java|78.27%|:green_circle:|
   |common|52.26% **`-2.09%`**|:green_circle:|
   |core|83.02% **`-0.45%`**|:green_circle:|
   |filesystem-hadoop3|77.28%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|48.68%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-auth|68.0%|:green_circle:|
   |hadoop-common|12.7%|:red_circle:|
   |hive-metastore-common|53.4%|:green_circle:|
   |iceberg-common|64.75%|:green_circle:|
   |iceberg-rest-server|75.02%|:green_circle:|
   |idp-basic|86.02%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|24.5%|:red_circle:|
   |lance-rest-server|64.23%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|83.17%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.89%|:green_circle:|
   |server-common|76.38%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|45.89%|:green_circle:|
   |tencent|69.84%|:green_circle:|
   |trino-connector|40.29%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |api|[UserChange.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/api/src/main/java/org/apache/gravitino/authorization/UserChange.java)|69.23%|:green_circle:|
   ||[User.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/api/src/main/java/org/apache/gravitino/authorization/User.java)|0.0%|:red_circle:|
   |cli|[ListUsers.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListUsers.java)|0.0%|:red_circle:|
   |common|[UserDTO.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/common/src/main/java/org/apache/gravitino/dto/authorization/UserDTO.java)|67.57%|:green_circle:|
   ||[DTOConverters.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java)|29.04%|:red_circle:|
   |core|[Entity.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/Entity.java)|100.0%|:green_circle:|
   ||[AccessControlManager.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/authorization/AccessControlManager.java)|100.0%|:green_circle:|
   ||[UserMetaBaseSQLProvider.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/UserMetaBaseSQLProvider.java)|100.0%|:green_circle:|
   ||[UserMetaSQLProviderFactory.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserMetaSQLProviderFactory.java)|96.3%|:green_circle:|
   ||[UserMetaService.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/storage/relational/service/UserMetaService.java)|92.78%|:green_circle:|
   ||[UserInfo.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/listener/api/info/UserInfo.java)|91.67%|:green_circle:|
   ||[AccessControlEventDispatcher.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/listener/AccessControlEventDispatcher.java)|89.54%|:green_circle:|
   ||[JDBCBackend.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java)|80.0%|:green_circle:|
   ||[UserGroupIdManager.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/authorization/UserGroupIdManager.java)|79.66%|:green_circle:|
   ||[UserGroupExternalManager.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/authorization/UserGroupExternalManager.java)|76.92%|:green_circle:|
   ||[AuthorizationUtils.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java)|65.91%|:green_circle:|
   ||[RelationalEntityStore.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java)|64.45%|:green_circle:|
   ||[AccessControlHookDispatcher.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/hook/AccessControlHookDispatcher.java)|34.44%|:red_circle:|
   ||[EntityStore.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/EntityStore.java)|30.0%|:red_circle:|
   ||[SupportsIdOperations.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/SupportsIdOperations.java)|0.0%|:red_circle:|
   ||[AccessControlDispatcher.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/authorization/AccessControlDispatcher.java)|0.0%|:red_circle:|
   ||[RelationalBackend.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/storage/relational/RelationalBackend.java)|0.0%|:red_circle:|
   ||[UserMetaMapper.java](https://github.com/lasdf1234/gravitino/blob/900a010287b95b5e83dc278582d8652dc8331e18/core/src/main/java/org/apache/gravitino/storage/relational/mapper/UserMetaMapper.java)|0.0%|:red_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] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/authorization/AccessControlDispatcher.java:
##########
@@ -145,6 +183,33 @@ User enableUser(String metalake, String externalId)
   User disableUser(String metalake, String externalId)
       throws NoSuchUserException, NoSuchMetalakeException;
 
+  /**
+   * Disables a User by Gravitino-assigned id without removing role bindings.
+   *
+   * @param metalake The Metalake of the User.
+   * @param userId The Gravitino-assigned id of the User.
+   * @return The updated User instance.
+   * @throws NoSuchUserException If the User with the given id does not exist.
+   * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+   * @throws RuntimeException If updating the User encounters storage issues.
+   */
+  User disableUserById(String metalake, long userId)
+      throws NoSuchUserException, NoSuchMetalakeException;
+
+  /**
+   * Updates the external identifier of a User by Gravitino-assigned id.
+   *
+   * @param metalake The Metalake of the User.
+   * @param userId The Gravitino-assigned id of the User.
+   * @param newExternalId The new external identifier, or null to clear it.
+   * @return The updated User instance.
+   * @throws NoSuchUserException If the User with the given id does not exist.
+   * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+   * @throws RuntimeException If updating the User encounters storage issues.
+   */
+  User updateUserExternalId(String metalake, long userId, String newExternalId)

Review Comment:
   The upstream system might change the 'externalId' based on the 'userId', so I have renamed this method: 'updateUserExternalIdById'



-- 
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] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/authorization/AccessControlDispatcher.java:
##########
@@ -145,6 +183,33 @@ User enableUser(String metalake, String externalId)
   User disableUser(String metalake, String externalId)
       throws NoSuchUserException, NoSuchMetalakeException;
 
+  /**
+   * Disables a User by Gravitino-assigned id without removing role bindings.
+   *
+   * @param metalake The Metalake of the User.
+   * @param userId The Gravitino-assigned id of the User.
+   * @return The updated User instance.
+   * @throws NoSuchUserException If the User with the given id does not exist.
+   * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+   * @throws RuntimeException If updating the User encounters storage issues.
+   */
+  User disableUserById(String metalake, long userId)
+      throws NoSuchUserException, NoSuchMetalakeException;
+
+  /**
+   * Updates the external identifier of a User by Gravitino-assigned id.
+   *
+   * @param metalake The Metalake of the User.
+   * @param userId The Gravitino-assigned id of the User.
+   * @param newExternalId The new external identifier, or null to clear it.
+   * @return The updated User instance.
+   * @throws NoSuchUserException If the User with the given id does not exist.
+   * @throws NoSuchMetalakeException If the Metalake with the given name does not exist.
+   * @throws RuntimeException If updating the User encounters storage issues.
+   */
+  User updateUserExternalId(String metalake, long userId, String newExternalId)

Review Comment:
   Why is this external id?



-- 
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] [#12330] feat(core): Add user by-id lookup, enable/disable, delete, and update-external-id APIs [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/authorization/UserGroupIdManager.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.authorization;
+
+import java.io.IOException;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.exceptions.NoSuchEntityException;
+import org.apache.gravitino.exceptions.NoSuchUserException;
+import org.apache.gravitino.meta.UserEntity;
+import org.apache.gravitino.storage.IdGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Manages user and group operations keyed by Gravitino-assigned id within a metalake. */
+class UserGroupIdManager extends UserGroupManager {
+
+  private static final Logger LOG = LoggerFactory.getLogger(UserGroupIdManager.class);
+
+  /**
+   * Creates a {@link UserGroupIdManager} instance.
+   *
+   * @param store the entity store
+   * @param idGenerator the id generator
+   */
+  UserGroupIdManager(EntityStore store, IdGenerator idGenerator) {
+    super(store, idGenerator);
+  }
+
+  boolean removeUserById(String metalake, long userId) {
+    try {
+      return store
+          .idOperations()
+          .deleteById(AuthorizationUtils.ofUserId(metalake, userId), Entity.EntityType.USER);
+    } catch (IOException ioe) {
+      LOG.error(
+          "Removing user with id {} in the metalake {} failed due to storage issues",
+          userId,
+          metalake,
+          ioe);
+      throw new RuntimeException(ioe);
+    }
+  }
+
+  User getUserById(String metalake, long userId) throws NoSuchUserException {
+    try {
+      return store
+          .idOperations()
+          .getById(
+              AuthorizationUtils.ofUserId(metalake, userId),
+              Entity.EntityType.USER,
+              UserEntity.class);
+    } catch (NoSuchEntityException e) {
+      LOG.warn("User with id {} does not exist in the metalake {}", userId, metalake, e);
+      throw new NoSuchUserException(
+          AuthorizationUtils.USER_WITH_ID_DOES_NOT_EXIST_MSG, userId, metalake);
+    } catch (IOException ioe) {
+      LOG.error("Getting user with id {} failed due to storage issues", userId, ioe);
+      throw new RuntimeException(ioe);
+    }
+  }
+
+  User enableUserById(String metalake, long userId) throws NoSuchUserException {
+    return updateEnabledById(metalake, userId, true);
+  }
+
+  User disableUserById(String metalake, long userId) throws NoSuchUserException {
+    return updateEnabledById(metalake, userId, false);
+  }
+
+  User updateUserExternalIdById(String metalake, long userId, String newExternalId)

Review Comment:
   When creating, the externalId was not provided. Later, it was added through a PATCH request (a common practice in Entra)



-- 
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] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/Entity.java:
##########
@@ -41,6 +41,17 @@ public interface Entity extends Serializable {
   /** The user schema name in the system catalog. */
   String USER_SCHEMA_NAME = "user";
 
+  /**
+   * A virtual schema name used only for {@link org.apache.gravitino.lock.TreeLockUtils} lock paths
+   * when operating on users by Gravitino-assigned id (for example,
+   * get/enable/disable/delete-by-id).
+   *
+   * <p>This is not a real metadata schema and does not store entities. It forms part of a synthetic
+   * {@link org.apache.gravitino.NameIdentifier} such as {@code {metalake, system, user-id, <id>}}
+   * so that concurrent operations on the same user id are serialized.
+   */
+  String USER_ID_SCHEMA_NAME = "user-id";

Review Comment:
   Reusing the USER_SCHEMA might cause a conflict.
   ex:
   {system, user, "42"}
   {system, user-id, "42"}
   
   If the same USER_SCHEMA is used, it will cause a conflict.



-- 
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] [#12330] feat(authz): Support user operations by Gravitino-assigned id [gravitino]

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


##########
core/src/main/java/org/apache/gravitino/listener/api/info/UserInfo.java:
##########
@@ -27,6 +27,7 @@
 /** Provides read-only access to user information for event listeners. */
 @DeveloperApi
 public class UserInfo {
+  private final Optional<Long> id;

Review Comment:
   Got resolved.



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