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 processTab(ActionResponse actionResponse, String tab)
     throws PortletException, IOException {
   if (tab.equals(PARAMV_TAB_GEOTHESAURUS)) {
     actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_GEOTHESAURUS));
   } else if (tab.equals(PARAMV_TAB_MAP)) {
     actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_MAP));
   } else {
     super.processTab(actionResponse, tab);
   }
 }
  @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);
      }
    }
  }
  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);
  }
  @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;
      }
    }
  }
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    Set<Long> messages = new HashSet<Long>();
    ThemeDisplay themedisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long userId = themedisplay.getUserId();
    String redirect = ParamUtil.getString(actionRequest, MessageConstants.REDIRECT);
    String[] msgs =
        ParamUtil.getString(actionRequest, MessageConstants.MOVE_MESSAGE_IDS, "").split(",");

    for (String s : msgs) {
      if (s.trim().length() == 0) continue;
      long messageId = Long.parseLong(s);
      Message m = MessageLocalServiceUtil.getMessage(messageId);
      if (!m.isArchived(userId)) {
        m.setArchived(userId);
      }
    }
    actionResponse.sendRedirect(redirect);
  }
  @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 remoteProcessAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, getServerPortletURL());

    setRequestParameters(actionRequest, actionResponse, oAuthRequest);

    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "1");
    addOAuthParameter(oAuthRequest, "p_p_state", WindowState.NORMAL.toString());

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    if (response.getCode() == HttpServletResponse.SC_FOUND) {
      String redirectLocation = response.getHeader(HttpHeaders.LOCATION);

      actionResponse.sendRedirect(redirectLocation);
    } else {
      HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);

      httpServletResponse.setContentType(response.getHeader(HttpHeaders.CONTENT_TYPE));

      ServletResponseUtil.write(httpServletResponse, response.getStream());
    }
  }
