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

"You do not have the roles required to access this portlet" when using $theme.runtime to include a portlet inside a theme

    Details

    • Liferay Contributor's Agreement:
      Accept

      Description

      If you include a portlet in the theme using $theme.runtime, the first time you view a page using this theme, the portlet is correctly included in the page.
      But if you refresh that page, you get an "You do not have the roles required to access this portlet" message instead.

      Code used to include an web content article (change the article id) :

      $velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
      $velocityPortletPreferences.setValue("group-id", "$group_id")
      $velocityPortletPreferences.setValue("article-id", "12345")
      $theme.runtime("56_INSTANCE_th00", "", $velocityPortletPreferences.toString())
      $velocityPortletPreferences.reset()

      Code from the render_portlet.jsp :

      boolean denyAccess = false;

      try {
      if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
      if (ResourcePermissionLocalServiceUtil.getResourcePermissionsCount(company.getCompanyId(), rootPortletId, ResourceConstants.SCOPE_INDIVIDUAL, portletPrimaryKey) == 0)

      { throw new NoSuchResourceException(); }

      }
      else if (!portlet.isUndeployedPortlet())

      { ResourceLocalServiceUtil.getResource(company.getCompanyId(), rootPortletId, ResourceConstants.SCOPE_INDIVIDUAL, portletPrimaryKey); }

      if (portlet.isAddDefaultResource() && !allowAddDefaultResource && !layoutTypePortlet.hasPortletId(portletId))

      { denyAccess = true; }
      }
      catch (NoSuchResourceException nsre) {

      boolean addDefaultResource = false;

      if (runtimePortlet) { addDefaultResource = true; }

      [...]

      if (addDefaultResource) { ResourceLocalServiceUtil.addResources(company.getCompanyId(), layout.getGroupId(), 0, rootPortletId, portletPrimaryKey, true, true, true); }
      else { denyAccess = true; }

      }

      The first time you see the page, there is no resource for the portlet, so an NoSuchResourceException is thrown, the resource is created and after that denyAccess is still false.
      The portlet is displayed.

      The problem is that the next time, the resource exists, so the portal checks if the portlet exists on the page with !layoutTypePortlet.hasPortletId(portletId).
      Because the runtime portlet doesn't exists on the page, denyAccess is set to true and you get an error.

      The patch I attached correct this by not checking if the portlet exists on the page, in case of a runtime portlet :

      if (portlet.isAddDefaultResource() && !allowAddDefaultResource && !runtimePortlet && !layoutTypePortlet.hasPortletId(portletId)) {
      denyAccess = true;
      }

        Attachments

          Activity

            People

            Assignee:
            support-lep@liferay.com SE Support
            Reporter:
            smeunier Sébastien Meunier (Inactive)
            Participants of an Issue:
            Recent user:
            Esther Sanz
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              8 years, 27 weeks, 4 days ago

                Packages

                Version Package
                6.0.4 GA