/** @deprecated {@link #addTable(long, String, String)} */
  public ExpandoTable addTable(String className, String name)
      throws PortalException, SystemException {

    long companyId = CompanyThreadLocal.getCompanyId();

    return addTable(companyId, className, name);
  }
  private static void _populateContextFromThreadLocals(Map<String, Serializable> context) {

    if (!context.containsKey("companyId")) {
      context.put("companyId", CompanyThreadLocal.getCompanyId());
    }

    if (!context.containsKey("defaultLocale")) {
      context.put("defaultLocale", LocaleThreadLocal.getDefaultLocale());
    }

    if (!context.containsKey("groupId")) {
      context.put("groupId", GroupThreadLocal.getGroupId());
    }

    if (!context.containsKey("principalName")) {
      context.put("principalName", PrincipalThreadLocal.getName());
    }

    if (!context.containsKey("principalPassword")) {
      context.put("principalPassword", PrincipalThreadLocal.getPassword());
    }

    if (!context.containsKey("siteDefaultLocale")) {
      context.put("siteDefaultLocale", LocaleThreadLocal.getSiteDefaultLocale());
    }

    if (!context.containsKey("themeDisplayLocale")) {
      context.put("themeDisplayLocale", LocaleThreadLocal.getThemeDisplayLocale());
    }
  }
  public void importFromLDAP(long companyId) throws Exception {
    if (!LDAPSettingsUtil.isImportEnabled(companyId)) {
      return;
    }

    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);

    if (LockLocalServiceUtil.hasLock(
        defaultUserId, PortalLDAPImporterUtil.class.getName(), companyId)) {

      if (_log.isDebugEnabled()) {
        _log.debug(
            "Skipping LDAP import for company "
                + companyId
                + "because another LDAP import is in process");
      }

      return;
    }

    LockLocalServiceUtil.lock(
        defaultUserId,
        PortalLDAPImporterUtil.class.getName(),
        companyId,
        PortalLDAPImporterImpl.class.getName(),
        false,
        PropsValues.LDAP_IMPORT_LOCK_EXPIRATION_TIME);

    long threadLocalCompanyId = CompanyThreadLocal.getCompanyId();

    try {
      if (threadLocalCompanyId == CompanyConstants.SYSTEM) {
        CompanyThreadLocal.setCompanyId(companyId);
      }

      long[] ldapServerIds =
          StringUtil.split(PrefsPropsUtil.getString(companyId, "ldap.server.ids"), 0L);

      for (long ldapServerId : ldapServerIds) {
        importFromLDAP(ldapServerId, companyId);
      }

      for (int ldapServerId = 0; ; ldapServerId++) {
        String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId);

        String providerUrl =
            PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_PROVIDER_URL + postfix);

        if (Validator.isNull(providerUrl)) {
          break;
        }

        importFromLDAP(ldapServerId, companyId);
      }
    } finally {
      LockLocalServiceUtil.unlock(PortalLDAPImporterUtil.class.getName(), companyId);

      CompanyThreadLocal.setCompanyId(threadLocalCompanyId);
    }
  }
Пример #4
0
  private static CompanyLocalesBag _getCompanyLocalesBag() {
    Long companyId = CompanyThreadLocal.getCompanyId();

    CompanyLocalesBag companyLocalesBag = _companyLocalesBags.get(companyId);

    if (companyLocalesBag == null) {
      companyLocalesBag = new CompanyLocalesBag(companyId);

      _companyLocalesBags.put(companyId, companyLocalesBag);
    }

    return companyLocalesBag;
  }
  public static boolean isOmniadmin(long userId) {
    if (CompanyThreadLocal.getCompanyId() != PortalInstances.getDefaultCompanyId()) {

      return false;
    }

    if (userId <= 0) {
      return false;
    }

    try {
      if (PropsValues.OMNIADMIN_USERS.length > 0) {
        for (int i = 0; i < PropsValues.OMNIADMIN_USERS.length; i++) {
          if (PropsValues.OMNIADMIN_USERS[i] == userId) {
            User user = UserLocalServiceUtil.getUserById(userId);

            if (user.getCompanyId() != PortalInstances.getDefaultCompanyId()) {

              return false;
            }

            return true;
          }
        }

        return false;
      } else {
        User user = UserLocalServiceUtil.getUserById(userId);

        if (user.getCompanyId() != PortalInstances.getDefaultCompanyId()) {

          return false;
        }

        return RoleLocalServiceUtil.hasUserRole(
            userId, user.getCompanyId(), RoleConstants.ADMINISTRATOR, true);
      }
    } catch (Exception e) {
      _log.error(e);

      return false;
    }
  }