Example #9
0
  private void _import(ActionRequest req, ActionResponse res) throws Exception {

    UploadPortletRequest uploadReq = PortalUtil.getUploadPortletRequest(req);

    String importerType = ParamUtil.get(uploadReq, "importer_type", ABUtil.IE_OUTLOOK);

    byte[] bytes = FileUtil.getBytes(uploadReq.getFile("import_file"));

    if (bytes == null || bytes.length == 0) {
      throw new UploadException();
    }

    Importer importer = null;

    if (importerType.equals(ABUtil.IE_OUTLOOK)) {
      importer = new OutlookImporter();
    } else if (importerType.equals(ABUtil.IE_YAHOO)) {
      importer = new OutlookImporter();
    }

    if (importer != null) {
      importer.setData(bytes);

      ABContactServiceUtil.addContacts(importer);
    }

    // Send redirect

    res.sendRedirect(ParamUtil.getString(req, "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);
    }
  }
  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 forwardCheckout(
      ActionRequest actionRequest, ActionResponse actionResponse, ShoppingOrder order)
      throws Exception {

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

    ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

    ShoppingWebComponentProvider shoppingWebComponentProvider =
        ShoppingWebComponentProvider.getShoppingWebComponentProvider();

    SettingsFactory settingsFactory = shoppingWebComponentProvider.getSettingsFactory();

    ShoppingGroupServiceSettings shoppingGroupServiceSettings =
        settingsFactory.getSettings(
            ShoppingGroupServiceSettings.class,
            new GroupServiceSettingsLocator(
                themeDisplay.getScopeGroupId(), ShoppingConstants.SERVICE_NAME));

    String returnURL =
        ShoppingUtil.getPayPalReturnURL(
            ((ActionResponseImpl) actionResponse).createActionURL(), order);
    String notifyURL = ShoppingUtil.getPayPalNotifyURL(themeDisplay);

    if (shoppingGroupServiceSettings.usePayPal()) {
      double total =
          ShoppingUtil.calculateTotal(
              cart.getItems(),
              order.getBillingState(),
              cart.getCoupon(),
              cart.getAltShipping(),
              cart.isInsure());

      String redirectURL =
          ShoppingUtil.getPayPalRedirectURL(
              shoppingGroupServiceSettings, order, total, returnURL, notifyURL);

      actionResponse.sendRedirect(redirectURL);
    } else {
      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

      ShoppingOrderLocalServiceUtil.sendEmail(order, "confirmation", serviceContext);

      actionResponse.sendRedirect(returnURL);
    }
  }
  @Override
  public void sendRedirect(String location) throws IOException {
    if (!_include) {
      if (_lifecycle.equals(PortletRequest.ACTION_PHASE)) {
        ActionResponse actionResponse = _getActionResponse();

        actionResponse.sendRedirect(location);
      }
    }
  }
  /**
   * @param request the request being processed
   * @param response the response to return
   * @param preferences the portlet preferences
   */
  @ActionMapping(params = Consts.ACTION_ENDDELEGATEMODE)
  public void doActionEndDelegationMode(
      ActionRequest request, ActionResponse response, PortletPreferences preferences, Model model)
      throws Exception {
    LogHelper log = new LogHelper(request);
    RequestMessages rqm = RequestMessages.getRequestMessages(request);
    PortletSession session = request.getPortletSession();
    try {
      log.startTimer("doActionEndDelegationMode");
      BannerPortletData data =
          (BannerPortletData)
              session.getAttribute("BannerPortletData", PortletSession.APPLICATION_SCOPE);
      if (data == null) {
        data = new BannerPortletData();
        data.loadFromRequest(request);
        data.loadFromPreferences(request, rqm);
      }
      // ProtectBlock actionEndDelegationModeBody
      logger.debug("In the doActionEndDelegationMode of ServiceCreditsDeleationView Controller ");
      log.startTimer("doActionEndDelegationMode");
      // logger.info("In the doActionEndDelegationMode,Sessin clean up triggred. "
      // +session.getAttributeMap(PortletSession.APPLICATION_SCOPE).keySet());
      logger.info(
          "Clearing all session attribute set by the ServiceCreditsDelegationView Controller : "
              + Consts.SESSION_SUBJECT_USER_MAP
              + " "
              + Consts.TEMP_SUBJECT_USER_MAP_KEY_IN_SESSION);
      session.removeAttribute(Consts.SESSION_SUBJECT_USER_MAP, PortletSession.APPLICATION_SCOPE);
      session.removeAttribute(
          Consts.TEMP_SUBJECT_USER_MAP_KEY_IN_SESSION, PortletSession.APPLICATION_SCOPE);

      // logger.info("In the doActionEndDelegationMode,Sessin clean up triggred. "
      // +session.getAttributeMap(PortletSession.APPLICATION_SCOPE).keySet());
      logger.debug("Setting the Session Cleanup flag to true");
      // request.setAttribute("spf.cleanupSession", true);
      logger.debug("Ending the Delegation session");
      logger.info("Sending redirect to ServiceCredits home page");
      PortalURL url = Utility.getServiceCreditsHomeUrl(request);
      url.setParameter("spf.cleanupSession", "true");
      response.sendRedirect(url.toString());
      logger.debug("End of doActionEndDelegationMode of ServiceCreditsDeleationView Controller ");
      // TODO Fill In Action Body
      // ProtectBlock End
      session.setAttribute("BannerPortletData", data, PortletSession.APPLICATION_SCOPE);
    } catch (Exception ex) {
      log.endTimer("doActionEndDelegationMode");
      throw ex;
    } finally {
      rqm.saveToRequest();
      session.setAttribute("ActionMode", "action", PortletSession.PORTLET_SCOPE);
      log.endTimer("doActionEndDelegationMode");
    }
  }
Example #15
0
  protected void forwardCheckout(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

    ShoppingOrder order = (ShoppingOrder) actionRequest.getAttribute(WebKeys.SHOPPING_ORDER);

    ShoppingPreferences preferences =
        ShoppingPreferences.getInstance(
            themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId());

    String returnURL =
        ShoppingUtil.getPayPalReturnURL(
            ((ActionResponseImpl) actionResponse).createActionURL(), order);
    String notifyURL = ShoppingUtil.getPayPalNotifyURL(themeDisplay);

    if (preferences.usePayPal()) {
      double total =
          ShoppingUtil.calculateTotal(
              cart.getItems(),
              order.getBillingState(),
              cart.getCoupon(),
              cart.getAltShipping(),
              cart.isInsure());

      String redirectURL =
          ShoppingUtil.getPayPalRedirectURL(preferences, order, total, returnURL, notifyURL);

      actionResponse.sendRedirect(redirectURL);
    } else {
      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

      ShoppingOrderLocalServiceUtil.sendEmail(order, "confirmation", serviceContext);

      actionResponse.sendRedirect(returnURL);
    }
  }
  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);
    }
  }
  @ActionMapping(params = "action=dettaglio")
  public void actionDettaglio(
      ActionRequest aRequest,
      ActionResponse aResponse,
      Model model,
      @ModelAttribute("navigaProgetti") NavigaProgetti navigaProgetti,
      @RequestParam(value = "idProgettoDettaglio") String idProgettoDettaglio,
      @RequestParam(value = "currentAction") String currentAction,
      @RequestParam(required = false, value = "cercaPerKeyword") String cercaPerKeyword) {

    navigaProgetti.setIdProgetto(idProgettoDettaglio);
    LiferayPortletURL renderURL =
        createLiferayPortletURL(aRequest, paginaDettaglioProgetto, dettaglioProgettoInstanceId);

    renderURL.setParameter("idPj", idProgettoDettaglio);

    try {

      ThemeDisplay themeDisplay = (ThemeDisplay) aRequest.getAttribute(WebKeys.THEME_DISPLAY);
      PortletURL returnURL =
          PortletURLFactoryUtil.create(
              aRequest,
              (String) aRequest.getAttribute(WebKeys.PORTLET_ID),
              themeDisplay.getLayout().getPlid(),
              PortletRequest.RENDER_PHASE);
      returnURL.setWindowState(WindowState.NORMAL);
      returnURL.setPortletMode(PortletMode.VIEW);
      // returnURL.setParameter("jsonnavigaprogetti",
      // createJsonStringFromModelAttribute(navigaProgetti));
      returnURL.setParameter("action", currentAction);
      if (!StringUtils.isEmpty(cercaPerKeyword)) {
        returnURL.setParameter("cercaPerKeyword", cercaPerKeyword);
      }

      renderURL.setParameter("returnUrl", returnURL.toString());

    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      aResponse.sendRedirect(
          HttpUtil.encodeParameters(
              renderURL.toString())); //  + "&idPj="+navigaProgetti.getIdProgetto() ) );
      return;
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig config,
      ActionRequest req,
      ActionResponse res)
      throws Exception {

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

    try {
      Organization organization = null;

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

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

      if (organization != null) {
        redirect += organization.getOrganizationId();
      }

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

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

        setForward(req, "portlet.enterprise_admin.error");
      } else if (e instanceof DuplicateOrganizationException
          || e instanceof NoSuchCountryException
          || e instanceof NoSuchListTypeException
          || e instanceof OrganizationNameException
          || e instanceof OrganizationParentException
          || e instanceof RequiredOrganizationException) {

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

        if (e instanceof RequiredOrganizationException) {
          res.sendRedirect(ParamUtil.getString(req, "redirect"));
        }
      } else {
        throw e;
      }
    }
  }
  public void deauthorize(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    oAuthManager.deleteAccessToken(themeDisplay.getUser());

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

    PortletURL portletURL = liferayPortletResponse.createRenderURL();

    portletURL.setParameter("mvcPath", "/view.jsp");

    actionResponse.sendRedirect(portletURL.toString());
  }
  /* (non-Javadoc)
   * @see org.springframework.webflow.mvc.portlet.AbstractFlowHandler#handleExecutionOutcome(org.springframework.webflow.execution.FlowExecutionOutcome, javax.portlet.ActionRequest, javax.portlet.ActionResponse)
   */
  @Override
  public boolean handleExecutionOutcome(
      FlowExecutionOutcome outcome, ActionRequest request, ActionResponse response) {
    if (this.redirectOnEnd != null) {
      final String redirectPath = request.getContextPath() + this.redirectOnEnd;
      try {
        response.sendRedirect(redirectPath);
        return true;
      } catch (IOException e) {
        this.logger.warn("Failed to send flow-end redirect to '" + redirectPath + "'");
      }
    }

    return false;
  }
  protected void handleUploadException(
      ActionRequest actionRequest, ActionResponse actionResponse, Exception e) throws Exception {

    if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

      SessionErrors.add(actionRequest, e.getClass(), e);
    } else if (e instanceof AntivirusScannerException
        || e instanceof DuplicateFileException
        || e instanceof DuplicateFolderNameException
        || e instanceof LiferayFileItemException
        || e instanceof FileExtensionException
        || e instanceof FileMimeTypeException
        || e instanceof FileNameException
        || e instanceof FileSizeException
        || e instanceof NoSuchFolderException
        || e instanceof SourceFileNameException
        || e instanceof StorageFieldRequiredException) {

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

      if (uploadException != null) {
        String uploadExceptionRedirect =
            ParamUtil.getString(actionRequest, "uploadExceptionRedirect");

        actionResponse.sendRedirect(uploadExceptionRedirect);

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

        return;
      }

      if (e instanceof AntivirusScannerException) {
        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }
    } else if (e instanceof InvalidFileVersionException
        || e instanceof NoSuchFileEntryException
        || e instanceof PrincipalException) {

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

      setForward(actionRequest, "portlet.document_library.error");
    } else {
      throw e;
    }
  }
  @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());
    }
  }
  public void processAction(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    try {
      String portletResource = ParamUtil.getString(actionRequest, "portletResource");

      PortletPreferences preferences =
          PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);

      if (cmd.equals("add-selection")) {
        AssetPublisherUtil.addSelection(actionRequest, preferences);
      } else if (cmd.equals("move-selection-down")) {
        moveSelectionDown(actionRequest, preferences);
      } else if (cmd.equals("move-selection-up")) {
        moveSelectionUp(actionRequest, preferences);
      } else if (cmd.equals("remove-selection")) {
        removeSelection(actionRequest, preferences);
      } else if (cmd.equals("selection-style")) {
        setSelectionStyle(actionRequest, preferences);
      } else if (cmd.equals(Constants.UPDATE)) {
        String selectionStyle = preferences.getValue("selection-style", "dynamic");

        if (selectionStyle.equals("dynamic")) {
          updateDynamicSettings(actionRequest, preferences);
        } else if (selectionStyle.equals("manual")) {
          updateManualSettings(actionRequest, preferences);
        }
      }

      if (SessionErrors.isEmpty(actionRequest)) {
        preferences.store();

        SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
      }

      actionResponse.sendRedirect(ParamUtil.getString(actionRequest, "redirect"));
    } catch (Exception e) {
      if (e instanceof AssetTagException) {
        SessionErrors.add(actionRequest, e.getClass().getName(), e);
      } else {
        throw e;
      }
    }
  }
  protected boolean redirectToLogin(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException {

    if (actionRequest.getRemoteUser() == null) {
      HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

      SessionErrors.add(request, PrincipalException.class.getName());

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

      actionResponse.sendRedirect(themeDisplay.getURLSignIn());

      return true;
    } else {
      return false;
    }
  }
  @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;
      }
    }
  }
  public void authorize(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    OAuthService oAuthService = oAuthManager.getOAuthService();

    Token requestToken = oAuthService.getRequestToken();

    oAuthManager.updateRequestToken(themeDisplay.getUser(), requestToken);

    String redirect = oAuthService.getAuthorizationUrl(requestToken);

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

    redirect = HttpUtil.addParameter(redirect, OAuthConstants.CALLBACK, callbackURL);

    actionResponse.sendRedirect(redirect);
  }
  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);
  }
  protected void postProcessAuthFailure(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    LiferayPortletRequest liferayPortletRequest =
        PortalUtil.getLiferayPortletRequest(actionRequest);

    String portletName = liferayPortletRequest.getPortletName();

    Layout layout = (Layout) actionRequest.getAttribute(WebKeys.LAYOUT);

    PortletURL portletURL =
        new PortletURLImpl(
            actionRequest, portletName, layout.getPlid(), PortletRequest.RENDER_PHASE);

    portletURL.setParameter("saveLastPath", Boolean.FALSE.toString());

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

    if (Validator.isNotNull(redirect)) {
      portletURL.setParameter("redirect", redirect);
    }

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

    if (Validator.isNotNull(login)) {
      portletURL.setParameter("login", login);
    }

    if (portletName.equals(LoginPortletKeys.LOGIN)) {
      portletURL.setWindowState(WindowState.MAXIMIZED);
    } else {
      portletURL.setWindowState(actionRequest.getWindowState());
    }

    actionResponse.sendRedirect(portletURL.toString());
  }
