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

    try {
      moveCategory(actionRequest, actionResponse);

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

      if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
      }
    } catch (Exception e) {
      if (e instanceof PrincipalException) {
        SessionErrors.add(actionRequest, e.getClass());
      } else {
        throw e;
      }
    }
  }
  @Override
  public void processAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

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

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }

        throw new PortalException(uploadException.getCause());
      } else {
        addFileEntry(actionRequest);
      }

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

      if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
      }
    } catch (Exception e) {
      handleUploadException(actionRequest, actionResponse, e);
    }
  }
  protected void login(
      ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    if (!themeDisplay.isSignedIn()) {
      String portletId = PortalUtil.getPortletId(actionRequest);

      PortletPreferences portletPreferences =
          PortletPreferencesFactoryUtil.getStrictPortletSetup(themeDisplay.getLayout(), portletId);

      String authType = portletPreferences.getValue("authType", null);

      AuthenticatedSessionManagerUtil.login(
          request, response, login, password, rememberMe, authType);
    }

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

    if (Validator.isNotNull(redirect)) {
      redirect = PortalUtil.escapeRedirect(redirect);

      if (Validator.isNotNull(redirect) && !redirect.startsWith(Http.HTTP)) {

        redirect = getCompleteRedirectURL(request, redirect);
      }
    }

    String mainPath = themeDisplay.getPathMain();

    if (PropsValues.PORTAL_JAAS_ENABLE) {
      if (Validator.isNotNull(redirect)) {
        redirect =
            mainPath.concat("/portal/protected?redirect=").concat(HttpUtil.encodeURL(redirect));
      } else {
        redirect = mainPath.concat("/portal/protected");
      }

      actionResponse.sendRedirect(redirect);
    } else {
      if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
      } else {
        boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

        if (doActionAfterLogin) {
          return;
        } else {
          actionResponse.sendRedirect(mainPath);
        }
      }
    }
  }
  protected void sendRedirect(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      ThemeDisplay themeDisplay,
      String login,
      String password)
      throws Exception {

    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);
  }
  public void deletePermission(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    long roleId = ParamUtil.getLong(actionRequest, "roleId");
    String name = ParamUtil.getString(actionRequest, "name");
    int scope = ParamUtil.getInteger(actionRequest, "scope");
    String primKey = ParamUtil.getString(actionRequest, "primKey");
    String actionId = ParamUtil.getString(actionRequest, "actionId");

    Role role = RoleLocalServiceUtil.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_OWNER)
        || roleName.equals(RoleConstants.OWNER)
        || roleName.equals(RoleConstants.SITE_ADMINISTRATOR)
        || roleName.equals(RoleConstants.SITE_OWNER)) {

      throw new RolePermissionsException(roleName);
    }

    if (ResourceBlockLocalServiceUtil.isSupported(name)) {
      if (scope == ResourceConstants.SCOPE_GROUP) {
        ResourceBlockServiceUtil.removeGroupScopePermission(
            themeDisplay.getScopeGroupId(),
            themeDisplay.getCompanyId(),
            GetterUtil.getLong(primKey),
            name,
            roleId,
            actionId);
      } else {
        ResourceBlockServiceUtil.removeCompanyScopePermission(
            themeDisplay.getScopeGroupId(), themeDisplay.getCompanyId(), name, roleId, actionId);
      }
    } else {
      ResourcePermissionServiceUtil.removeResourcePermission(
          themeDisplay.getScopeGroupId(),
          themeDisplay.getCompanyId(),
          name,
          scope,
          primKey,
          roleId,
          actionId);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionDeleted");

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

    if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
  protected void sendRedirect(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String redirect,
      String closeRedirect)
      throws IOException {

    if (isDisplaySuccessMessage(actionRequest)) {
      addSuccessMessage(actionRequest, actionResponse);
    }

    if (Validator.isNull(redirect)) {
      redirect = (String) actionRequest.getAttribute(WebKeys.REDIRECT);
    }

    if (Validator.isNull(redirect)) {
      redirect = ParamUtil.getString(actionRequest, "redirect");
    }

    if ((portletConfig != null)
        && Validator.isNotNull(redirect)
        && Validator.isNotNull(closeRedirect)) {

      redirect = HttpUtil.setParameter(redirect, "closeRedirect", closeRedirect);

      SessionMessages.add(
          actionRequest,
          PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_CLOSE_REDIRECT,
          closeRedirect);
    }

    if (Validator.isNull(redirect)) {
      return;
    }

    // LPS-1928

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    if (BrowserSnifferUtil.isIe(request)
        && (BrowserSnifferUtil.getMajorVersion(request) == 6.0)
        && redirect.contains(StringPool.POUND)) {

      String redirectToken = "&#";

      if (!redirect.contains(StringPool.QUESTION)) {
        redirectToken = StringPool.QUESTION + redirectToken;
      }

      redirect = StringUtil.replace(redirect, StringPool.POUND, redirectToken);
    }

    redirect = PortalUtil.escapeRedirect(redirect);

    if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
  protected void sendEditEntryRedirect(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    WindowState windowState = actionRequest.getWindowState();

    if (!windowState.equals(LiferayWindowState.POP_UP)) {
      sendRedirect(actionRequest, actionResponse);
    } else if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
  @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);
      }
    }
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    try {
      moveCategory(actionRequest, actionResponse);

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

      if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
      }
    } catch (PrincipalException pe) {
      SessionErrors.add(actionRequest, pe.getClass());
    }
  }
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

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

    try {
      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
        updatePasswordPolicy(actionRequest);
      } else if (cmd.equals(Constants.DELETE)) {
        deletePasswordPolicy(actionRequest);
      }

      sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
      if (e instanceof PrincipalException) {
        SessionErrors.add(actionRequest, e.getClass());

        setForward(actionRequest, "portlet.password_policies_admin.error");
      } else if (e instanceof DuplicatePasswordPolicyException
          || e instanceof PasswordPolicyNameException
          || e instanceof NoSuchPasswordPolicyException
          || e instanceof RequiredPasswordPolicyException) {

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

        if (cmd.equals(Constants.DELETE)) {
          String redirect =
              PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

          if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
          }
        }
      } else {
        throw e;
      }
    }
  }
