/**
  * Gets the tenant id from the tenant domain
  *
  * @param domain - tenant domain
  * @return - tenantId
  * @throws AdminManagementException, if getting tenant id failed.
  */
 public static int getTenantIdFromDomain(String domain) throws AdminManagementException {
   TenantManager tenantManager = AdminManagementServiceComponent.getTenantManager();
   int tenantId;
   if (domain.trim().equals("")) {
     tenantId = MultitenantConstants.SUPER_TENANT_ID;
     if (log.isDebugEnabled()) {
       String msg = "Password reset attempt on Super Tenant";
       log.debug(msg);
     }
   } else {
     try {
       tenantId = tenantManager.getTenantId(domain);
       if (tenantId < 1) {
         String msg = "Only the existing tenants can update the password";
         log.error(msg);
         throw new AdminManagementException(msg);
       }
     } catch (UserStoreException e) {
       String msg = "Error in retrieving tenant id of tenant domain: " + domain + ".";
       log.error(msg);
       throw new AdminManagementException(msg, e);
     }
   }
   return tenantId;
 }
 /**
  * Cleanup the used resources
  *
  * @param tenantLessUserName, userName without tenant
  * @param domain, The tenant domain
  * @throws AdminManagementException, if the cleanup failed.
  */
 public static void cleanupResources(String tenantLessUserName, String domain)
     throws AdminManagementException {
   String adminManagementPath = getAdminManagementPath(tenantLessUserName, domain);
   UserRegistry superTenantSystemRegistry;
   Resource resource;
   try {
     superTenantSystemRegistry =
         AdminManagementServiceComponent.getGovernanceSystemRegistry(
             MultitenantConstants.SUPER_TENANT_ID);
     if (superTenantSystemRegistry.resourceExists(adminManagementPath)) {
       resource = superTenantSystemRegistry.get(adminManagementPath);
       Resource tempResource = superTenantSystemRegistry.get(resource.getPath());
       if (tempResource != null) {
         superTenantSystemRegistry.delete(resource.getPath());
       }
     }
   } catch (RegistryException e) {
     String msg = "Registry resource doesn't exist at the path, " + adminManagementPath;
     log.error(msg, e);
     throw new AdminManagementException(msg, e);
   }
 }