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.security.permission;
016    
017    import com.liferay.portal.NoSuchResourceActionException;
018    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    import com.liferay.portal.model.Group;
020    import com.liferay.portal.model.Portlet;
021    import com.liferay.portal.model.Role;
022    
023    import java.io.InputStream;
024    
025    import java.util.List;
026    import java.util.Locale;
027    
028    import javax.servlet.http.HttpServletRequest;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Daeyoung Song
033     */
034    public class ResourceActionsUtil {
035    
036            /**
037             * @deprecated As of 6.1.0, replaced by {@link #getActionNamePrefix}
038             */
039            @Deprecated
040            public static final String ACTION_NAME_PREFIX =
041                    ResourceActions.ACTION_NAME_PREFIX;
042    
043            /**
044             * @deprecated As of 6.1.0, replaced by {@link #getModelResourceNamePrefix}
045             */
046            @Deprecated
047            public static final String MODEL_RESOURCE_NAME_PREFIX =
048                    ResourceActions.MODEL_RESOURCE_NAME_PREFIX;
049    
050            /**
051             * @deprecated As of 6.1.0, replaced by {@link
052             *             #getOrganizationModelResources}
053             */
054            @Deprecated
055            public static final String[] ORGANIZATION_MODEL_RESOURCES =
056                    ResourceActions.ORGANIZATION_MODEL_RESOURCES;
057    
058            /**
059             * @deprecated As of 6.1.0, replaced by {@link #getPortalModelResources}
060             */
061            @Deprecated
062            public static final String[] PORTAL_MODEL_RESOURCES =
063                    ResourceActions.PORTAL_MODEL_RESOURCES;
064    
065            public static void checkAction(String name, String actionId)
066                    throws NoSuchResourceActionException {
067    
068                    getResourceActions().checkAction(name, actionId);
069            }
070    
071            public static String getAction(HttpServletRequest request, String action) {
072                    return getResourceActions().getAction(request, action);
073            }
074    
075            public static String getAction(Locale locale, String action) {
076                    return getResourceActions().getAction(locale, action);
077            }
078    
079            public static String getActionNamePrefix() {
080                    return getResourceActions().getActionNamePrefix();
081            }
082    
083            public static List<String> getActionsNames(
084                    HttpServletRequest request, List<String> actions) {
085    
086                    return getResourceActions().getActionsNames(request, actions);
087            }
088    
089            public static List<String> getActionsNames(
090                    HttpServletRequest request, String name, long actionIds) {
091    
092                    return getResourceActions().getActionsNames(request, name, actionIds);
093            }
094    
095            public static List<String> getModelNames() {
096                    return getResourceActions().getModelNames();
097            }
098    
099            public static List<String> getModelPortletResources(String name) {
100                    return getResourceActions().getModelPortletResources(name);
101            }
102    
103            public static String getModelResource(
104                    HttpServletRequest request, String name) {
105    
106                    return getResourceActions().getModelResource(request, name);
107            }
108    
109            public static String getModelResource(Locale locale, String name) {
110                    return getResourceActions().getModelResource(locale, name);
111            }
112    
113            public static List<String> getModelResourceActions(String name) {
114                    return getResourceActions().getModelResourceActions(name);
115            }
116    
117            public static List<String> getModelResourceGroupDefaultActions(
118                    String name) {
119    
120                    return getResourceActions().getModelResourceGroupDefaultActions(name);
121            }
122    
123            public static List<String> getModelResourceGuestDefaultActions(
124                    String name) {
125    
126                    return getResourceActions().getModelResourceGuestDefaultActions(name);
127            }
128    
129            public static List<String> getModelResourceGuestUnsupportedActions(
130                    String name) {
131    
132                    return getResourceActions().getModelResourceGuestUnsupportedActions(
133                            name);
134            }
135    
136            public static String getModelResourceNamePrefix() {
137                    return getResourceActions().getModelResourceNamePrefix();
138            }
139    
140            public static List<String> getModelResourceOwnerDefaultActions(
141                    String name) {
142    
143                    return getResourceActions().getModelResourceOwnerDefaultActions(name);
144            }
145    
146            public static Double getModelResourceWeight(String name) {
147                    return getResourceActions().getModelResourceWeight(name);
148            }
149    
150            public static String[] getOrganizationModelResources() {
151                    return getResourceActions().getOrganizationModelResources();
152            }
153    
154            public static String[] getPortalModelResources() {
155                    return getResourceActions().getPortalModelResources();
156            }
157    
158            public static String getPortletBaseResource(String portletName) {
159                    return getResourceActions().getPortletBaseResource(portletName);
160            }
161    
162            public static List<String> getPortletModelResources(String portletName) {
163                    return getResourceActions().getPortletModelResources(portletName);
164            }
165    
166            public static List<String> getPortletNames() {
167                    return getResourceActions().getPortletNames();
168            }
169    
170            public static List<String> getPortletResourceActions(Portlet portlet) {
171                    return getResourceActions().getPortletResourceActions(portlet);
172            }
173    
174            public static List<String> getPortletResourceActions(String name) {
175                    return getResourceActions().getPortletResourceActions(name);
176            }
177    
178            public static List<String> getPortletResourceGroupDefaultActions(
179                    String name) {
180    
181                    return getResourceActions().getPortletResourceGroupDefaultActions(name);
182            }
183    
184            public static List<String> getPortletResourceGuestDefaultActions(
185                    String name) {
186    
187                    return getResourceActions().getPortletResourceGuestDefaultActions(name);
188            }
189    
190            public static List<String> getPortletResourceGuestUnsupportedActions(
191                    String name) {
192    
193                    return getResourceActions().getPortletResourceGuestUnsupportedActions(
194                            name);
195            }
196    
197            public static List<String> getPortletResourceLayoutManagerActions(
198                    String name) {
199    
200                    return getResourceActions().getPortletResourceLayoutManagerActions(
201                            name);
202            }
203    
204            public static String getPortletRootModelResource(String portletName) {
205                    return getResourceActions().getPortletRootModelResource(portletName);
206            }
207    
208            public static ResourceActions getResourceActions() {
209                    PortalRuntimePermission.checkGetBeanProperty(ResourceActionsUtil.class);
210    
211                    return _resourceActions;
212            }
213    
214            public static List<String> getResourceActions(String name) {
215                    return getResourceActions().getResourceActions(name);
216            }
217    
218            public static List<String> getResourceActions(
219                    String portletResource, String modelResource) {
220    
221                    return getResourceActions().getResourceActions(
222                            portletResource, modelResource);
223            }
224    
225            public static List<String> getResourceGroupDefaultActions(String name) {
226                    return getResourceActions().getResourceGroupDefaultActions(name);
227            }
228    
229            public static List<String> getResourceGuestUnsupportedActions(
230                    String portletResource, String modelResource) {
231    
232                    return getResourceActions().getResourceGuestUnsupportedActions(
233                            portletResource, modelResource);
234            }
235    
236            /**
237             * @deprecated As of 6.1.0, replaced by {@link #getRoles(long, Group,
238             *             String, int[])}
239             */
240            @Deprecated
241            public static List<Role> getRoles(
242                    long companyId, Group group, String modelResource) {
243    
244                    return getResourceActions().getRoles(companyId, group, modelResource);
245            }
246    
247            public static List<Role> getRoles(
248                    long companyId, Group group, String modelResource, int[] roleTypes) {
249    
250                    return getResourceActions().getRoles(
251                            companyId, group, modelResource, roleTypes);
252            }
253    
254            public static boolean hasModelResourceActions(String name) {
255                    return getResourceActions().hasModelResourceActions(name);
256            }
257    
258            /**
259             * @deprecated As of 6.1.0
260             */
261            @Deprecated
262            public static void init() {
263            }
264    
265            public static boolean isOrganizationModelResource(String modelResource) {
266                    return getResourceActions().isOrganizationModelResource(modelResource);
267            }
268    
269            public static boolean isPortalModelResource(String modelResource) {
270                    return getResourceActions().isPortalModelResource(modelResource);
271            }
272    
273            public static void read(
274                            String servletContextName, ClassLoader classLoader, String source)
275                    throws Exception {
276    
277                    getResourceActions().read(servletContextName, classLoader, source);
278            }
279    
280            public static void read(String servletContextName, InputStream inputStream)
281                    throws Exception {
282    
283                    getResourceActions().read(servletContextName, inputStream);
284            }
285    
286            public void setResourceActions(ResourceActions resourceActions) {
287                    PortalRuntimePermission.checkSetBeanProperty(getClass());
288    
289                    _resourceActions = resourceActions;
290            }
291    
292            private static ResourceActions _resourceActions;
293    
294    }