Skip to content

Commit 2e29e67

Browse files
lfbesadabrianchandotcom
authored andcommitted
LPD-49304 Check the portlet add to page permission and the portlet category visibility
1 parent a9d83a1 commit 2e29e67

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

modules/apps/layout/layout-impl/src/main/java/com/liferay/layout/internal/struts/UpdateLayoutStrutsAction.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@
2020
import com.liferay.portal.kernel.model.LayoutRevision;
2121
import com.liferay.portal.kernel.model.LayoutTypePortlet;
2222
import com.liferay.portal.kernel.model.Portlet;
23+
import com.liferay.portal.kernel.model.PortletCategory;
2324
import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil;
2425
import com.liferay.portal.kernel.portlet.render.PortletRenderParts;
2526
import com.liferay.portal.kernel.portlet.render.PortletRenderUtil;
27+
import com.liferay.portal.kernel.security.auth.PrincipalException;
28+
import com.liferay.portal.kernel.security.permission.ActionKeys;
2629
import com.liferay.portal.kernel.service.LayoutRevisionLocalService;
2730
import com.liferay.portal.kernel.service.LayoutService;
2831
import com.liferay.portal.kernel.service.PortletLocalService;
2932
import com.liferay.portal.kernel.service.ServiceContext;
3033
import com.liferay.portal.kernel.service.ServiceContextFactory;
34+
import com.liferay.portal.kernel.service.permission.PortletPermissionUtil;
3135
import com.liferay.portal.kernel.servlet.BufferCacheServletResponse;
3236
import com.liferay.portal.kernel.servlet.DynamicServletRequest;
3337
import com.liferay.portal.kernel.servlet.ServletResponseUtil;
@@ -49,6 +53,9 @@
4953
import com.liferay.portal.struts.Action;
5054
import com.liferay.portal.util.LayoutClone;
5155
import com.liferay.portal.util.LayoutCloneFactory;
56+
import com.liferay.portal.util.WebAppPool;
57+
58+
import java.util.Set;
5259

5360
import javax.portlet.PortletPreferences;
5461

@@ -96,6 +103,8 @@ public String execute(
96103
throw new IllegalArgumentException("Portlet ID is null");
97104
}
98105

106+
_checkPortletPermission(portletId, themeDisplay);
107+
99108
String columnId = ParamUtil.getString(
100109
httpServletRequest, "p_p_col_id", null);
101110
int columnPos = ParamUtil.getInteger(
@@ -387,6 +396,39 @@ protected void storeAddContentPortletPreferences(
387396
portletPreferences.store();
388397
}
389398

399+
private void _checkPortletPermission(
400+
String portletId, ThemeDisplay themeDisplay)
401+
throws Exception {
402+
403+
PortletPermissionUtil.check(
404+
themeDisplay.getPermissionChecker(), portletId,
405+
ActionKeys.ADD_TO_PAGE);
406+
407+
PortletCategory portletCategory = (PortletCategory)WebAppPool.get(
408+
themeDisplay.getCompanyId(), WebKeys.PORTLET_CATEGORY);
409+
410+
Portlet portlet = _portletLocalService.getPortletById(
411+
themeDisplay.getCompanyId(), portletId);
412+
413+
Set<String> categoryNames = portlet.getCategoryNames();
414+
415+
for (PortletCategory curPortletCategory :
416+
portletCategory.getCategories()) {
417+
418+
if (!curPortletCategory.isHidden() &&
419+
categoryNames.contains(curPortletCategory.getName())) {
420+
421+
return;
422+
}
423+
}
424+
425+
throw new PrincipalException.MustHavePermission(
426+
themeDisplay.getPermissionChecker(),
427+
StringBundler.concat(
428+
Portlet.class.getName(), StringPool.UNDERLINE, portletId),
429+
0, ActionKeys.ADD_TO_PAGE);
430+
}
431+
390432
@Reference
391433
private LayoutRevisionLocalService _layoutRevisionLocalService;
392434

0 commit comments

Comments
 (0)