@Override
  protected synchronized RequestProcessor getRequestProcessor(ModuleConfig moduleConfig)
      throws ServletException {

    ServletContext servletContext = getServletContext();

    String key = Globals.REQUEST_PROCESSOR_KEY + moduleConfig.getPrefix();

    RequestProcessor requestProcessor = (RequestProcessor) servletContext.getAttribute(key);

    if (requestProcessor == null) {
      ControllerConfig controllerConfig = moduleConfig.getControllerConfig();

      try {
        requestProcessor =
            (RequestProcessor)
                InstanceFactory.newInstance(
                    ClassLoaderUtil.getPortalClassLoader(), controllerConfig.getProcessorClass());
      } catch (Exception e) {
        throw new ServletException(e);
      }

      requestProcessor.init(this, moduleConfig);

      servletContext.setAttribute(key, requestProcessor);
    }

    return requestProcessor;
  }
  @Override
  public Date getLastPostDateByUserId(long groupId, long userId) {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            MBThread.class, MBStatsUserImpl.TABLE_NAME, ClassLoaderUtil.getPortalClassLoader());

    Projection projection = ProjectionFactoryUtil.max("lastPostDate");

    dynamicQuery.setProjection(projection);

    Property property = PropertyFactoryUtil.forName("threadId");

    Disjunction disjunction = RestrictionsFactoryUtil.disjunction();

    QueryDefinition queryDefinition = new QueryDefinition(WorkflowConstants.STATUS_IN_TRASH);

    List<MBThread> threads = mbThreadLocalService.getGroupThreads(groupId, queryDefinition);

    for (MBThread thread : threads) {
      disjunction.add(property.ne(thread.getThreadId()));
    }

    dynamicQuery.add(disjunction);

    List<Date> results = mbStatsUserLocalService.dynamicQuery(dynamicQuery);

    return results.get(0);
  }
  private static void _initKeys() {
    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();

    if ((classLoader == null) || (_encryptedSymmetricKey != null)) {
      return;
    }

    try {
      URL url = classLoader.getResource("com/liferay/portal/license/public.key");

      byte[] bytes = IOUtils.toByteArray(url.openStream());

      X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(bytes);

      KeyFactory keyFactory = KeyFactory.getInstance("RSA");

      PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec);

      KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");

      keyGenerator.init(128, new SecureRandom());

      _symmetricKey = keyGenerator.generateKey();

      byte[] encryptedSymmetricKey =
          Encryptor.encryptUnencoded(publicKey, _symmetricKey.getEncoded());

      _encryptedSymmetricKey = Base64.objectToString(encryptedSymmetricKey);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
Beispiel #4
0
  private MergeScheduler _getMergeScheduler() throws Exception {
    if (PropsValues.LUCENE_MERGE_SCHEDULER.equals(NoMergeScheduler.class.getName())) {

      return NoMergeScheduler.INSTANCE;
    }

    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();

    return (MergeScheduler)
        InstanceFactory.newInstance(classLoader, PropsValues.LUCENE_MERGE_SCHEDULER);
  }
  protected void initSocial(PluginPackage pluginPackage) throws Exception {
    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();

    ServletContext servletContext = getServletContext();

    String[] xmls =
        new String[] {
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-social.xml")),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-social-ext.xml"))
        };

    SocialConfigurationUtil.read(classLoader, xmls);
  }
Beispiel #6
0
  public void afterPropertiesSet() throws Exception {
    if (_log.isDebugEnabled()) {
      _log.debug("Instantiate " + PropsValues.MEMBERSHIP_POLICY_USER_GROUPS);
    }

    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();

    _originalUserGroupMembershipPolicy =
        (UserGroupMembershipPolicy)
            InstanceFactory.newInstance(classLoader, PropsValues.MEMBERSHIP_POLICY_USER_GROUPS);

    _userGroupMembershipPolicy = _originalUserGroupMembershipPolicy;
  }
  public void afterPropertiesSet() throws Exception {
    if (_log.isDebugEnabled()) {
      _log.debug("Instantiate " + PropsValues.USERS_SCREEN_NAME_VALIDATOR);
    }

    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();

    _originalScreenNameValidator =
        (ScreenNameValidator)
            InstanceFactory.newInstance(classLoader, PropsValues.USERS_SCREEN_NAME_VALIDATOR);

    _screenNameValidator = _originalScreenNameValidator;
  }