Example #29
0
 protected void processTab(ActionResponse actionResponse, String tab)
     throws PortletException, IOException {
   if (tab.equals(PARAMV_TAB_TOPIC)) {
     actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_TOPIC));
   } else if (tab.equals(PARAMV_TAB_PLACE)) {
     actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_PLACE));
   } else if (tab.equals(PARAMV_TAB_TIME)) {
     actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_TIME));
   } else if (tab.equals(PARAMV_TAB_AREA)) {
     if (PortalConfig.getInstance()
         .getBoolean("portal.enable.search.ext.env.area.contents", true)) {
       actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_AREA_CONTENTS));
     } else if (PortalConfig.getInstance()
         .getBoolean("portal.enable.search.ext.env.area.sources", true)) {
       actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_AREA_SOURCES));
     } else if (PortalConfig.getInstance()
         .getBoolean("portal.enable.search.ext.env.area.partner", true)) {
       actionResponse.sendRedirect(actionResponse.encodeURL(PAGE_AREA_PARTNER));
     }
   }
 }
  @Override
  public void processAction(ActionRequest request, ActionResponse response)
      throws PortletException, IOException {
    String ctx = request.getContextPath();
    boolean isClose = "true".equals(request.getParameter("close"));

    if (isClose) {
      // Clean up the session
      LOG.debug("Closing the form");
      request.getPortletSession().removeAttribute(VIEW_TYPE);
      response.sendRedirect(ctx + CLOSE_PAGE);
      return;
    }

    int projectIdToBookmark = Integer.valueOf(request.getParameter(PROJECT_ID_TO_BOOKMARK));
    int projectIdOfLists = Integer.valueOf(request.getParameter(PROJECT_ID_OF_LISTS));
    String newListName = request.getParameter(NEW_LIST_NAME);

    // If the user selected an item in the drop-down, then that means they are
    // changing lists
    int pidToCompare = Integer.valueOf(request.getParameter("pidToCompare"));
    boolean isChangePidOfLists = pidToCompare != projectIdOfLists;
    if (isChangePidOfLists) {
      LOG.debug("A new project has been selected: " + projectIdOfLists);
      response.setRenderParameter(PROJECT_ID_OF_LISTS, String.valueOf(projectIdOfLists));
      return;
    }

    try {
      LOG.debug("Saving the form...");

      boolean isSuccess;

      User user = PortalUtils.getUser(request);
      int userId = user.getId();
      Connection db = PortalUtils.useConnection(request);
      Project projectOfLists = new Project(db, projectIdOfLists);
      Project projectToBookmark = new Project(db, projectIdToBookmark);
      Collection<Integer> listIds = getListIds(request.getParameterValues(LIST));
      // verify user can modify lists for project
      boolean isAddNewList = false;
      if (ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-modify")) {

        if (!StringUtils.hasText(newListName) && (listIds.size() == 0)) {
          System.out.println("Error need to show From");
          request.getPortletSession().setAttribute(ACTION_ERROR, "Choose a list or create one");
          request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE);
          return;
        }

        if (StringUtils.hasText(newListName)) {
          if (!ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-add")) {
            request
                .getPortletSession()
                .setAttribute(ACTION_ERROR, "Not authorized to create new list");
            request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE);
            return;
          }
          int newListId = saveNewList(db, projectIdOfLists, newListName);
          if (newListId == -1) {
            request.getPortletSession().setAttribute(ACTION_ERROR, "Unable to create new list.");
            request.getPortletSession().setAttribute(VIEW_TYPE, SAVE_FAILURE);
            return;
          } else {
            listIds.add(newListId);
            isAddNewList = true;
          }
        }
        TaskList existingTasks =
            findExistingTasksForProjects(db, projectIdOfLists, projectIdToBookmark);
        // check to see if the user is deleting tasks (listItems)
        if ((isAddNewList && existingTasks.size() > listIds.size() - 1)
            || !isAddNewList && existingTasks.size() > listIds.size()) {
          if (!ProjectUtils.hasAccess(projectOfLists.getId(), user, "project-lists-delete")) {
            request
                .getPortletSession()
                .setAttribute(ACTION_ERROR, "Not authorized to delete items");
            request.getPortletSession().setAttribute(VIEW_TYPE, VIEW_FORM_PAGE);
            return;
          } else {
            deleteFromLists(db, existingTasks, listIds);
          }
        }
        isSuccess =
            saveToLists(
                db,
                existingTasks,
                listIds,
                userId,
                projectIdToBookmark,
                projectToBookmark.getTitle(),
                projectIdOfLists,
                request);
      } else {
        isSuccess = false;
        request.getPortletSession().setAttribute(ACTION_ERROR, "Not authorized to bookmark");
      }

      if (isSuccess) {
        // Close the panel, everything went well
        response.sendRedirect(ctx + "/close_panel_refresh.jsp");
      } else {
        request.getPortletSession().setAttribute(VIEW_TYPE, SAVE_FAILURE);
      }
    } catch (SQLException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }