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 {

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

    MBMessage message = null;

    try {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        Throwable cause = uploadException.getCause();

        if (uploadException.isExceededFileSizeLimit()) {
          throw new FileSizeException(cause);
        }

        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException(cause);
        }

        if (uploadException.isExceededUploadRequestSizeLimit()) {
          throw new UploadRequestSizeException(cause);
        }

        throw new PortalException(cause);
      } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {

        message = updateMessage(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.ADD_ANSWER)) {
        addAnswer(actionRequest);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteMessage(actionRequest);
      } else if (cmd.equals(Constants.DELETE_ANSWER)) {
        deleteAnswer(actionRequest);
      } else if (cmd.equals(Constants.LOCK)) {
        lockThreads(actionRequest);
      } else if (cmd.equals(Constants.SUBSCRIBE)) {
        subscribeMessage(actionRequest);
      } else if (cmd.equals(Constants.UNLOCK)) {
        unlockThreads(actionRequest);
      } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
        unsubscribeMessage(actionRequest);
      }

      if (Validator.isNotNull(cmd)) {
        WindowState windowState = actionRequest.getWindowState();

        if (!windowState.equals(LiferayWindowState.POP_UP)) {
          String redirect = getRedirect(actionRequest, actionResponse, message);

          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          String redirect =
              PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

          if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
          }
        }
      }
    } catch (NoSuchMessageException | PrincipalException | RequiredMessageException e) {

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

      actionResponse.setRenderParameter("mvcPath", "/message_boards/error.jsp");
    } catch (AntivirusScannerException
        | CaptchaConfigurationException
        | CaptchaMaxChallengesException
        | CaptchaTextException
        | DuplicateFileEntryException
        | FileExtensionException
        | FileNameException
        | FileSizeException
        | LiferayFileItemException
        | LockedThreadException
        | MessageBodyException
        | MessageSubjectException
        | SanitizerException
        | UploadRequestSizeException e) {

      if (e instanceof AntivirusScannerException) {
        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }
    } catch (AssetCategoryException | AssetTagException e) {
      SessionErrors.add(actionRequest, e.getClass(), e);
    } catch (Exception e) {
      Throwable cause = e.getCause();

      if (cause instanceof SanitizerException) {
        SessionErrors.add(actionRequest, SanitizerException.class);
      } else {
        throw e;
      }
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    try {
      if (cmd.equals(Constants.CANCEL_CHECKOUT)) {
        cancelCheckedOutEntries(actionRequest);
      } else if (cmd.equals(Constants.CHECKIN)) {
        checkInEntries(actionRequest);
      } else if (cmd.equals(Constants.CHECKOUT)) {
        checkOutEntries(actionRequest);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteEntries(actionRequest, false);
      } else if (cmd.equals(Constants.MOVE)) {
        moveEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteEntries(actionRequest, true);
      } else if (cmd.equals(Constants.RESTORE)) {
        restoreTrashEntries(actionRequest);
      }

      WindowState windowState = actionRequest.getWindowState();

      if (windowState.equals(LiferayWindowState.POP_UP)) {
        String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

        if (Validator.isNotNull(redirect)) {
          sendRedirect(actionRequest, actionResponse, redirect);
        }
      }
    } catch (DuplicateLockException
        | NoSuchFileEntryException
        | NoSuchFolderException
        | PrincipalException e) {

      if (e instanceof DuplicateLockException) {
        DuplicateLockException dle = (DuplicateLockException) e;

        SessionErrors.add(actionRequest, dle.getClass(), dle.getLock());
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }

      actionResponse.setRenderParameter("mvcPath", "/document_library/error.jsp");
    } catch (DuplicateFileEntryException
        | DuplicateFolderNameException
        | SourceFileNameException e) {

      if (e instanceof DuplicateFileEntryException) {
        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

        response.setStatus(ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION);
      }

      SessionErrors.add(actionRequest, e.getClass());
    } catch (AssetCategoryException | AssetTagException | InvalidFolderException e) {

      SessionErrors.add(actionRequest, e.getClass(), e);
    } catch (Exception e) {
      throw new PortletException(e);
    }
  }