Esempio n. 1
1
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String text = null;

    try {
      text = getText(mapping, form, request, response);
    } catch (Exception e) {
      PortalUtil.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request, response);

      return null;
    }

    response.setContentType(ContentTypes.TEXT_PLAIN_UTF8);
    response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);

    PrintWriter printWriter = response.getWriter();

    printWriter.write(text);

    printWriter.close();

    return null;
  }
Esempio n. 2
0
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

    try {
      long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

      long folderId = ParamUtil.getLong(actionRequest, "folderId");
      String name = ParamUtil.getString(actionRequest, "name");
      String title = ParamUtil.getString(actionRequest, "title");
      String version = ParamUtil.getString(actionRequest, "version");

      long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId");

      String uuid = ParamUtil.getString(actionRequest, "uuid");

      String targetExtension = ParamUtil.getString(actionRequest, "targetExtension");

      ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

      long groupId = ParamUtil.getLong(actionRequest, "groupId", themeDisplay.getScopeGroupId());

      getFile(
          fileEntryId,
          folderId,
          name,
          title,
          version,
          fileShortcutId,
          uuid,
          groupId,
          targetExtension,
          request,
          response);

      setForward(actionRequest, ActionConstants.COMMON_NULL);
    } catch (NoSuchFileEntryException nsfee) {
      PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, actionRequest, actionResponse);
    } catch (PrincipalException pe) {
      processPrincipalException(pe, request, response);
    } catch (Exception e) {
      PortalUtil.sendError(e, actionRequest, actionResponse);
    }
  }
Esempio n. 3
0
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    try {
      long groupId = ParamUtil.getLong(request, "groupId");
      String articleId = ParamUtil.getString(request, "articleId");

      String languageId = LanguageUtil.getLanguageId(request);

      JournalArticle article =
          JournalArticleServiceUtil.getLatestArticle(
              groupId, articleId, WorkflowConstants.STATUS_APPROVED);

      String fileName = "content.xml";
      byte[] bytes = article.getContentByLocale(languageId).getBytes();

      ServletResponseUtil.sendFile(request, response, fileName, bytes, ContentTypes.TEXT_XML_UTF8);

      return null;
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    }
  }
  @Override
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!_openId.isEnabled(themeDisplay.getCompanyId())) {
      throw new PrincipalException.MustBeEnabled(
          themeDisplay.getCompanyId(), OpenId.class.getName());
    }

    if (actionRequest.getRemoteUser() != null) {
      actionResponse.sendRedirect(themeDisplay.getPathMain());

      return;
    }

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {
      if (cmd.equals(Constants.READ)) {
        String redirect = readOpenIdResponse(themeDisplay, actionRequest);

        if (Validator.isNull(redirect)) {
          redirect = themeDisplay.getURLSignIn();
        }

        redirect = PortalUtil.escapeRedirect(redirect);

        actionResponse.sendRedirect(redirect);
      } else {
        sendOpenIdRequest(themeDisplay, actionRequest, actionResponse);
      }
    } catch (Exception e) {
      if (e instanceof OpenIDException) {
        if (_log.isInfoEnabled()) {
          _log.info("Error communicating with OpenID provider: " + e.getMessage());
        }

        SessionErrors.add(actionRequest, e.getClass());
      } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) {

        SessionErrors.add(actionRequest, e.getClass());
      } else {
        _log.error("Error processing the OpenID login", e);

        PortalUtil.sendError(e, actionRequest, actionResponse);
      }
    }
  }
Esempio n. 5
0
  @Override
  public ActionForward strutsExecute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    try {
      long fileEntryId = ParamUtil.getLong(request, "fileEntryId");

      long folderId = ParamUtil.getLong(request, "folderId");
      String name = ParamUtil.getString(request, "name");
      String title = ParamUtil.getString(request, "title");
      String version = ParamUtil.getString(request, "version");

      long fileShortcutId = ParamUtil.getLong(request, "fileShortcutId");

      String uuid = ParamUtil.getString(request, "uuid");

      String targetExtension = ParamUtil.getString(request, "targetExtension");

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      long groupId = ParamUtil.getLong(request, "groupId", themeDisplay.getScopeGroupId());

      getFile(
          fileEntryId,
          folderId,
          name,
          title,
          version,
          fileShortcutId,
          uuid,
          groupId,
          targetExtension,
          request,
          response);

      return null;
    } catch (PrincipalException pe) {
      processPrincipalException(pe, request, response);

      return null;
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    }
  }
