Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-52754

Hooks bug: When a Struts action has been overridden, the overridden action can be invoked by incorrect Struts action paths

    Details

    • Fix Priority:
      3

      Description

      Hooks bug: When a Struts action has been overridden, the overridden action can be invoked by incorrect Struts action paths.

      Reported by JL Gonzalez on this documentation page: https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/lp-6-1-dgen06-overriding-and-adding-struts-actions-0

      If you override a Struts path that 'contains' in its string the path of another one, your overridden action will be called not only when your action is called but also when any other Struts path that 'contains' it is called. Consider the following example:

      Suppose we create a hook to override the following Struts path: /document_library/edit_file_entry

      To do so, we create a hook and add this to the lifery-hook.xml:
      <struts-action>
      <struts-action-path>/document_library/edit_file_entry</struts-action-path>
      <struts-action-impl>com.myproject.portlet.documentlibrary.action.ModifiedEditFil­eEntryAction</struts-action-impl>
      </struts-action>

      When we execute this, it works perfectly. But try to edit a File Entry Type or try to add a comment to a file.

      Those actions have the following Struts paths:
      /document_library/edit_file_entry_discussion
      /document_library/edit_file_entry_ty­pe

      Notice that both 'contain' the string of our modified Struts path:
      '/document_library/edit_file_entry'

      All of these action paths invoke ModifiedEditFileEntryAction. This is not the intended behavior. Only '/document_library/edit_file_entry' should do invoke ModifiedEditFileEntryAction.

      Workaround:

      If you call originalStrutsPortletAction.processAction inside the Action it will work properly, redirecting to the right '/document_library/edit_file_entry_discussion' or 'document_library/edit_file_entry_type' or 'document_library/edit_file_entry'.

      The only way to avoid this is checking if your Struts path is not 'contained' in any other Struts path of the struts-config.xml and if it is, create a <struts-action> for each one in your liferay-hook, redirecting to a dummy XXXXXAction that will only override the processAction, render and serveResource with a call to the original ones with originalStrutsPortletAction.processAction,originalStrutsPortletAction.render or originalStrutsPortletAction.serveResource

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  2 years, 30 weeks, 4 days ago

                  Packages

                  Version Package