|
20 | 20 | import com.liferay.portal.kernel.model.LayoutRevision;
|
21 | 21 | import com.liferay.portal.kernel.model.LayoutTypePortlet;
|
22 | 22 | import com.liferay.portal.kernel.model.Portlet;
|
| 23 | +import com.liferay.portal.kernel.model.PortletCategory; |
23 | 24 | import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil;
|
24 | 25 | import com.liferay.portal.kernel.portlet.render.PortletRenderParts;
|
25 | 26 | 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; |
26 | 29 | import com.liferay.portal.kernel.service.LayoutRevisionLocalService;
|
27 | 30 | import com.liferay.portal.kernel.service.LayoutService;
|
28 | 31 | import com.liferay.portal.kernel.service.PortletLocalService;
|
29 | 32 | import com.liferay.portal.kernel.service.ServiceContext;
|
30 | 33 | import com.liferay.portal.kernel.service.ServiceContextFactory;
|
| 34 | +import com.liferay.portal.kernel.service.permission.PortletPermissionUtil; |
31 | 35 | import com.liferay.portal.kernel.servlet.BufferCacheServletResponse;
|
32 | 36 | import com.liferay.portal.kernel.servlet.DynamicServletRequest;
|
33 | 37 | import com.liferay.portal.kernel.servlet.ServletResponseUtil;
|
|
49 | 53 | import com.liferay.portal.struts.Action;
|
50 | 54 | import com.liferay.portal.util.LayoutClone;
|
51 | 55 | import com.liferay.portal.util.LayoutCloneFactory;
|
| 56 | +import com.liferay.portal.util.WebAppPool; |
| 57 | + |
| 58 | +import java.util.Set; |
52 | 59 |
|
53 | 60 | import javax.portlet.PortletPreferences;
|
54 | 61 |
|
@@ -96,6 +103,8 @@ public String execute(
|
96 | 103 | throw new IllegalArgumentException("Portlet ID is null");
|
97 | 104 | }
|
98 | 105 |
|
| 106 | + _checkPortletPermission(portletId, themeDisplay); |
| 107 | + |
99 | 108 | String columnId = ParamUtil.getString(
|
100 | 109 | httpServletRequest, "p_p_col_id", null);
|
101 | 110 | int columnPos = ParamUtil.getInteger(
|
@@ -387,6 +396,39 @@ protected void storeAddContentPortletPreferences(
|
387 | 396 | portletPreferences.store();
|
388 | 397 | }
|
389 | 398 |
|
| 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 | + |
390 | 432 | @Reference
|
391 | 433 | private LayoutRevisionLocalService _layoutRevisionLocalService;
|
392 | 434 |
|
|
0 commit comments