Esempio n. 6
0
  protected void sendError(
      int status, Throwable t, HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    DynamicServletRequest dynamicRequest = new DynamicServletRequest(request);

    // Reset layout params or there will be an infinite loop

    dynamicRequest.setParameter("p_l_id", StringPool.BLANK);

    dynamicRequest.setParameter("groupId", StringPool.BLANK);
    dynamicRequest.setParameter("layoutId", StringPool.BLANK);
    dynamicRequest.setParameter("privateLayout", StringPool.BLANK);

    PortalUtil.sendError(status, (Exception) t, dynamicRequest, response);
  }
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    if (!PropsValues.SETUP_WIZARD_ENABLED) {
      response.sendRedirect(themeDisplay.getPathMain());
    }

    String cmd = ParamUtil.getString(request, Constants.CMD);

    try {
      if (Validator.isNull(cmd)) {
        return mapping.findForward("portal.setup_wizard");
      } else if (cmd.equals(Constants.TRANSLATE)) {
        SetupWizardUtil.updateLanguage(request, response);

        return mapping.findForward("portal.setup_wizard");
      } else if (cmd.equals(Constants.TEST)) {
        testDatabase(request, response);

        return null;
      } else if (cmd.equals(Constants.UPDATE)) {
        SetupWizardUtil.updateSetup(request, response);
      }

      response.sendRedirect(themeDisplay.getPathMain() + "/portal/setup_wizard");

      return null;
    } catch (Exception e) {
      if (e instanceof PrincipalException) {
        SessionErrors.add(request, e.getClass());

        return mapping.findForward("portal.setup_wizard");
      } else {
        PortalUtil.sendError(e, request, response);

        return null;
      }
    }
  }
  protected void processPrincipalException(
      Throwable t, User user, HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    if (!user.isDefaultUser()) {
      PortalUtil.sendError(HttpServletResponse.SC_UNAUTHORIZED, (Exception) t, request, response);

      return;
    }

    String redirect = request.getContextPath() + Portal.PATH_MAIN + "/portal/login";

    String currentURL = PortalUtil.getCurrentURL(request);

    redirect = HttpUtil.addParameter(redirect, "redirect", currentURL);

    response.sendRedirect(redirect);
  }
Esempio n. 9
0
  @Override
  public ActionForward strutsExecute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    try {
      ServletResponseUtil.sendFile(
          request, response, null, getRSS(request), ContentTypes.TEXT_XML_UTF8);

      return null;
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    }
  }
  @Override
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String cmd = ParamUtil.getString(request, Constants.CMD);

    if (Validator.isNull(cmd)) {
      return actionMapping.findForward("portal.update_email_address");
    }

    try {
      updateEmailAddress(request);

      return actionMapping.findForward(ActionConstants.COMMON_REFERER_JSP);
    } catch (Exception e) {
      if (e instanceof DuplicateUserEmailAddressException
          || e instanceof ReservedUserEmailAddressException
          || e instanceof UserEmailAddressException) {

        SessionErrors.add(request, e.getClass());

        return actionMapping.findForward("portal.update_email_address");
      } else if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

        SessionErrors.add(request, e.getClass());

        return actionMapping.findForward("portal.error");
      } else {
        PortalUtil.sendError(e, request, response);

        return null;
      }
    }
  }
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    if (!PropsValues.PORTLET_URL_GENERATE_BY_PATH_ENABLED) {
      response.sendError(HttpServletResponse.SC_FORBIDDEN);

      return null;
    }

    try {
      String portletURL = getPortletURL(request);

      ServletResponseUtil.write(response, portletURL);
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);
    }

    return null;
  }