Beispiel #8
0
  private MergePolicy _getMergePolicy() throws Exception {
    if (PropsValues.LUCENE_MERGE_POLICY.equals(NoMergePolicy.class.getName())) {

      return NoMergePolicy.NO_COMPOUND_FILES;
    }

    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();

    MergePolicy mergePolicy =
        (MergePolicy) InstanceFactory.newInstance(classLoader, PropsValues.LUCENE_MERGE_POLICY);

    if (mergePolicy instanceof LogMergePolicy) {
      LogMergePolicy logMergePolicy = (LogMergePolicy) mergePolicy;

      logMergePolicy.setMergeFactor(PropsValues.LUCENE_MERGE_FACTOR);
    }

    return mergePolicy;
  }
  public static Session createSession(String workspaceName) throws RepositoryException {

    if (workspaceName == null) {
      workspaceName = JCRFactory.WORKSPACE_NAME;
    }

    if (!PropsValues.JCR_WRAP_SESSION) {
      JCRFactory jcrFactory = getJCRFactory();

      return jcrFactory.createSession(workspaceName);
    }

    Map<String, Session> sessions = _sessions.get();

    Session session = sessions.get(workspaceName);

    if (session != null) {
      return session;
    }

    JCRFactory jcrFactory = getJCRFactory();

    Session jcrSession = jcrFactory.createSession(workspaceName);

    JCRSessionInvocationHandler jcrSessionInvocationHandler =
        new JCRSessionInvocationHandler(jcrSession);

    Object sessionProxy =
        ProxyUtil.newProxyInstance(
            ClassLoaderUtil.getPortalClassLoader(),
            new Class<?>[] {Map.class, Session.class},
            jcrSessionInvocationHandler);

    FinalizeManager.register(
        sessionProxy, jcrSessionInvocationHandler, FinalizeManager.PHANTOM_REFERENCE_FACTORY);

    session = (Session) sessionProxy;

    sessions.put(workspaceName, session);

    return session;
  }
  @Override
  public long getMessageCountByUserId(long userId) {
    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            MBStatsUser.class, MBStatsUserImpl.TABLE_NAME, ClassLoaderUtil.getPortalClassLoader());

    Projection projection = ProjectionFactoryUtil.sum("messageCount");

    dynamicQuery.setProjection(projection);

    Property property = PropertyFactoryUtil.forName("userId");

    dynamicQuery.add(property.eq(userId));

    List<Long> results = mbStatsUserLocalService.dynamicQuery(dynamicQuery);

    if (results.get(0) == null) {
      return 0;
    }

    return results.get(0);
  }
