smengcl commented on a change in pull request #3177:
URL: https://github.com/apache/ozone/pull/3177#discussion_r832641968



##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMultiTenantManagerImpl.java
##########
@@ -378,9 +382,60 @@ public void deactivateUser(String accessID)
 
   }
 
-  @Override
-  public boolean isTenantAdmin(String user, String tenantId) {
-    return true;
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isTenantAdmin(UserGroupInformation callerUgi,
+      String tenantId, Boolean delegated) {
+    if (callerUgi == null) {
+      return false;
+    } else {
+      return isTenantAdmin(
+              callerUgi.getShortUserName(), tenantId, delegated)
+          || isTenantAdmin(
+              callerUgi.getUserName(), tenantId, delegated)
+          || ozoneManager.isAdmin(callerUgi.getShortUserName())
+          || ozoneManager.isAdmin(callerUgi.getUserName());
+    }
+  }
+
+  /**
+   * Internal isTenantAdmin method that takes a username String instead of UGI.
+   */
+  private boolean isTenantAdmin(String username, String tenantId,
+      Boolean delegated) {
+    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(tenantId)) {
+      return false;
+    }
+
+    try {
+      final OmDBUserPrincipalInfo principalInfo =
+          omMetadataManager.getPrincipalToAccessIdsTable().get(username);
+
+      if (principalInfo == null) {
+        // The user is not assigned to any tenant
+        return false;
+      }
+
+      // Find accessId assigned to the specified tenant
+      for (final String accessId : principalInfo.getAccessIds()) {
+        final OmDBAccessIdInfo accessIdInfo =
+            omMetadataManager.getTenantAccessIdTable().get(accessId);
+        if (tenantId.equals(accessIdInfo.getTenantId())) {

Review comment:
       Ok. Added null check




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to