Esempio n. 12
0
  protected void processPrincipalException(
      Throwable t, HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    User user = permissionChecker.getUser();

    if ((user != null) && !user.isDefaultUser()) {
      PortalUtil.sendError(HttpServletResponse.SC_UNAUTHORIZED, (Exception) t, request, response);

      return;
    }

    String redirect = request.getContextPath() + Portal.PATH_MAIN + "/portal/login";

    String currentURL = PortalUtil.getCurrentURL(request);

    redirect = HttpUtil.addParameter(redirect, "redirect", currentURL);

    response.sendRedirect(redirect);
  }
Esempio n. 13
0
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (PropsValues.AUTH_LOGIN_DISABLED) {
      actionResponse.sendRedirect(
          themeDisplay.getPathMain() + PropsValues.AUTH_LOGIN_DISABLED_PATH);

      return;
    }

    /*if (actionRequest.getRemoteUser() != null) {
    	actionResponse.sendRedirect(themeDisplay.getPathMain());

    	return;
    }*/

    try {
      PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest);

      login(themeDisplay, actionRequest, actionResponse, preferences);

      boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

      if (doActionAfterLogin) {
        setForward(actionRequest, "portlet.login.login_redirect");
      }
    } catch (Exception e) {
      if (e instanceof AuthException) {
        Throwable cause = e.getCause();

        if (cause instanceof PasswordExpiredException || cause instanceof UserLockoutException) {

          SessionErrors.add(actionRequest, cause.getClass().getName());
        } else {
          if (_log.isInfoEnabled()) {
            _log.info("Authentication failed");
          }

          SessionErrors.add(actionRequest, e.getClass().getName());
        }
      } else if (e instanceof CompanyMaxUsersException
          || e instanceof CookieNotSupportedException
          || e instanceof NoSuchUserException
          || e instanceof PasswordExpiredException
          || e instanceof UserEmailAddressException
          || e instanceof UserIdException
          || e instanceof UserLockoutException
          || e instanceof UserPasswordException
          || e instanceof UserScreenNameException) {

        SessionErrors.add(actionRequest, e.getClass().getName());
      } else {
        _log.error(e, e);

        PortalUtil.sendError(e, actionRequest, actionResponse);
      }
    }
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    UploadServletRequest uploadRequest = null;

    try {
      String cmd = ParamUtil.getString(request, Constants.CMD);

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      long groupId = ParamUtil.getLong(request, "groupId");
      String articleId = ParamUtil.getString(request, "articleId");
      double version =
          ParamUtil.getDouble(request, "version", JournalArticleConstants.DEFAULT_VERSION);

      String languageId = LanguageUtil.getLanguageId(request);

      String output = null;

      if (cmd.equals(Constants.PREVIEW)) {
        uploadRequest = PortalUtil.getUploadServletRequest(request);

        String title = ParamUtil.getString(uploadRequest, "title");
        String description = ParamUtil.getString(uploadRequest, "description");
        String type = ParamUtil.getString(uploadRequest, "type");
        String structureId = ParamUtil.getString(uploadRequest, "structureId");
        String templateId = ParamUtil.getString(uploadRequest, "templateId");

        Date now = new Date();

        Date createDate = now;
        Date modifiedDate = now;
        Date displayDate = now;

        User user = PortalUtil.getUser(uploadRequest);

        String xml = ParamUtil.getString(uploadRequest, "xml");

        Document doc = SAXReaderUtil.read(xml);

        Element root = doc.getRootElement();

        String previewArticleId = "PREVIEW_" + PwdGenerator.getPassword(PwdGenerator.KEY3, 10);

        format(groupId, articleId, version, previewArticleId, root, uploadRequest);

        Map<String, String> tokens = JournalUtil.getTokens(groupId, themeDisplay);

        tokens.put("article_resource_pk", "-1");

        JournalArticle article = new JournalArticleImpl();

        article.setGroupId(groupId);
        article.setCompanyId(user.getCompanyId());
        article.setUserId(user.getUserId());
        article.setUserName(user.getFullName());
        article.setCreateDate(createDate);
        article.setModifiedDate(modifiedDate);
        article.setArticleId(articleId);
        article.setVersion(version);
        article.setTitle(title);
        article.setDescription(description);
        article.setContent(xml);
        article.setType(type);
        article.setStructureId(structureId);
        article.setTemplateId(templateId);
        article.setDisplayDate(displayDate);

        output =
            JournalArticleLocalServiceUtil.getArticleContent(
                article, templateId, null, languageId, themeDisplay);
      } else {
        output =
            JournalArticleServiceUtil.getArticleContent(
                groupId, articleId, version, languageId, themeDisplay);
      }

      request.setAttribute(WebKeys.JOURNAL_ARTICLE_CONTENT, output);

      if (output.startsWith("<?xml ")) {
        return mapping.findForward("portlet.journal.raw_article_content");
      } else {
        return mapping.findForward("portlet.journal.view_article_content");
      }
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    } finally {
      if (uploadRequest != null) {
        uploadRequest.cleanUp();
      }
    }
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HeaderCacheServletResponse headerCacheServletResponse = null;

    if (response instanceof HeaderCacheServletResponse) {
      headerCacheServletResponse = (HeaderCacheServletResponse) response;
    } else {
      headerCacheServletResponse = new HeaderCacheServletResponse(response);
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    Boolean layoutDefault = (Boolean) request.getAttribute(WebKeys.LAYOUT_DEFAULT);

    if ((layoutDefault != null) && (layoutDefault.booleanValue())) {
      Layout requestedLayout = (Layout) request.getAttribute(WebKeys.REQUESTED_LAYOUT);

      if (requestedLayout != null) {
        String redirectParam = "redirect";

        if (Validator.isNotNull(PropsValues.AUTH_LOGIN_PORTLET_NAME)) {
          redirectParam =
              PortalUtil.getPortletNamespace(PropsValues.AUTH_LOGIN_PORTLET_NAME) + redirectParam;
        }

        String authLoginURL = null;

        if (PrefsPropsUtil.getBoolean(
            themeDisplay.getCompanyId(),
            PropsKeys.CAS_AUTH_ENABLED,
            PropsValues.CAS_AUTH_ENABLED)) {

          authLoginURL = themeDisplay.getURLSignIn();
        }

        if (Validator.isNull(authLoginURL)) {
          authLoginURL = PortalUtil.getCommunityLoginURL(themeDisplay);
        }

        if (Validator.isNull(authLoginURL)) {
          authLoginURL = PropsValues.AUTH_LOGIN_URL;
        }

        if (Validator.isNull(authLoginURL)) {
          PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid());

          authLoginURL = loginURL.toString();
        }

        String currentURL = PortalUtil.getCurrentURL(request);

        authLoginURL = HttpUtil.setParameter(authLoginURL, redirectParam, currentURL);

        if (_log.isDebugEnabled()) {
          _log.debug("Redirect requested layout to " + authLoginURL);
        }

        headerCacheServletResponse.sendRedirect(authLoginURL);
      } else {
        String redirect = PortalUtil.getLayoutURL(layout, themeDisplay);

        if (_log.isDebugEnabled()) {
          _log.debug("Redirect default layout to " + redirect);
        }

        headerCacheServletResponse.sendRedirect(redirect);
      }

      return null;
    }

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (_log.isDebugEnabled()) {
      _log.debug("p_l_id is " + plid);
    }

    if (plid > 0) {
      ActionForward actionForward =
          processLayout(mapping, request, headerCacheServletResponse, plid);

      String contentType = response.getContentType();

      CacheResponseUtil.setHeaders(response, headerCacheServletResponse.getHeaders());

      if (contentType != null) {
        response.setContentType(contentType);
      }

      return actionForward;
    } else {
      try {
        forwardLayout(request);

        return mapping.findForward(ActionConstants.COMMON_FORWARD_JSP);
      } catch (Exception e) {
        PortalUtil.sendError(e, request, headerCacheServletResponse);

        CacheResponseUtil.setHeaders(response, headerCacheServletResponse.getHeaders());

        return null;
      }
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (PropsValues.AUTH_LOGIN_DISABLED) {
      actionResponse.sendRedirect(
          themeDisplay.getPathMain() + PropsValues.AUTH_LOGIN_DISABLED_PATH);

      return;
    }

    /*if (actionRequest.getRemoteUser() != null) {
    	actionResponse.sendRedirect(themeDisplay.getPathMain());

    	return;
    }*/

    try {
      login(themeDisplay, actionRequest, actionResponse);

      boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

      if (doActionAfterLogin) {
        LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

        PortletURL renderURL = liferayPortletResponse.createRenderURL();

        renderURL.setParameter("mvcRenderCommandName", "/login/login_redirect");

        actionRequest.setAttribute(WebKeys.REDIRECT, renderURL.toString());
      }
    } catch (Exception e) {
      if (e instanceof AuthException) {
        Throwable cause = e.getCause();

        if (cause instanceof PasswordExpiredException || cause instanceof UserLockoutException) {

          SessionErrors.add(actionRequest, cause.getClass(), cause);
        } else {
          if (_log.isInfoEnabled()) {
            _log.info("Authentication failed");
          }

          SessionErrors.add(actionRequest, e.getClass());
        }
      } else if (e instanceof CompanyMaxUsersException
          || e instanceof CookieNotSupportedException
          || e instanceof NoSuchUserException
          || e instanceof PasswordExpiredException
          || e instanceof UserEmailAddressException
          || e instanceof UserIdException
          || e instanceof UserLockoutException
          || e instanceof UserPasswordException
          || e instanceof UserScreenNameException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        _log.error(e, e);

        PortalUtil.sendError(e, actionRequest, actionResponse);

        return;
      }

      postProcessAuthFailure(actionRequest, actionResponse);
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    if (!company.isStrangers()) {
      throw new PrincipalException.MustBeEnabled(
          company.getCompanyId(), PropsKeys.COMPANY_SECURITY_STRANGERS);
    }

    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(LoginPortletKeys.FAST_LOGIN)) {
      throw new PrincipalException("Unable to create anonymous account");
    }

    if (actionRequest.getRemoteUser() != null) {
      actionResponse.sendRedirect(themeDisplay.getPathMain());

      return;
    }

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            actionRequest,
            LoginPortletKeys.FAST_LOGIN,
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/login/login_redirect");
    portletURL.setParameter("emailAddress", emailAddress);
    portletURL.setParameter("anonymousUser", Boolean.TRUE.toString());
    portletURL.setWindowState(LiferayWindowState.POP_UP);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      if (cmd.equals(Constants.ADD)) {
        addAnonymousUser(actionRequest, actionResponse);

        sendRedirect(actionRequest, actionResponse, portletURL.toString());
      } else if (cmd.equals(Constants.UPDATE)) {
        jsonObject = updateIncompleteUser(actionRequest, actionResponse);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
      }
    } catch (Exception e) {
      if (cmd.equals(Constants.UPDATE)) {
        jsonObject.putException(e);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
      } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) {

        User user =
            _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

        if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
          SessionErrors.add(actionRequest, e.getClass());
        } else {
          sendRedirect(actionRequest, actionResponse, portletURL.toString());
        }
      } else if (e instanceof CaptchaConfigurationException
          || e instanceof CaptchaTextException
          || e instanceof CompanyMaxUsersException
          || e instanceof ContactNameException
          || e instanceof EmailAddressException
          || e instanceof GroupFriendlyURLException
          || e instanceof UserEmailAddressException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        _log.error("Unable to create anonymous account", e);

        PortalUtil.sendError(e, actionRequest, actionResponse);
      }
    }
  }
  @Override
  public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws IOException, PortletException {

    String resourceID = GetterUtil.getString(resourceRequest.getResourceID());

    HttpServletRequest request = PortalUtil.getHttpServletRequest(resourceRequest);

    HttpServletResponse response = PortalUtil.getHttpServletResponse(resourceResponse);

    if (resourceID.equals("compareVersions")) {
      ThemeDisplay themeDisplay =
          (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

      long groupId = ParamUtil.getLong(resourceRequest, "groupId");
      String articleId = ParamUtil.getString(resourceRequest, "articleId");
      double sourceVersion = ParamUtil.getDouble(resourceRequest, "filterSourceVersion");
      double targetVersion = ParamUtil.getDouble(resourceRequest, "filterTargetVersion");
      String languageId = ParamUtil.getString(resourceRequest, "languageId");

      String diffHtmlResults = null;

      try {
        diffHtmlResults =
            JournalUtil.diffHtml(
                groupId,
                articleId,
                sourceVersion,
                targetVersion,
                languageId,
                new PortletRequestModel(resourceRequest, resourceResponse),
                themeDisplay);
      } catch (CompareVersionsException cve) {
        resourceRequest.setAttribute(WebKeys.DIFF_VERSION, cve.getVersion());
      } catch (Exception e) {
        try {
          PortalUtil.sendError(e, request, response);
        } catch (ServletException se) {
        }
      }

      resourceRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, diffHtmlResults);

      PortletSession portletSession = resourceRequest.getPortletSession();

      PortletContext portletContext = portletSession.getPortletContext();

      PortletRequestDispatcher portletRequestDispatcher =
          portletContext.getRequestDispatcher(
              "/html/taglib/ui/diff_version_comparator/diff_html.jsp");

      portletRequestDispatcher.include(resourceRequest, resourceResponse);
    } else if (resourceID.equals("rss")) {
      try {
        byte[] xml = JournalRSSUtil.getRSS(resourceRequest, resourceResponse);

        ServletResponseUtil.sendFile(request, response, null, xml, ContentTypes.TEXT_XML_UTF8);
      } catch (Exception e) {
        try {
          PortalUtil.sendError(e, request, response);
        } catch (ServletException se) {
        }
      }
    } else {
      super.serveResource(resourceRequest, resourceResponse);
    }
  }
  protected ActionForward processLayout(
      ActionMapping mapping, HttpServletRequest request, HttpServletResponse response, long plid)
      throws Exception {

    HttpSession session = request.getSession();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    try {
      Layout layout = themeDisplay.getLayout();

      boolean resetLayout =
          ParamUtil.getBoolean(request, "p_l_reset", PropsValues.LAYOUT_DEFAULT_P_L_RESET);

      String portletId = ParamUtil.getString(request, "p_p_id");

      Layout previousLayout = (Layout) session.getAttribute(WebKeys.PREVIOUS_LAYOUT);

      if ((previousLayout == null) || (layout.getPlid() != previousLayout.getPlid())) {

        session.setAttribute(WebKeys.PREVIOUS_LAYOUT, layout);

        if (themeDisplay.isSignedIn()
            && PropsValues.AUDIT_MESSAGE_COM_LIFERAY_PORTAL_MODEL_LAYOUT_VIEW
            && MessageBusUtil.hasMessageListener(DestinationNames.AUDIT)) {

          User user = themeDisplay.getUser();

          AuditMessage auditMessage =
              new AuditMessage(
                  ActionKeys.VIEW,
                  user.getCompanyId(),
                  user.getUserId(),
                  user.getFullName(),
                  Layout.class.getName(),
                  String.valueOf(layout.getPlid()));

          AuditRouterUtil.route(auditMessage);
        }
      }

      if (!PropsValues.TCK_URL
          && resetLayout
          && (Validator.isNull(portletId)
              || ((previousLayout != null) && (layout.getPlid() != previousLayout.getPlid())))) {

        // Always clear render parameters on a layout url, but do not
        // clear on portlet urls invoked on the same layout

        RenderParametersPool.clear(request, plid);
      }

      if (themeDisplay.isLifecycleAction()) {
        Portlet portlet = processPortletRequest(request, response, PortletRequest.ACTION_PHASE);

        if (portlet != null) {
          ActionResponseImpl actionResponseImpl =
              (ActionResponseImpl) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

          String redirectLocation = actionResponseImpl.getRedirectLocation();

          if (Validator.isNotNull(redirectLocation)) {
            response.sendRedirect(redirectLocation);

            return null;
          }

          if (portlet.isActionURLRedirect()) {
            redirectActionURL(request, response, actionResponseImpl, portlet);

            return null;
          }
        }
      } else if (themeDisplay.isLifecycleRender()) {
        processPortletRequest(request, response, PortletRequest.RENDER_PHASE);
      }

      if (themeDisplay.isLifecycleResource()) {
        processPortletRequest(request, response, PortletRequest.RESOURCE_PHASE);

        return null;
      } else {
        if (response.isCommitted()) {
          return null;
        }

        if (layout != null) {

          // Include layout content before the page loads because
          // portlets on the page can set the page title and page
          // subtitle

          includeLayoutContent(request, response, themeDisplay, layout);

          if (themeDisplay.isStateExclusive()) {
            renderExclusive(request, response, themeDisplay);

            return null;
          }
        }

        return mapping.findForward("portal.layout");
      }
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    } finally {
      if (!ServerDetector.isResin()) {
        PortletRequest portletRequest =
            (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

        if (portletRequest != null) {
          PortletRequestImpl portletRequestImpl = (PortletRequestImpl) portletRequest;

          portletRequestImpl.cleanUp();
        }
      }
    }
  }
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String portletName = portletConfig.getPortletName();

    if (!portletName.equals(PortletKeys.FAST_LOGIN)) {
      throw new PrincipalException();
    }

    if (actionRequest.getRemoteUser() != null) {
      actionResponse.sendRedirect(themeDisplay.getPathMain());

      return;
    }

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            actionRequest,
            PortletKeys.FAST_LOGIN,
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/login/login_redirect");
    portletURL.setParameter("emailAddress", emailAddress);
    portletURL.setParameter("anonymousUser", Boolean.TRUE.toString());
    portletURL.setWindowState(LiferayWindowState.POP_UP);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {
      if (cmd.equals(Constants.ADD)) {
        addAnonymousUser(actionRequest, actionResponse);

        sendRedirect(actionRequest, actionResponse, portletURL.toString());
      } else if (cmd.equals(Constants.UPDATE)) {
        jsonObject = updateIncompleteUser(actionRequest, actionResponse);

        writeJSON(actionRequest, actionResponse, jsonObject);
      }
    } catch (Exception e) {
      if (cmd.equals(Constants.UPDATE)) {
        jsonObject.putException(e);

        writeJSON(actionRequest, actionResponse, jsonObject);
      } else if (e instanceof DuplicateUserEmailAddressException) {
        User user =
            UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

        if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
          SessionErrors.add(actionRequest, e.getClass());
        } else {
          sendRedirect(actionRequest, actionResponse, portletURL.toString());
        }
      } else if (e instanceof CaptchaTextException
          || e instanceof CompanyMaxUsersException
          || e instanceof ContactFirstNameException
          || e instanceof ContactFullNameException
          || e instanceof ContactLastNameException
          || e instanceof EmailAddressException
          || e instanceof GroupFriendlyURLException
          || e instanceof ReservedUserEmailAddressException
          || e instanceof UserEmailAddressException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        _log.error("Unable to create anonymous account", e);

        PortalUtil.sendError(e, actionRequest, actionResponse);
      }
    }
  }
  @Override
  public void service(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    User user = null;

    try {
      user = _getUser(request);

      PrincipalThreadLocal.setName(user.getUserId());
      PrincipalThreadLocal.setPassword(PortalUtil.getUserPassword(request));

      PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

      PermissionThreadLocal.setPermissionChecker(permissionChecker);

      if (_lastModified) {
        long lastModified = getLastModified(request);

        if (lastModified > 0) {
          long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);

          if ((ifModifiedSince > 0) && (ifModifiedSince == lastModified)) {

            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);

            return;
          }
        }

        if (lastModified > 0) {
          response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified);
        }
      }

      String path = HttpUtil.fixPath(request.getPathInfo());
      String[] pathArray = StringUtil.split(path, CharPool.SLASH);

      if (pathArray.length == 0) {
        sendGroups(response, user, request.getServletPath() + StringPool.SLASH + path);
      } else {
        if (_PATH_DDM.equals(pathArray[0])) {
          sendDDMRecordFile(request, response, pathArray);
        } else if (Validator.isNumber(pathArray[0])) {
          sendFile(request, response, user, pathArray);
        } else {
          if (isLegacyImageGalleryImageId(request, response)) {
            return;
          }

          Image image = getImage(request, true);

          if (image != null) {
            writeImage(image, request, response);
          } else {
            sendDocumentLibrary(
                request,
                response,
                user,
                request.getServletPath() + StringPool.SLASH + path,
                pathArray);
          }
        }
      }
    } catch (NoSuchFileEntryException nsfee) {
      PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response);
    } catch (PrincipalException pe) {
      processPrincipalException(pe, user, request, response);
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);
    }
  }