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.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
021    import com.liferay.portal.model.Layout;
022    import com.liferay.portal.model.Portlet;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    
025    import java.util.Collection;
026    
027    import javax.portlet.PortletMode;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Raymond Aug??
032     */
033    public class PortletPermissionUtil {
034    
035            public static void check(
036                            PermissionChecker permissionChecker, Layout layout,
037                            String portletId, String actionId)
038                    throws PortalException {
039    
040                    getPortletPermission().check(
041                            permissionChecker, layout, portletId, actionId);
042            }
043    
044            public static void check(
045                            PermissionChecker permissionChecker, Layout layout,
046                            String portletId, String actionId, boolean strict)
047                    throws PortalException {
048    
049                    getPortletPermission().check(
050                            permissionChecker, layout, portletId, actionId, strict);
051            }
052    
053            public static void check(
054                            PermissionChecker permissionChecker, long groupId, Layout layout,
055                            String portletId, String actionId)
056                    throws PortalException {
057    
058                    getPortletPermission().check(
059                            permissionChecker, groupId, layout, portletId, actionId);
060            }
061    
062            public static void check(
063                            PermissionChecker permissionChecker, long groupId, Layout layout,
064                            String portletId, String actionId, boolean strict)
065                    throws PortalException {
066    
067                    getPortletPermission().check(
068                            permissionChecker, groupId, layout, portletId, actionId, strict);
069            }
070    
071            public static void check(
072                            PermissionChecker permissionChecker, long groupId, Layout layout,
073                            String portletId, String actionId, boolean strict,
074                            boolean checkStagingPermission)
075                    throws PortalException {
076    
077                    getPortletPermission().check(
078                            permissionChecker, groupId, layout, portletId, actionId, strict,
079                            checkStagingPermission);
080            }
081    
082            public static void check(
083                            PermissionChecker permissionChecker, long groupId, long plid,
084                            String portletId, String actionId)
085                    throws PortalException {
086    
087                    getPortletPermission().check(
088                            permissionChecker, groupId, plid, portletId, actionId);
089            }
090    
091            public static void check(
092                            PermissionChecker permissionChecker, long groupId, long plid,
093                            String portletId, String actionId, boolean strict)
094                    throws PortalException {
095    
096                    getPortletPermission().check(
097                            permissionChecker, groupId, plid, portletId, actionId, strict);
098            }
099    
100            public static void check(
101                            PermissionChecker permissionChecker, long plid, String portletId,
102                            String actionId)
103                    throws PortalException {
104    
105                    getPortletPermission().check(
106                            permissionChecker, plid, portletId, actionId);
107            }
108    
109            public static void check(
110                            PermissionChecker permissionChecker, long plid, String portletId,
111                            String actionId, boolean strict)
112                    throws PortalException {
113    
114                    getPortletPermission().check(
115                            permissionChecker, plid, portletId, actionId, strict);
116            }
117    
118            public static void check(
119                            PermissionChecker permissionChecker, String portletId,
120                            String actionId)
121                    throws PortalException {
122    
123                    getPortletPermission().check(permissionChecker, portletId, actionId);
124            }
125    
126            public static boolean contains(
127                            PermissionChecker permissionChecker, Layout layout, Portlet portlet,
128                            String actionId)
129                    throws PortalException {
130    
131                    return getPortletPermission().contains(
132                            permissionChecker, layout, portlet, actionId);
133            }
134    
135            public static boolean contains(
136                            PermissionChecker permissionChecker, Layout layout, Portlet portlet,
137                            String actionId, boolean strict)
138                    throws PortalException {
139    
140                    return getPortletPermission().contains(
141                            permissionChecker, layout, portlet, actionId, strict);
142            }
143    
144            public static boolean contains(
145                            PermissionChecker permissionChecker, Layout layout,
146                            String portletId, String actionId)
147                    throws PortalException {
148    
149                    return getPortletPermission().contains(
150                            permissionChecker, layout, portletId, actionId);
151            }
152    
153            public static boolean contains(
154                            PermissionChecker permissionChecker, Layout layout,
155                            String portletId, String actionId, boolean strict)
156                    throws PortalException {
157    
158                    return getPortletPermission().contains(
159                            permissionChecker, layout, portletId, actionId, strict);
160            }
161    
162            public static boolean contains(
163                            PermissionChecker permissionChecker, long groupId, Layout layout,
164                            Portlet portlet, String actionId)
165                    throws PortalException {
166    
167                    return getPortletPermission().contains(
168                            permissionChecker, groupId, layout, portlet, actionId);
169            }
170    
171            public static boolean contains(
172                            PermissionChecker permissionChecker, long groupId, Layout layout,
173                            Portlet portlet, String actionId, boolean strict)
174                    throws PortalException {
175    
176                    return getPortletPermission().contains(
177                            permissionChecker, groupId, layout, portlet, actionId, strict);
178            }
179    
180            public static boolean contains(
181                            PermissionChecker permissionChecker, long groupId, Layout layout,
182                            String portletId, String actionId)
183                    throws PortalException {
184    
185                    return getPortletPermission().contains(
186                            permissionChecker, groupId, layout, portletId, actionId);
187            }
188    
189            public static boolean contains(
190                            PermissionChecker permissionChecker, long groupId, Layout layout,
191                            String portletId, String actionId, boolean strict)
192                    throws PortalException {
193    
194                    return getPortletPermission().contains(
195                            permissionChecker, groupId, layout, portletId, actionId, strict);
196            }
197    
198            public static boolean contains(
199                            PermissionChecker permissionChecker, long groupId, Layout layout,
200                            String portletId, String actionId, boolean strict,
201                            boolean checkStagingPermission)
202                    throws PortalException {
203    
204                    return getPortletPermission().contains(
205                            permissionChecker, groupId, layout, portletId, actionId, strict,
206                            checkStagingPermission);
207            }
208    
209            /**
210             * @deprecated As of 6.2.0, replaced by {@link
211             *             #hasControlPanelAccessPermission(PermissionChecker, long,
212             *             Collection)}
213             */
214            @Deprecated
215            public static boolean contains(
216                    PermissionChecker permissionChecker, long groupId, long plid,
217                    Collection<Portlet> portlets, String actionId) {
218    
219                    try {
220                            return hasControlPanelAccessPermission(
221                                    permissionChecker, groupId, portlets);
222                    }
223                    catch (Exception e) {
224                            _log.error(e, e);
225                    }
226    
227                    return false;
228            }
229    
230            public static boolean contains(
231                            PermissionChecker permissionChecker, long groupId, long plid,
232                            String portletId, String actionId, boolean strict)
233                    throws PortalException {
234    
235                    return getPortletPermission().contains(
236                            permissionChecker, groupId, plid, portletId, actionId, strict);
237            }
238    
239            public static boolean contains(
240                            PermissionChecker permissionChecker, long plid, Portlet portlet,
241                            String actionId)
242                    throws PortalException {
243    
244                    return getPortletPermission().contains(
245                            permissionChecker, plid, portlet, actionId);
246            }
247    
248            public static boolean contains(
249                            PermissionChecker permissionChecker, long plid, Portlet portlet,
250                            String actionId, boolean strict)
251                    throws PortalException {
252    
253                    return getPortletPermission().contains(
254                            permissionChecker, plid, portlet, actionId, strict);
255            }
256    
257            public static boolean contains(
258                            PermissionChecker permissionChecker, long plid, String portletId,
259                            String actionId)
260                    throws PortalException {
261    
262                    return getPortletPermission().contains(
263                            permissionChecker, plid, portletId, actionId);
264            }
265    
266            public static boolean contains(
267                            PermissionChecker permissionChecker, long plid, String portletId,
268                            String actionId, boolean strict)
269                    throws PortalException {
270    
271                    return getPortletPermission().contains(
272                            permissionChecker, plid, portletId, actionId, strict);
273            }
274    
275            public static boolean contains(
276                            PermissionChecker permissionChecker, String portletId,
277                            String actionId)
278                    throws PortalException {
279    
280                    return getPortletPermission().contains(
281                            permissionChecker, portletId, actionId);
282            }
283    
284            public static PortletPermission getPortletPermission() {
285                    PortalRuntimePermission.checkGetBeanProperty(
286                            PortletPermissionUtil.class);
287    
288                    return _portletPermission;
289            }
290    
291            public static String getPrimaryKey(long plid, String portletId) {
292                    return getPortletPermission().getPrimaryKey(plid, portletId);
293            }
294    
295            public static boolean hasAccessPermission(
296                            PermissionChecker permissionChecker, long scopeGroupId,
297                            Layout layout, Portlet portlet, PortletMode portletMode)
298                    throws PortalException {
299    
300                    return getPortletPermission().hasAccessPermission(
301                            permissionChecker, scopeGroupId, layout, portlet, portletMode);
302            }
303    
304            public static boolean hasConfigurationPermission(
305                            PermissionChecker permissionChecker, long groupId, Layout layout,
306                            String actionId)
307                    throws PortalException {
308    
309                    return getPortletPermission().hasConfigurationPermission(
310                            permissionChecker, groupId, layout, actionId);
311            }
312    
313            public static boolean hasControlPanelAccessPermission(
314                            PermissionChecker permissionChecker, long scopeGroupId,
315                            Collection<Portlet> portlets)
316                    throws PortalException {
317    
318                    return getPortletPermission().hasControlPanelAccessPermission(
319                            permissionChecker, scopeGroupId, portlets);
320            }
321    
322            public static boolean hasControlPanelAccessPermission(
323                            PermissionChecker permissionChecker, long scopeGroupId,
324                            Portlet portlet)
325                    throws PortalException {
326    
327                    return getPortletPermission().hasControlPanelAccessPermission(
328                            permissionChecker, scopeGroupId, portlet);
329            }
330    
331            public static boolean hasControlPanelAccessPermission(
332                            PermissionChecker permissionChecker, long scopeGroupId,
333                            String portletId)
334                    throws PortalException {
335    
336                    return getPortletPermission().hasControlPanelAccessPermission(
337                            permissionChecker, scopeGroupId, portletId);
338            }
339    
340            public static boolean hasLayoutManagerPermission(
341                    String portletId, String actionId) {
342    
343                    return getPortletPermission().hasLayoutManagerPermission(
344                            portletId, actionId);
345            }
346    
347            public void setPortletPermission(PortletPermission portletPermission) {
348                    PortalRuntimePermission.checkSetBeanProperty(getClass());
349    
350                    _portletPermission = portletPermission;
351            }
352    
353            private static final Log _log = LogFactoryUtil.getLog(
354                    PortletPermissionUtil.class);
355    
356            private static PortletPermission _portletPermission;
357    
358    }