Beispiel #11
0
  @Override
  public void processAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

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

    try {
      if (cmd.equals(Constants.DELETE) || cmd.equals(Constants.DELETE_VERSIONS)) {

        deleteEntries(actionRequest, false);
      } else if (cmd.equals(Constants.EXPIRE)) {
        expireEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE)) {
        moveEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteEntries(actionRequest, true);
      }

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

      if (cmd.equals(Constants.DELETE_VERSIONS) && !ActionUtil.hasArticle(actionRequest)) {

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

        if (Validator.isNotNull(referringPortletResource)) {
          setForward(actionRequest, "portlet.journal.asset.add_asset_redirect");

          return;
        } else {
          ThemeDisplay themeDisplay =
              (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

          PortletURL portletURL =
              PortletURLFactoryUtil.create(
                  actionRequest,
                  portletConfig.getPortletName(),
                  themeDisplay.getPlid(),
                  PortletRequest.RENDER_PHASE);

          redirect = portletURL.toString();
        }
      }

      WindowState windowState = actionRequest.getWindowState();

      if (!windowState.equals(LiferayWindowState.POP_UP)) {
        sendRedirect(actionRequest, actionResponse);
      } else if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
      }
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException
          || e instanceof NoSuchFolderException
          || e instanceof PrincipalException) {

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

        setForward(actionRequest, "portlet.journal.error");
      } else if (e instanceof DuplicateArticleIdException
          || e instanceof DuplicateFolderNameException
          || e instanceof NoSuchFolderException) {

        SessionErrors.add(actionRequest, e.getClass());
      } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } 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);
    }
  }
  protected void sendEditArticleRedirect(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      JournalArticle article,
      String oldUrlTitle)
      throws Exception {

    String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

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

    int workflowAction =
        ParamUtil.getInteger(actionRequest, "workflowAction", WorkflowConstants.ACTION_PUBLISH);

    String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

    String namespace = PortalUtil.getPortletNamespace(portletId);

    if (Validator.isNotNull(oldUrlTitle)) {
      String oldRedirectParam = namespace + "redirect";

      String oldRedirect = HttpUtil.getParameter(redirect, oldRedirectParam, false);

      if (Validator.isNotNull(oldRedirect)) {
        String newRedirect = HttpUtil.decodeURL(oldRedirect);

        newRedirect = StringUtil.replace(newRedirect, oldUrlTitle, article.getUrlTitle());
        newRedirect = StringUtil.replace(newRedirect, oldRedirectParam, "redirect");

        redirect = StringUtil.replace(redirect, oldRedirect, newRedirect);
      }
    }

    if ((actionName.equals("deleteArticle") || actionName.equals("deleteArticles"))
        && !ActionUtil.hasArticle(actionRequest)) {

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

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

      redirect = portletURL.toString();
    }

    if ((article != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

      redirect = getSaveAndContinueRedirect(actionRequest, article, redirect);

      if (actionName.equals("previewArticle")) {
        SessionMessages.add(actionRequest, "previewRequested");

        hideDefaultSuccessMessage(actionRequest);
      }
    } else {
      WindowState windowState = actionRequest.getWindowState();

      if (windowState.equals(LiferayWindowState.POP_UP)) {
        redirect = PortalUtil.escapeRedirect(redirect);

        if (Validator.isNotNull(redirect)) {
          if (actionName.equals("addArticle") && (article != null)) {
            redirect =
                HttpUtil.addParameter(
                    redirect, namespace + "className", JournalArticle.class.getName());
            redirect =
                HttpUtil.addParameter(
                    redirect,
                    namespace + "classPK",
                    JournalArticleAssetRenderer.getClassPK(article));
          }

          actionResponse.sendRedirect(redirect);
        }
      }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
  }
  @Override
  protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    FileEntry fileEntry = null;

    PortletConfig portletConfig = getPortletConfig(actionRequest);

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

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }

        throw new PortalException(uploadException.getCause());
      } else if (cmd.equals(Constants.ADD)
          || cmd.equals(Constants.ADD_DYNAMIC)
          || cmd.equals(Constants.UPDATE)
          || cmd.equals(Constants.UPDATE_AND_CHECKIN)) {

        fileEntry = updateFileEntry(portletConfig, actionRequest, actionResponse);
      } else if (cmd.equals(Constants.ADD_MULTIPLE)) {
        addMultipleFileEntries(portletConfig, actionRequest, actionResponse);

        hideDefaultSuccessMessage(actionRequest);
      } else if (cmd.equals(Constants.ADD_TEMP)) {
        addTempFileEntry(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteFileEntry(actionRequest, false);
      } else if (cmd.equals(Constants.DELETE_TEMP)) {
        deleteTempFileEntry(actionRequest, actionResponse);
      } else if (cmd.equals(Constants.CANCEL_CHECKOUT)) {
        cancelFileEntriesCheckOut(actionRequest);
      } else if (cmd.equals(Constants.CHECKIN)) {
        checkInFileEntries(actionRequest);
      } else if (cmd.equals(Constants.CHECKOUT)) {
        checkOutFileEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteFileEntry(actionRequest, true);
      } else if (cmd.equals(Constants.RESTORE)) {
        restoreTrashEntries(actionRequest);
      } else if (cmd.equals(Constants.REVERT)) {
        revertFileEntry(actionRequest);
      }

      WindowState windowState = actionRequest.getWindowState();

      if (cmd.equals(Constants.ADD_TEMP) || cmd.equals(Constants.DELETE_TEMP)) {

        actionResponse.setRenderParameter("mvcPath", "/null.jsp");
      } else if (cmd.equals(Constants.PREVIEW)) {
      } else if (!windowState.equals(LiferayWindowState.POP_UP)) {
      } else {
        String redirect = ParamUtil.getString(actionRequest, "redirect");
        int workflowAction =
            ParamUtil.getInteger(
                actionRequest, "workflowAction", WorkflowConstants.ACTION_SAVE_DRAFT);

        if ((fileEntry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

          redirect = getSaveAndContinueRedirect(portletConfig, actionRequest, fileEntry, redirect);

          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          if (windowState.equals(LiferayWindowState.POP_UP)) {
            redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

            if (Validator.isNotNull(redirect)) {
              if (cmd.equals(Constants.ADD) && (fileEntry != null)) {

                String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

                String namespace = PortalUtil.getPortletNamespace(portletId);

                redirect =
                    HttpUtil.addParameter(
                        redirect, namespace + "className", DLFileEntry.class.getName());
                redirect =
                    HttpUtil.addParameter(
                        redirect, namespace + "classPK", fileEntry.getFileEntryId());
              }

              sendRedirect(actionRequest, actionResponse, redirect);
            }
          }
        }
      }
    } catch (Exception e) {
      handleUploadException(portletConfig, actionRequest, actionResponse, cmd, e);
    }
  }
  public void updateActions(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

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

    Role role = RoleLocalServiceUtil.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_OWNER)
        || roleName.equals(RoleConstants.OWNER)
        || roleName.equals(RoleConstants.SITE_ADMINISTRATOR)
        || roleName.equals(RoleConstants.SITE_OWNER)) {

      throw new RolePermissionsException(roleName);
    }

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String[] relatedPortletResources =
        StringUtil.split(ParamUtil.getString(actionRequest, "relatedPortletResources"));
    String[] modelResources =
        StringUtil.split(ParamUtil.getString(actionRequest, "modelResources"));

    Map<String, List<String>> resourceActionsMap = new HashMap<>();

    if (Validator.isNotNull(portletResource)) {
      resourceActionsMap.put(
          portletResource, ResourceActionsUtil.getResourceActions(portletResource, null));
    }

    for (String relatedPortletResource : relatedPortletResources) {
      resourceActionsMap.put(
          relatedPortletResource,
          ResourceActionsUtil.getResourceActions(relatedPortletResource, null));
    }

    for (String modelResource : modelResources) {
      resourceActionsMap.put(
          modelResource, ResourceActionsUtil.getResourceActions(null, modelResource));
    }

    int rootResourceScope = ResourceConstants.SCOPE_COMPANY;
    String[] rootResourceGroupIds = null;

    String[] selectedTargets =
        StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets"));
    String[] unselectedTargets =
        StringUtil.split(ParamUtil.getString(actionRequest, "unselectedTargets"));

    for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) {

      String selResource = entry.getKey();
      List<String> actions = entry.getValue();

      actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale()));

      for (String actionId : actions) {
        String target = selResource + actionId;

        boolean selected = ArrayUtil.contains(selectedTargets, target);

        if (!selected && !ArrayUtil.contains(unselectedTargets, target)) {

          continue;
        }

        String[] groupIds =
            StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target));

        groupIds = ArrayUtil.distinct(groupIds);

        int scope = ResourceConstants.SCOPE_COMPANY;

        if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
            || (role.getType() == RoleConstants.TYPE_PROVIDER)
            || (role.getType() == RoleConstants.TYPE_SITE)) {

          scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
        } else {
          if (groupIds.length > 0) {
            scope = ResourceConstants.SCOPE_GROUP;
          }
        }

        if (ResourceBlockLocalServiceUtil.isSupported(selResource)) {
          updateActions_Blocks(
              role,
              themeDisplay.getScopeGroupId(),
              selResource,
              actionId,
              selected,
              scope,
              groupIds);
        } else {
          updateAction(
              role,
              themeDisplay.getScopeGroupId(),
              selResource,
              actionId,
              selected,
              scope,
              groupIds);
        }

        if (selected && actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL)) {

          updateViewControlPanelPermission(
              role, themeDisplay.getScopeGroupId(), selResource, scope, groupIds);

          rootResourceScope = scope;
          rootResourceGroupIds = groupIds;
        }
      }
    }

    // LPS-38031

    if (rootResourceGroupIds != null) {
      updateViewRootResourcePermission(
          role,
          themeDisplay.getScopeGroupId(),
          portletResource,
          rootResourceScope,
          rootResourceGroupIds);
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionsUpdated");

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

    if (Validator.isNotNull(redirect)) {
      actionResponse.sendRedirect(redirect);
    }
  }
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

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

    try {
      BlogsEntry entry = null;
      String oldUrlTitle = StringPool.BLANK;

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
        Object[] returnValue = updateEntry(actionRequest);

        entry = (BlogsEntry) returnValue[0];
        oldUrlTitle = ((String) returnValue[1]);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteEntries(actionRequest);
      } else if (cmd.equals(Constants.SUBSCRIBE)) {
        subscribe(actionRequest);
      } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
        unsubscribe(actionRequest);
      }

      String redirect = ParamUtil.getString(actionRequest, "redirect");
      boolean updateRedirect = false;

      if (redirect.contains("/blogs/" + oldUrlTitle + "/maximized")) {
        oldUrlTitle += "/maximized";
      }

      if ((entry != null)
          && (Validator.isNotNull(oldUrlTitle))
          && (redirect.endsWith("/blogs/" + oldUrlTitle)
              || redirect.contains("/blogs/" + oldUrlTitle + "?")
              || redirect.contains("/blog/" + oldUrlTitle + "?"))) {

        int pos = redirect.indexOf("?");

        if (pos == -1) {
          pos = redirect.length();
        }

        String newRedirect = redirect.substring(0, pos - oldUrlTitle.length());

        newRedirect += entry.getUrlTitle();

        if (oldUrlTitle.indexOf("/maximized") != -1) {
          newRedirect += "/maximized";
        }

        if (pos < redirect.length()) {
          newRedirect += "?" + redirect.substring(pos + 1);
        }

        redirect = newRedirect;
        updateRedirect = true;
      }

      int workflowAction =
          ParamUtil.getInteger(
              actionRequest, "workflowAction", WorkflowConstants.ACTION_SAVE_DRAFT);

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

      if (ajax) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("entryId", entry.getEntryId());
        jsonObject.put("redirect", redirect);
        jsonObject.put("updateRedirect", updateRedirect);

        writeJSON(actionRequest, actionResponse, jsonObject);

        return;
      }

      if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

        redirect = getSaveAndContinueRedirect(portletConfig, actionRequest, entry, redirect);

        sendRedirect(actionRequest, actionResponse, redirect);
      } else {
        WindowState windowState = actionRequest.getWindowState();

        if (!windowState.equals(LiferayWindowState.POP_UP)) {
          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          redirect = PortalUtil.escapeRedirect(redirect);

          if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
          }
        }
      }
    } catch (Exception e) {
      if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

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

        setForward(actionRequest, "portlet.blogs.error");
      } else if (e instanceof EntryContentException
          || e instanceof EntryDisplayDateException
          || e instanceof EntrySmallImageNameException
          || e instanceof EntrySmallImageSizeException
          || e instanceof EntryTitleException) {

        SessionErrors.add(actionRequest, e.getClass().getName());
      } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass().getName(), e);
      } else {
        throw e;
      }
    }
  }
  @Override
  public void processAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

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

    try {
      Organization organization = null;

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
        organization = updateOrganization(actionRequest);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteOrganizations(actionRequest);
      }

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

      if (organization != null) {
        redirect =
            HttpUtil.setParameter(
                redirect,
                actionResponse.getNamespace() + "organizationId",
                organization.getOrganizationId());
      }

      sendRedirect(actionRequest, actionResponse, redirect);
    } catch (Exception e) {
      if (e instanceof NoSuchOrganizationException || e instanceof PrincipalException) {

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

        setForward(actionRequest, "portlet.users_admin.error");
      } else if (e instanceof AddressCityException
          || e instanceof AddressStreetException
          || e instanceof AddressZipException
          || e instanceof DuplicateOrganizationException
          || e instanceof EmailAddressException
          || e instanceof NoSuchCountryException
          || e instanceof NoSuchListTypeException
          || e instanceof NoSuchRegionException
          || e instanceof OrganizationNameException
          || e instanceof OrganizationParentException
          || e instanceof PhoneNumberException
          || e instanceof RequiredOrganizationException
          || e instanceof WebsiteURLException) {

        if (e instanceof NoSuchListTypeException) {
          NoSuchListTypeException nslte = (NoSuchListTypeException) e;

          SessionErrors.add(actionRequest, e.getClass().getName() + nslte.getType());
        } else {
          SessionErrors.add(actionRequest, e.getClass());
        }

        if (e instanceof RequiredOrganizationException) {
          String redirect =
              PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

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

          if (organizationId > 0) {
            redirect =
                HttpUtil.setParameter(
                    redirect, actionResponse.getNamespace() + "organizationId", organizationId);
          }

          if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
          }
        }
      } else {
        throw e;
      }
    }
  }
  protected void login(
      ThemeDisplay themeDisplay,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      PortletPreferences preferences)
      throws Exception {

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

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    String authType = preferences.getValue("authType", null);

    // cusotm code =============
    try {
      User tmp = null;
      UserEntry userEntryTmp = null;
      if (Validator.isEmailAddress(login)) {
        tmp = UserLocalServiceUtil.getUserByEmailAddress(PortalUtil.getCompanyId(request), login);
        login = String.valueOf(tmp.getUserId());
        System.out.println("email:" + login);
      } else if (Validator.isNumber(login)) {
        // is mobile number
        //				UserEntryLocalServiceUtil.get
        userEntryTmp = UserEntryLocalServiceUtil.findByMobilePhone(login);
        login = String.valueOf(userEntryTmp.getUserId());
        System.out.println("mobile number:" + login);
      } else {
        // userEntryTmp = UserEntryLocalServiceUtil.findByUserName(login);
        tmp = UserLocalServiceUtil.getUserByScreenName(PortalUtil.getCompanyId(request), login);
        login = String.valueOf(tmp.getUserId());
        System.out.println("userName:"******"/portal/protected");
    } else {
      String redirect = ParamUtil.getString(actionRequest, "redirect");

      if (Validator.isNotNull(redirect)) {
        redirect = PortalUtil.escapeRedirect(redirect);

        if (!redirect.startsWith(Http.HTTP)) {
          redirect = getCompleteRedirectURL(request, redirect);
        }

        actionResponse.sendRedirect(redirect);
      } else {
        boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

        if (doActionAfterLogin) {
          return;
        } else {
          actionResponse.sendRedirect(themeDisplay.getPathMain());
        }
      }
    }
  }
  protected void updateActions(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

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

    Role role = RoleLocalServiceUtil.getRole(roleId);

    String roleName = role.getName();

    if (roleName.equals(RoleConstants.ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR)
        || roleName.equals(RoleConstants.ORGANIZATION_OWNER)
        || roleName.equals(RoleConstants.OWNER)
        || roleName.equals(RoleConstants.SITE_ADMINISTRATOR)
        || roleName.equals(RoleConstants.SITE_OWNER)) {

      throw new RolePermissionsException(roleName);
    }

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");
    String[] modelResources =
        StringUtil.split(ParamUtil.getString(actionRequest, "modelResources"));
    boolean showModelResources = ParamUtil.getBoolean(actionRequest, "showModelResources");

    Map<String, List<String>> resourceActionsMap = new HashMap<String, List<String>>();

    if (showModelResources) {
      for (String modelResource : modelResources) {
        resourceActionsMap.put(
            modelResource, ResourceActionsUtil.getResourceActions(null, modelResource));
      }
    } else if (Validator.isNotNull(portletResource)) {
      resourceActionsMap.put(
          portletResource, ResourceActionsUtil.getResourceActions(portletResource, null));
    }

    String[] selectedTargets =
        StringUtil.split(ParamUtil.getString(actionRequest, "selectedTargets"));

    for (Map.Entry<String, List<String>> entry : resourceActionsMap.entrySet()) {

      String selResource = entry.getKey();
      List<String> actions = entry.getValue();

      actions = ListUtil.sort(actions, new ActionComparator(themeDisplay.getLocale()));

      for (String actionId : actions) {
        String target = selResource + actionId;

        boolean selected = ArrayUtil.contains(selectedTargets, target);

        String[] groupIds =
            StringUtil.split(ParamUtil.getString(actionRequest, "groupIds" + target));

        groupIds = ArrayUtil.distinct(groupIds);

        int scope = ResourceConstants.SCOPE_COMPANY;

        if ((role.getType() == RoleConstants.TYPE_ORGANIZATION)
            || (role.getType() == RoleConstants.TYPE_PROVIDER)
            || (role.getType() == RoleConstants.TYPE_SITE)) {

          scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
        } else {
          if (groupIds.length > 0) {
            scope = ResourceConstants.SCOPE_GROUP;
          }
        }

        if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
          if (ResourceBlockLocalServiceUtil.isSupported(selResource)) {

            updateActions_6Blocks(
                role,
                themeDisplay.getScopeGroupId(),
                selResource,
                actionId,
                selected,
                scope,
                groupIds);
          } else {
            updateAction_6(
                role,
                themeDisplay.getScopeGroupId(),
                selResource,
                actionId,
                selected,
                scope,
                groupIds);
          }
        } else {
          updateAction_1to5(
              role,
              themeDisplay.getScopeGroupId(),
              selResource,
              actionId,
              selected,
              scope,
              groupIds);
        }
      }
    }

    // Send redirect

    SessionMessages.add(actionRequest, "permissionsUpdated");

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

    if (Validator.isNotNull(redirect)) {
      redirect = redirect + "&" + Constants.CMD + "=" + Constants.VIEW;

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

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

    try {
      BlogsEntry entry = null;
      String oldUrlTitle = StringPool.BLANK;
      List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = null;

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

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }

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

        Callable<Object[]> updateEntryCallable = new UpdateEntryCallable(actionRequest);

        Object[] returnValue =
            TransactionInvokerUtil.invoke(_transactionAttribute, updateEntryCallable);

        entry = (BlogsEntry) returnValue[0];
        oldUrlTitle = ((String) returnValue[1]);
        blogsEntryAttachmentFileEntryReferences =
            ((List<BlogsEntryAttachmentFileEntryReference>) returnValue[2]);
      } else if (cmd.equals(Constants.DELETE)) {
        deleteEntries(actionRequest, false);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteEntries(actionRequest, true);
      } else if (cmd.equals(Constants.RESTORE)) {
        restoreTrashEntries(actionRequest);
      } else if (cmd.equals(Constants.SUBSCRIBE)) {
        subscribe(actionRequest);
      } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
        unsubscribe(actionRequest);
      }

      String redirect = ParamUtil.getString(actionRequest, "redirect");
      boolean updateRedirect = false;

      String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

      if (Validator.isNotNull(oldUrlTitle)) {
        String oldRedirectParam = PortalUtil.getPortletNamespace(portletId) + "redirect";

        String oldRedirect = HttpUtil.getParameter(redirect, oldRedirectParam, false);

        if (Validator.isNotNull(oldRedirect)) {
          String newRedirect = HttpUtil.decodeURL(oldRedirect);

          newRedirect = StringUtil.replace(newRedirect, oldUrlTitle, entry.getUrlTitle());
          newRedirect = StringUtil.replace(newRedirect, oldRedirectParam, "redirect");

          redirect = StringUtil.replace(redirect, oldRedirect, newRedirect);
        } else if (redirect.endsWith("/blogs/" + oldUrlTitle)
            || redirect.contains("/blogs/" + oldUrlTitle + "?")
            || redirect.contains("/blog/" + oldUrlTitle + "?")) {

          redirect = StringUtil.replace(redirect, oldUrlTitle, entry.getUrlTitle());
        }

        updateRedirect = true;
      }

      int workflowAction =
          ParamUtil.getInteger(
              actionRequest, "workflowAction", WorkflowConstants.ACTION_SAVE_DRAFT);

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

      if (ajax) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

        for (BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference :
            blogsEntryAttachmentFileEntryReferences) {

          JSONObject blogsEntryFileEntryReferencesJSONObject = JSONFactoryUtil.createJSONObject();

          blogsEntryFileEntryReferencesJSONObject.put(
              "attributeDataImageId", EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
          blogsEntryFileEntryReferencesJSONObject.put(
              "fileEntryId",
              String.valueOf(
                  blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId()));
          blogsEntryFileEntryReferencesJSONObject.put(
              "fileEntryUrl",
              PortletFileRepositoryUtil.getPortletFileEntryURL(
                  null,
                  blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry(),
                  StringPool.BLANK));

          jsonArray.put(blogsEntryFileEntryReferencesJSONObject);
        }

        jsonObject.put("blogsEntryAttachmentReferences", jsonArray);

        jsonObject.put("entryId", entry.getEntryId());
        jsonObject.put("redirect", redirect);
        jsonObject.put("updateRedirect", updateRedirect);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

        return;
      }

      if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

        redirect = getSaveAndContinueRedirect(actionRequest, entry, redirect);

        sendRedirect(actionRequest, actionResponse, redirect);
      } else {
        WindowState windowState = actionRequest.getWindowState();

        if (!windowState.equals(LiferayWindowState.POP_UP)) {
          sendRedirect(actionRequest, actionResponse, redirect);
        } else {
          redirect = PortalUtil.escapeRedirect(redirect);

          if (Validator.isNotNull(redirect)) {
            if (cmd.equals(Constants.ADD) && (entry != null)) {
              String namespace = PortalUtil.getPortletNamespace(portletId);

              redirect =
                  HttpUtil.addParameter(
                      redirect, namespace + "className", BlogsEntry.class.getName());
              redirect = HttpUtil.addParameter(redirect, namespace + "classPK", entry.getEntryId());
            }

            sendRedirect(actionRequest, actionResponse, redirect);
          }
        }
      }
    } catch (Exception e) {
      String mvcPath = "/blogs/edit_entry.jsp";

      if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

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

        mvcPath = "/blogs/error.jsp";
      } else if (e instanceof EntryContentException
          || e instanceof EntryCoverImageCropException
          || e instanceof EntryDescriptionException
          || e instanceof EntryDisplayDateException
          || e instanceof EntrySmallImageNameException
          || e instanceof EntrySmallImageScaleException
          || e instanceof EntryTitleException
          || e instanceof FileSizeException
          || e instanceof LiferayFileItemException
          || e instanceof SanitizerException) {

        SessionErrors.add(actionRequest, e.getClass());
      } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        Throwable cause = e.getCause();

        if (cause instanceof SanitizerException) {
          SessionErrors.add(actionRequest, SanitizerException.class);
        } else {
          throw e;
        }
      }

      actionResponse.setRenderParameter("mvcPath", mvcPath);
    } catch (Throwable t) {
      _log.error(t, t);

      actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");
    }
  }