Пример #6
0
  private Configuration _getConfiguration() {
    if (_configurations == null) {
      return _configuration;
    }

    Long companyId = CompanyThreadLocal.getCompanyId();

    if (companyId > CompanyConstants.SYSTEM) {
      Configuration configuration = _configurations.get(companyId);

      if (configuration == null) {
        configuration =
            new ConfigurationImpl(PropsUtil.class.getClassLoader(), PropsFiles.PORTAL, companyId);

        _configurations.put(companyId, configuration);
      }

      return configuration;
    } else {
      return _configuration;
    }
  }
  @AccessControlled(guestAccessEnabled = true)
  @Override
  public SyncContext getSyncContext() throws PortalException {
    try {
      User user = getGuestOrUser();

      SyncContext syncContext = new SyncContext();

      String authType =
          PrefsPropsUtil.getString(
              CompanyThreadLocal.getCompanyId(),
              PropsKeys.COMPANY_SECURITY_AUTH_TYPE,
              PropsUtil.get(PropsKeys.COMPANY_SECURITY_AUTH_TYPE));

      syncContext.setAuthType(authType);

      boolean oAuthEnabled =
          PrefsPropsUtil.getBoolean(
              user.getCompanyId(),
              PortletPropsKeys.SYNC_OAUTH_ENABLED,
              PortletPropsValues.SYNC_OAUTH_ENABLED);

      if (oAuthEnabled) {
        String oAuthConsumerKey =
            PrefsPropsUtil.getString(user.getCompanyId(), PortletPropsKeys.SYNC_OAUTH_CONSUMER_KEY);

        syncContext.setOAuthConsumerKey(oAuthConsumerKey);

        String oAuthConsumerSecret =
            PrefsPropsUtil.getString(
                user.getCompanyId(), PortletPropsKeys.SYNC_OAUTH_CONSUMER_SECRET);

        syncContext.setOAuthConsumerSecret(oAuthConsumerSecret);
      }

      syncContext.setOAuthEnabled(oAuthEnabled);

      PluginPackage syncWebPluginPackage = DeployManagerUtil.getInstalledPluginPackage("sync-web");

      syncContext.setPluginVersion(syncWebPluginPackage.getVersion());

      if (!user.isDefaultUser()) {
        syncContext.setPortalBuildNumber(ReleaseInfo.getBuildNumber());

        PluginPackage soPortletPluginPackage =
            DeployManagerUtil.getInstalledPluginPackage("so-portlet");

        syncContext.setPortletPreferencesMap(getPortletPreferencesMap());

        if (soPortletPluginPackage != null) {
          syncContext.setSocialOfficeInstalled(true);
        } else {
          syncContext.setSocialOfficeInstalled(false);
        }

        syncContext.setUser(user);
        syncContext.setUserSitesGroups(getUserSitesGroups());
      }

      return syncContext;
    } catch (PortalException pe) {
      throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
  }
Пример #8
0
  @Override
  protected void dispatch(final Set<MessageListener> messageListeners, final Message message) {

    if (!message.contains("companyId")) {
      message.put("companyId", CompanyThreadLocal.getCompanyId());
    }

    if (!message.contains("permissionChecker")) {
      message.put("permissionChecker", PermissionThreadLocal.getPermissionChecker());
    }

    if (!message.contains("principalName")) {
      message.put("principalName", PrincipalThreadLocal.getName());
    }

    if (!message.contains("principalPassword")) {
      message.put("principalPassword", PrincipalThreadLocal.getPassword());
    }

    ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();

    Runnable runnable =
        new MessageRunnable(message) {

          public void run() {
            try {
              long messageCompanyId = message.getLong("companyId");

              if (messageCompanyId > 0) {
                CompanyThreadLocal.setCompanyId(messageCompanyId);
              }

              PermissionChecker permissionChecker =
                  (PermissionChecker) message.get("permissionChecker");

              if (permissionChecker != null) {
                PermissionThreadLocal.setPermissionChecker(permissionChecker);
              }

              String messagePrincipalName = message.getString("principalName");

              if (Validator.isNotNull(messagePrincipalName)) {
                PrincipalThreadLocal.setName(messagePrincipalName);
              }

              String messagePrincipalPassword = message.getString("principalPassword");

              if (Validator.isNotNull(messagePrincipalPassword)) {
                PrincipalThreadLocal.setPassword(messagePrincipalPassword);
              }

              Boolean clusterForwardMessage =
                  (Boolean) message.get(ClusterLinkUtil.CLUSTER_FORWARD_MESSAGE);

              if (clusterForwardMessage != null) {
                MessageValuesThreadLocal.setValue(
                    ClusterLinkUtil.CLUSTER_FORWARD_MESSAGE, clusterForwardMessage);
              }

              for (MessageListener messageListener : messageListeners) {
                try {
                  messageListener.receive(message);
                } catch (MessageListenerException mle) {
                  _log.error("Unable to process message " + message, mle);
                }
              }
            } finally {
              ThreadLocalCacheManager.clearAll(Lifecycle.REQUEST);

              CentralizedThreadLocal.clearShortLivedThreadLocals();
            }
          }
        };

    threadPoolExecutor.execute(runnable);
  }
  @Override
  protected void dispatch(Set<MessageListener> messageListeners, final Message message) {

    if (!message.contains("companyId")) {
      message.put("companyId", CompanyThreadLocal.getCompanyId());
    }

    if (!message.contains("principalName")) {
      message.put("principalName", PrincipalThreadLocal.getName());
    }

    if (!message.contains("principalPassword")) {
      message.put("principalPassword", PrincipalThreadLocal.getPassword());
    }

    ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();

    for (final MessageListener messageListener : messageListeners) {
      Runnable runnable =
          new MessageRunnable(message) {

            public void run() {
              long companyId = CompanyThreadLocal.getCompanyId();
              String principalName = PrincipalThreadLocal.getName();
              String principalPassword = PrincipalThreadLocal.getPassword();

              try {
                long messageCompanyId = message.getLong("companyId");

                if (messageCompanyId > 0) {
                  CompanyThreadLocal.setCompanyId(messageCompanyId);
                }

                String messagePrincipalName = message.getString("principalName");

                if (Validator.isNotNull(messagePrincipalName)) {
                  PrincipalThreadLocal.setName(messagePrincipalName);
                }

                String messagePrincipalPassword = message.getString("principalPassword");

                if (Validator.isNotNull(messagePrincipalPassword)) {
                  PrincipalThreadLocal.setPassword(messagePrincipalPassword);
                }

                messageListener.receive(message);
              } catch (MessageListenerException mle) {
                _log.error("Unable to process message " + message, mle);
              } finally {
                CompanyThreadLocal.setCompanyId(companyId);
                PrincipalThreadLocal.setName(principalName);
                PrincipalThreadLocal.setPassword(principalPassword);

                CentralizedThreadLocal.clearShortLivedThreadLocals();
              }
            }
          };

      threadPoolExecutor.execute(runnable);
    }
  }
Пример #10
0
  private long _initCompany(ServletContext servletContext, String webId) {

    // Begin initializing company

    if (_log.isDebugEnabled()) {
      _log.debug("Begin initializing company with web id " + webId);
    }

    long companyId = 0;

    try {
      Company company = CompanyLocalServiceUtil.checkCompany(webId);

      companyId = company.getCompanyId();
    } catch (Exception e) {
      _log.error(e, e);
    }

    Long currentThreadCompanyId = CompanyThreadLocal.getCompanyId();

    String currentThreadPrincipalName = PrincipalThreadLocal.getName();

    try {
      CompanyThreadLocal.setCompanyId(companyId);

      String principalName = null;

      try {
        User user = UserLocalServiceUtil.getUser(PrincipalThreadLocal.getUserId());

        if (user.getCompanyId() == companyId) {
          principalName = currentThreadPrincipalName;
        }
      } catch (Exception e) {
      }

      PrincipalThreadLocal.setName(principalName);

      // Initialize display

      if (_log.isDebugEnabled()) {
        _log.debug("Initialize display");
      }

      try {
        String xml =
            HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-display.xml"));

        PortletCategory portletCategory =
            (PortletCategory) WebAppPool.get(companyId, WebKeys.PORTLET_CATEGORY);

        if (portletCategory == null) {
          portletCategory = new PortletCategory();
        }

        PortletCategory newPortletCategory = PortletLocalServiceUtil.getEARDisplay(xml);

        portletCategory.merge(newPortletCategory);

        for (int i = 0; i < _companyIds.length; i++) {
          long currentCompanyId = _companyIds[i];

          PortletCategory currentPortletCategory =
              (PortletCategory) WebAppPool.get(currentCompanyId, WebKeys.PORTLET_CATEGORY);

          if (currentPortletCategory != null) {
            portletCategory.merge(currentPortletCategory);
          }
        }

        WebAppPool.put(companyId, WebKeys.PORTLET_CATEGORY, portletCategory);
      } catch (Exception e) {
        _log.error(e, e);
      }

      // LDAP import

      try {
        if (LDAPSettingsUtil.isImportOnStartup(companyId)) {
          UserImporterUtil.importUsers(companyId);
        }
      } catch (Exception e) {
        _log.error(e, e);
      }

      // Process application startup events

      if (_log.isDebugEnabled()) {
        _log.debug("Process application startup events");
      }

      try {
        EventsProcessorUtil.process(
            PropsKeys.APPLICATION_STARTUP_EVENTS,
            PropsValues.APPLICATION_STARTUP_EVENTS,
            new String[] {String.valueOf(companyId)});
      } catch (Exception e) {
        _log.error(e, e);
      }

      // End initializing company

      if (_log.isDebugEnabled()) {
        _log.debug(
            "End initializing company with web id " + webId + " and company id " + companyId);
      }

      addCompanyId(companyId);
    } finally {
      CompanyThreadLocal.setCompanyId(currentThreadCompanyId);

      PrincipalThreadLocal.setName(currentThreadPrincipalName);
    }

    return companyId;
  }