yuqi1129 commented on code in PR #6770:
URL: https://github.com/apache/gravitino/pull/6770#discussion_r2022014688


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -1044,4 +1044,34 @@ public boolean 
validAuthorizationOperation(List<SecurableObject> securableObject
               return match.get();
             });
   }
+
+  private Optional<Long> getUserId(String name) {
+    VXUserList list = rangerClient.searchUser(ImmutableMap.of("name", name));
+    if (list.getListSize() > 0) {
+      for (VXUser vxUser : list.getList()) {
+        if (vxUser.getName().equals(name)) {
+          return Optional.of(vxUser.getId());
+        }
+      }
+    }
+    return Optional.empty();
+  }
+
+  private Optional<Long> getGroupId(String name) {
+    VXGroupList vxGroupList = rangerClient.searchGroup(ImmutableMap.of("name", 
name));
+    try {
+      for (VXGroup group : vxGroupList.getList()) {
+        Class<?> clazz = group.getClass();
+        Field field = clazz.getDeclaredField("name");
+        field.setAccessible(true);
+        String value = (String) field.get(group);

Review Comment:
   String value = (String)  FieldUtils.readField(group, "name", true);
   



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -734,19 +735,18 @@ public Boolean onUserAdded(User user) throws 
AuthorizationPluginException {
 
   @Override
   public Boolean onUserRemoved(User user) throws AuthorizationPluginException {
-    VXUserList list = rangerClient.searchUser(ImmutableMap.of("name", 
user.name()));
-    if (list.getListSize() == 0) {
-      LOG.warn("The user({}) doesn't exist in the Ranger!", user);
+    Optional<Long> userId = getUserId(user.name());

Review Comment:
   Since you have use `Optional`, I have you can:
   
   return userId.map(id -> {
   rangerClient.deleteUser(id)
   return True;
   ).orElseGet(() -> {
   Log.warn
    return false;
   )



-- 
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-unsubscr...@gravitino.apache.org

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

Reply via email to