/**
   * super admin adds a tenant
   *
   * @param tenantInfoBean tenant info bean
   * @return UUID
   * @throws Exception if error in adding new tenant.
   */
  public String addTenant(TenantInfoBean tenantInfoBean) throws Exception {
    try {
      PrivilegedCarbonContext.startTenantFlow();
      PrivilegedCarbonContext.getThreadLocalCarbonContext()
          .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
      PrivilegedCarbonContext.getThreadLocalCarbonContext()
          .setTenantId(MultitenantConstants.SUPER_TENANT_ID);
      Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
      tenant.setId(tenantInfoBean.getTenantId());
      TenantPersistor persistor = new TenantPersistor();
      int tenantId;
      // not validating the domain ownership, since created by super tenant
      try {
        tenantId =
            persistor.persistTenant(
                tenant,
                false,
                tenantInfoBean.getSuccessKey(),
                tenantInfoBean.getOriginatedService(),
                false);
      } catch (Exception e) {
        String msg = "Error in persisting tenant ";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
      }

      tenantInfoBean.setTenantId(tenantId);
      TenantMgtUtil.addClaimsToUserStoreManager(tenant);
      // Notify tenant addition
      try {
        TenantMgtUtil.triggerAddTenant(tenantInfoBean);
      } catch (StratosException e) {
        String msg = "Error in notifying tenant addition.";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
      }

      TenantMgtUtil.activateTenantInitially(tenantInfoBean, tenantId);
      return TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    } finally {
      PrivilegedCarbonContext.endTenantFlow();
    }
  }