001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.model.Layout;
019    import com.liferay.portal.kernel.model.Portlet;
020    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
021    import com.liferay.portal.kernel.security.permission.PermissionChecker;
022    
023    import java.util.Collection;
024    
025    import javax.portlet.PortletMode;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Raymond Aug??
030     */
031    public class PortletPermissionUtil {
032    
033            public static void check(
034                            PermissionChecker permissionChecker, Layout layout,
035                            String portletId, String actionId)
036                    throws PortalException {
037    
038                    getPortletPermission().check(
039                            permissionChecker, layout, portletId, actionId);
040            }
041    
042            public static void check(
043                            PermissionChecker permissionChecker, Layout layout,
044                            String portletId, String actionId, boolean strict)
045                    throws PortalException {
046    
047                    getPortletPermission().check(
048                            permissionChecker, layout, portletId, actionId, strict);
049            }
050    
051            public static void check(
052                            PermissionChecker permissionChecker, long groupId, Layout layout,
053                            String portletId, String actionId)
054                    throws PortalException {
055    
056                    getPortletPermission().check(
057                            permissionChecker, groupId, layout, portletId, actionId);
058            }
059    
060            public static void check(
061                            PermissionChecker permissionChecker, long groupId, Layout layout,
062                            String portletId, String actionId, boolean strict)
063                    throws PortalException {
064    
065                    getPortletPermission().check(
066                            permissionChecker, groupId, layout, portletId, actionId, strict);
067            }
068    
069            public static void check(
070                            PermissionChecker permissionChecker, long groupId, Layout layout,
071                            String portletId, String actionId, boolean strict,
072                            boolean checkStagingPermission)
073                    throws PortalException {
074    
075                    getPortletPermission().check(
076                            permissionChecker, groupId, layout, portletId, actionId, strict,
077                            checkStagingPermission);
078            }
079    
080            public static void check(
081                            PermissionChecker permissionChecker, long groupId, long plid,
082                            String portletId, String actionId)
083                    throws PortalException {
084    
085                    getPortletPermission().check(
086                            permissionChecker, groupId, plid, portletId, actionId);
087            }
088    
089            public static void check(
090                            PermissionChecker permissionChecker, long groupId, long plid,
091                            String portletId, String actionId, boolean strict)
092                    throws PortalException {
093    
094                    getPortletPermission().check(
095                            permissionChecker, groupId, plid, portletId, actionId, strict);
096            }
097    
098            public static void check(
099                            PermissionChecker permissionChecker, long plid, String portletId,
100                            String actionId)
101                    throws PortalException {
102    
103                    getPortletPermission().check(
104                            permissionChecker, plid, portletId, actionId);
105            }
106    
107            public static void check(
108                            PermissionChecker permissionChecker, long plid, String portletId,
109                            String actionId, boolean strict)
110                    throws PortalException {
111    
112                    getPortletPermission().check(
113                            permissionChecker, plid, portletId, actionId, strict);
114            }
115    
116            public static void check(
117                            PermissionChecker permissionChecker, String portletId,
118                            String actionId)
119                    throws PortalException {
120    
121                    getPortletPermission().check(permissionChecker, portletId, actionId);
122            }
123    
124            public static boolean contains(
125                            PermissionChecker permissionChecker, Layout layout, Portlet portlet,
126                            String actionId)
127                    throws PortalException {
128    
129                    return getPortletPermission().contains(
130                            permissionChecker, layout, portlet, actionId);
131            }
132    
133            public static boolean contains(
134                            PermissionChecker permissionChecker, Layout layout, Portlet portlet,
135                            String actionId, boolean strict)
136                    throws PortalException {
137    
138                    return getPortletPermission().contains(
139                            permissionChecker, layout, portlet, actionId, strict);
140            }
141    
142            public static boolean contains(
143                            PermissionChecker permissionChecker, Layout layout,
144                            String portletId, String actionId)
145                    throws PortalException {
146    
147                    return getPortletPermission().contains(
148                            permissionChecker, layout, portletId, actionId);
149            }
150    
151            public static boolean contains(
152                            PermissionChecker permissionChecker, Layout layout,
153                            String portletId, String actionId, boolean strict)
154                    throws PortalException {
155    
156                    return getPortletPermission().contains(
157                            permissionChecker, layout, portletId, actionId, strict);
158            }
159    
160            public static boolean contains(
161                            PermissionChecker permissionChecker, long groupId, Layout layout,
162                            Portlet portlet, String actionId)
163                    throws PortalException {
164    
165                    return getPortletPermission().contains(
166                            permissionChecker, groupId, layout, portlet, actionId);
167            }
168    
169            public static boolean contains(
170                            PermissionChecker permissionChecker, long groupId, Layout layout,
171                            Portlet portlet, String actionId, boolean strict)
172                    throws PortalException {
173    
174                    return getPortletPermission().contains(
175                            permissionChecker, groupId, layout, portlet, actionId, strict);
176            }
177    
178            public static boolean contains(
179                            PermissionChecker permissionChecker, long groupId, Layout layout,
180                            String portletId, String actionId)
181                    throws PortalException {
182    
183                    return getPortletPermission().contains(
184                            permissionChecker, groupId, layout, portletId, actionId);
185            }
186    
187            public static boolean contains(
188                            PermissionChecker permissionChecker, long groupId, Layout layout,
189                            String portletId, String actionId, boolean strict)
190                    throws PortalException {
191    
192                    return getPortletPermission().contains(
193                            permissionChecker, groupId, layout, portletId, actionId, strict);
194            }
195    
196            public static boolean contains(
197                            PermissionChecker permissionChecker, long groupId, Layout layout,
198                            String portletId, String actionId, boolean strict,
199                            boolean checkStagingPermission)
200                    throws PortalException {
201    
202                    return getPortletPermission().contains(
203                            permissionChecker, groupId, layout, portletId, actionId, strict,
204                            checkStagingPermission);
205            }
206    
207            public static boolean contains(
208                            PermissionChecker permissionChecker, long groupId, long plid,
209                            String portletId, String actionId, boolean strict)
210                    throws PortalException {
211    
212                    return getPortletPermission().contains(
213                            permissionChecker, groupId, plid, portletId, actionId, strict);
214            }
215    
216            public static boolean contains(
217                            PermissionChecker permissionChecker, long plid, Portlet portlet,
218                            String actionId)
219                    throws PortalException {
220    
221                    return getPortletPermission().contains(
222                            permissionChecker, plid, portlet, actionId);
223            }
224    
225            public static boolean contains(
226                            PermissionChecker permissionChecker, long plid, Portlet portlet,
227                            String actionId, boolean strict)
228                    throws PortalException {
229    
230                    return getPortletPermission().contains(
231                            permissionChecker, plid, portlet, actionId, strict);
232            }
233    
234            public static boolean contains(
235                            PermissionChecker permissionChecker, long plid, String portletId,
236                            String actionId)
237                    throws PortalException {
238    
239                    return getPortletPermission().contains(
240                            permissionChecker, plid, portletId, actionId);
241            }
242    
243            public static boolean contains(
244                            PermissionChecker permissionChecker, long plid, String portletId,
245                            String actionId, boolean strict)
246                    throws PortalException {
247    
248                    return getPortletPermission().contains(
249                            permissionChecker, plid, portletId, actionId, strict);
250            }
251    
252            public static boolean contains(
253                            PermissionChecker permissionChecker, String portletId,
254                            String actionId)
255                    throws PortalException {
256    
257                    return getPortletPermission().contains(
258                            permissionChecker, portletId, actionId);
259            }
260    
261            public static PortletPermission getPortletPermission() {
262                    PortalRuntimePermission.checkGetBeanProperty(
263                            PortletPermissionUtil.class);
264    
265                    return _portletPermission;
266            }
267    
268            public static String getPrimaryKey(long plid, String portletId) {
269                    return getPortletPermission().getPrimaryKey(plid, portletId);
270            }
271    
272            public static boolean hasAccessPermission(
273                            PermissionChecker permissionChecker, long scopeGroupId,
274                            Layout layout, Portlet portlet, PortletMode portletMode)
275                    throws PortalException {
276    
277                    return getPortletPermission().hasAccessPermission(
278                            permissionChecker, scopeGroupId, layout, portlet, portletMode);
279            }
280    
281            public static boolean hasConfigurationPermission(
282                            PermissionChecker permissionChecker, long groupId, Layout layout,
283                            String actionId)
284                    throws PortalException {
285    
286                    return getPortletPermission().hasConfigurationPermission(
287                            permissionChecker, groupId, layout, actionId);
288            }
289    
290            public static boolean hasControlPanelAccessPermission(
291                            PermissionChecker permissionChecker, long scopeGroupId,
292                            Collection<Portlet> portlets)
293                    throws PortalException {
294    
295                    return getPortletPermission().hasControlPanelAccessPermission(
296                            permissionChecker, scopeGroupId, portlets);
297            }
298    
299            public static boolean hasControlPanelAccessPermission(
300                            PermissionChecker permissionChecker, long scopeGroupId,
301                            Portlet portlet)
302                    throws PortalException {
303    
304                    return getPortletPermission().hasControlPanelAccessPermission(
305                            permissionChecker, scopeGroupId, portlet);
306            }
307    
308            public static boolean hasControlPanelAccessPermission(
309                            PermissionChecker permissionChecker, long scopeGroupId,
310                            String portletId)
311                    throws PortalException {
312    
313                    return getPortletPermission().hasControlPanelAccessPermission(
314                            permissionChecker, scopeGroupId, portletId);
315            }
316    
317            public static boolean hasLayoutManagerPermission(
318                    String portletId, String actionId) {
319    
320                    return getPortletPermission().hasLayoutManagerPermission(
321                            portletId, actionId);
322            }
323    
324            public void setPortletPermission(PortletPermission portletPermission) {
325                    PortalRuntimePermission.checkSetBeanProperty(getClass());
326    
327                    _portletPermission = portletPermission;
328            }
329    
330            private static PortletPermission _portletPermission;
331    
332    }