Beispiel #11
0
  protected List<Portlet> initPortlets(PluginPackage pluginPackage) throws Exception {

    ServletContext servletContext = getServletContext();

    String[] xmls =
        new String[] {
          HttpUtil.URLtoString(
              servletContext.getResource("/WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_CUSTOM)),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/portlet-ext.xml")),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-portlet.xml")),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-portlet-ext.xml")),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/web.xml"))
        };

    PortletLocalServiceUtil.initEAR(servletContext, xmls, pluginPackage);

    PortletBagFactory portletBagFactory = new PortletBagFactory();

    portletBagFactory.setClassLoader(ClassLoaderUtil.getPortalClassLoader());
    portletBagFactory.setServletContext(servletContext);
    portletBagFactory.setWARFile(false);

    List<Portlet> portlets = PortletLocalServiceUtil.getPortlets();

    for (int i = 0; i < portlets.size(); i++) {
      Portlet portlet = portlets.get(i);

      portletBagFactory.create(portlet);

      if (i == 0) {
        initPortletApp(portlet, servletContext);
      }
    }

    servletContext.setAttribute(WebKeys.PLUGIN_PORTLETS, portlets);

    return portlets;
  }
  private String _getSystemPackagesExtra() {
    String[] systemPackagesExtra = PropsValues.MODULE_FRAMEWORK_SYSTEM_PACKAGES_EXTRA;

    String hashcode =
        _getHashcode(
            systemPackagesExtra, PropsValues.MODULE_FRAMEWORK_SYSTEM_BUNDLE_IGNORED_FRAGMENTS);

    File coreDir = new File(PropsValues.LIFERAY_WEB_PORTAL_CONTEXT_TEMPDIR, "osgi");

    File cacheFile = new File(coreDir, "system-packages.txt");
    File hashcodeFile = new File(coreDir, "system-packages.hash");

    if (cacheFile.exists()
        && hashcodeFile.exists()
        && _hasMatchingHashcode(hashcodeFile, hashcode)) {

      ObjectInputStream objectInputStream = null;

      try {
        objectInputStream = new ObjectInputStream(new FileInputStream(cacheFile));

        _extraPackageMap = (Map<String, List<URL>>) objectInputStream.readObject();

        return (String) objectInputStream.readObject();
      } catch (IOException ioe) {
        _log.error(ioe, ioe);
      } catch (ClassNotFoundException cnfe) {
        _log.error(cnfe, cnfe);
      } finally {
        if (objectInputStream != null) {
          try {
            objectInputStream.close();
          } catch (IOException ioe) {
            _log.error(ioe, ioe);
          }
        }
      }
    }

    _extraPackageMap = new TreeMap<String, List<URL>>();

    StringBundler sb = new StringBundler();

    for (String extraPackage : systemPackagesExtra) {
      sb.append(extraPackage);
      sb.append(StringPool.COMMA);
    }

    ClassLoader classLoader = ClassLoaderUtil.getPortalClassLoader();

    PrintStream err = System.err;

    try {
      System.setErr(
          new PrintStream(err) {

            @Override
            public void println(String string) {
              if (_log.isDebugEnabled()) {
                _log.debug(string);
              }
            }
          });

      Enumeration<URL> enu = classLoader.getResources("META-INF/MANIFEST.MF");

      while (enu.hasMoreElements()) {
        URL url = enu.nextElement();

        _processURL(sb, url, PropsValues.MODULE_FRAMEWORK_SYSTEM_BUNDLE_IGNORED_FRAGMENTS);
      }
    } catch (IOException ioe) {
      _log.error(ioe, ioe);
    } finally {
      System.setErr(err);
    }

    _extraPackageMap = Collections.unmodifiableMap(_extraPackageMap);

    sb.setIndex(sb.index() - 1);

    if (_log.isTraceEnabled()) {
      String s = sb.toString();

      s = s.replace(",", "\n");

      _log.trace("The portal's system bundle is exporting the following " + "packages:\n" + s);
    }

    if (!coreDir.exists()) {
      coreDir.mkdir();
    }

    ObjectOutputStream objectOutputStream = null;

    try {
      objectOutputStream = new ObjectOutputStream(new FileOutputStream(cacheFile));

      objectOutputStream.writeObject(_extraPackageMap);
      objectOutputStream.writeObject(sb.toString());

      FileUtil.write(hashcodeFile, hashcode);
    } catch (IOException ioe) {
      _log.error(ioe, ioe);
    } finally {
      if (objectOutputStream != null) {
        try {
          objectOutputStream.close();
        } catch (IOException ioe) {
          _log.error(ioe, ioe);
        }
      }
    }

    return sb.toString();
  }