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

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

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

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

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

    StagingUtil.setRecentLayoutBranchId(
        request, layoutSetBranchId, themeDisplay.getPlid(), layoutBranchId);

    ActionUtil.addLayoutBranchSessionMessages(actionRequest, actionResponse);
  }
  protected void sendRedirect(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      ThemeDisplay themeDisplay,
      User user,
      String password)
      throws Exception {

    String login = null;

    Company company = themeDisplay.getCompany();

    String authType = company.getAuthType();

    if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
      login = String.valueOf(user.getUserId());
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
      login = user.getScreenName();
    } else {
      login = user.getEmailAddress();
    }

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

    if (Validator.isNotNull(redirect)) {
      HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

      AuthenticatedSessionManagerUtil.login(request, response, login, password, false, null);
    } else {
      PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid());

      loginURL.setParameter("login", login);

      redirect = loginURL.toString();
    }

    actionResponse.sendRedirect(redirect);
  }
  @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);
      }
    }
  }
예제 #4
0
  @Override
  protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

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

    if (plid == LayoutConstants.DEFAULT_PLID) {
      plid = themeDisplay.getPlid();
    }

    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long organizationId = ParamUtil.getLong(request, "organizationId");
    int status = WorkflowConstants.STATUS_APPROVED;
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.FORMAT_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle =
        ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);

    String feedURL =
        themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/blogs/find_entry?";

    String entryURL = feedURL;

    String rss = StringPool.BLANK;

    if (companyId > 0) {
      feedURL = StringPool.BLANK;

      rss =
          _blogsEntryService.getCompanyEntriesRSS(
              companyId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    } else if (groupId > 0) {
      feedURL += "p_l_id=" + plid;

      entryURL = feedURL;

      rss =
          _blogsEntryService.getGroupEntriesRSS(
              groupId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    } else if (organizationId > 0) {
      feedURL = StringPool.BLANK;

      rss =
          _blogsEntryService.getOrganizationEntriesRSS(
              organizationId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    } else if (layout != null) {
      groupId = themeDisplay.getScopeGroupId();

      feedURL = themeDisplay.getPathMain() + "/blogs/rss";

      entryURL = feedURL;

      rss =
          _blogsEntryService.getGroupEntriesRSS(
              groupId,
              new Date(),
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
  }
예제 #5
0
  public static void doTag(
      String portletName,
      String instanceId,
      String queryString,
      String settingsScope,
      String defaultPreferences,
      boolean persistSettings,
      PageContext pageContext,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    if (pageContext != null) {
      response = new PipingServletResponse(response, pageContext.getOut());
    }

    PortletInstance portletInstance = PortletInstance.fromPortletInstanceKey(portletName);

    if (Validator.isNotNull(instanceId)) {
      portletInstance =
          new PortletInstance(
              portletInstance.getPortletName(), portletInstance.getUserId(), instanceId);
    }

    RestrictPortletServletRequest restrictPortletServletRequest =
        new RestrictPortletServletRequest(PortalUtil.getOriginalServletRequest(request));

    queryString =
        PortletParameterUtil.addNamespace(portletInstance.getPortletInstanceKey(), queryString);

    Map<String, String[]> parameterMap = request.getParameterMap();

    if (!Objects.equals(portletInstance.getPortletInstanceKey(), request.getParameter("p_p_id"))) {

      parameterMap = MapUtil.filterByKeys(parameterMap, (key) -> !key.startsWith("p_p_"));
    }

    request =
        DynamicServletRequest.addQueryString(
            restrictPortletServletRequest, parameterMap, queryString, false);

    try {
      request.setAttribute(WebKeys.RENDER_PORTLET_RESOURCE, Boolean.TRUE);

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

      Portlet portlet =
          getPortlet(themeDisplay.getCompanyId(), portletInstance.getPortletInstanceKey());

      Stack<String> embeddedPortletIds = _embeddedPortletIds.get();

      if (embeddedPortletIds == null) {
        embeddedPortletIds = new Stack<>();

        _embeddedPortletIds.set(embeddedPortletIds);
      }

      if (embeddedPortletIds.search(portlet.getPortletId()) > -1) {
        String errorMessage = LanguageUtil.get(request, "the-application-cannot-include-itself");

        request.setAttribute("liferay-portlet:runtime:errorMessage", errorMessage);

        PortalIncludeUtil.include(pageContext, _ERROR_PAGE);

        return;
      }

      if (themeDisplay.isStateMaximized()) {
        LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

        if (layoutTypePortlet.hasStateMaxPortletId(portletInstance.getPortletInstanceKey())) {

          // A portlet in the maximized state has already been
          // processed

          return;
        }
      }

      Layout layout = themeDisplay.getLayout();

      request.setAttribute(WebKeys.SETTINGS_SCOPE, settingsScope);

      JSONObject jsonObject = null;

      boolean writeJSONObject = false;

      LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

      if (persistSettings && !layoutTypePortlet.isPortletEmbedded(portlet.getPortletId())) {

        PortletPreferencesFactoryUtil.getLayoutPortletSetup(
            themeDisplay.getCompanyId(),
            themeDisplay.getScopeGroupId(),
            PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
            PortletKeys.PREFS_PLID_SHARED,
            portletInstance.getPortletInstanceKey(),
            defaultPreferences);

        writeJSONObject = true;
      }

      if (PortletPreferencesLocalServiceUtil.getPortletPreferencesCount(
              PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
              themeDisplay.getPlid(),
              portletInstance.getPortletInstanceKey())
          < 1) {

        PortletPreferencesFactoryUtil.getLayoutPortletSetup(
            layout, portletInstance.getPortletInstanceKey(), defaultPreferences);
        PortletPreferencesFactoryUtil.getPortletSetup(
            request, portletInstance.getPortletInstanceKey(), defaultPreferences);

        PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance();

        if (portletLayoutListener != null) {
          portletLayoutListener.onAddToLayout(
              portletInstance.getPortletInstanceKey(), themeDisplay.getPlid());
        }

        writeJSONObject = true;
      }

      if (writeJSONObject) {
        jsonObject = JSONFactoryUtil.createJSONObject();

        PortletJSONUtil.populatePortletJSONObject(request, StringPool.BLANK, portlet, jsonObject);
      }

      if (jsonObject != null) {
        PortletJSONUtil.writeHeaderPaths(response, jsonObject);
      }

      embeddedPortletIds.push(portletInstance.getPortletInstanceKey());

      PortletContainerUtil.render(request, response, portlet);

      embeddedPortletIds.pop();

      if (jsonObject != null) {
        PortletJSONUtil.writeFooterPaths(response, jsonObject);
      }
    } finally {
      restrictPortletServletRequest.mergeSharedAttributes();
    }
  }