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.exception.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            /**
084             * @deprecated As of 7.0.0
085             */
086            @Deprecated
087            public static List<String> getActionsNames(
088                    HttpServletRequest request, List<String> actions) {
089    
090                    return getResourceActions().getActionsNames(request, actions);
091            }
092    
093            /**
094             * @deprecated As of 7.0.0
095             */
096            @Deprecated
097            public static List<String> getActionsNames(
098                    HttpServletRequest request, String name, long actionIds) {
099    
100                    return getResourceActions().getActionsNames(request, name, actionIds);
101            }
102    
103            public static String getCompositeModelNameSeparator() {
104                    return getResourceActions().getCompositeModelNameSeparator();
105            }
106    
107            public static List<String> getModelNames() {
108                    return getResourceActions().getModelNames();
109            }
110    
111            public static List<String> getModelPortletResources(String name) {
112                    return getResourceActions().getModelPortletResources(name);
113            }
114    
115            public static String getModelResource(
116                    HttpServletRequest request, String name) {
117    
118                    return getResourceActions().getModelResource(request, name);
119            }
120    
121            public static String getModelResource(Locale locale, String name) {
122                    return getResourceActions().getModelResource(locale, name);
123            }
124    
125            public static List<String> getModelResourceActions(String name) {
126                    return getResourceActions().getModelResourceActions(name);
127            }
128    
129            public static List<String> getModelResourceGroupDefaultActions(
130                    String name) {
131    
132                    return getResourceActions().getModelResourceGroupDefaultActions(name);
133            }
134    
135            public static List<String> getModelResourceGuestDefaultActions(
136                    String name) {
137    
138                    return getResourceActions().getModelResourceGuestDefaultActions(name);
139            }
140    
141            public static List<String> getModelResourceGuestUnsupportedActions(
142                    String name) {
143    
144                    return getResourceActions().getModelResourceGuestUnsupportedActions(
145                            name);
146            }
147    
148            public static String getModelResourceNamePrefix() {
149                    return getResourceActions().getModelResourceNamePrefix();
150            }
151    
152            public static List<String> getModelResourceOwnerDefaultActions(
153                    String name) {
154    
155                    return getResourceActions().getModelResourceOwnerDefaultActions(name);
156            }
157    
158            public static Double getModelResourceWeight(String name) {
159                    return getResourceActions().getModelResourceWeight(name);
160            }
161    
162            public static String[] getOrganizationModelResources() {
163                    return getResourceActions().getOrganizationModelResources();
164            }
165    
166            public static String[] getPortalModelResources() {
167                    return getResourceActions().getPortalModelResources();
168            }
169    
170            public static String getPortletBaseResource(String portletName) {
171                    return getResourceActions().getPortletBaseResource(portletName);
172            }
173    
174            public static List<String> getPortletModelResources(String portletName) {
175                    return getResourceActions().getPortletModelResources(portletName);
176            }
177    
178            public static List<String> getPortletNames() {
179                    return getResourceActions().getPortletNames();
180            }
181    
182            public static List<String> getPortletResourceActions(Portlet portlet) {
183                    return getResourceActions().getPortletResourceActions(portlet);
184            }
185    
186            public static List<String> getPortletResourceActions(String name) {
187                    return getResourceActions().getPortletResourceActions(name);
188            }
189    
190            public static List<String> getPortletResourceGroupDefaultActions(
191                    String name) {
192    
193                    return getResourceActions().getPortletResourceGroupDefaultActions(name);
194            }
195    
196            public static List<String> getPortletResourceGuestDefaultActions(
197                    String name) {
198    
199                    return getResourceActions().getPortletResourceGuestDefaultActions(name);
200            }
201    
202            public static List<String> getPortletResourceGuestUnsupportedActions(
203                    String name) {
204    
205                    return getResourceActions().getPortletResourceGuestUnsupportedActions(
206                            name);
207            }
208    
209            public static List<String> getPortletResourceLayoutManagerActions(
210                    String name) {
211    
212                    return getResourceActions().getPortletResourceLayoutManagerActions(
213                            name);
214            }
215    
216            public static String getPortletRootModelResource(String portletName) {
217                    return getResourceActions().getPortletRootModelResource(portletName);
218            }
219    
220            public static ResourceActions getResourceActions() {
221                    PortalRuntimePermission.checkGetBeanProperty(ResourceActionsUtil.class);
222    
223                    return _resourceActions;
224            }
225    
226            public static List<String> getResourceActions(String name) {
227                    return getResourceActions().getResourceActions(name);
228            }
229    
230            public static List<String> getResourceActions(
231                    String portletResource, String modelResource) {
232    
233                    return getResourceActions().getResourceActions(
234                            portletResource, modelResource);
235            }
236    
237            public static List<String> getResourceGroupDefaultActions(String name) {
238                    return getResourceActions().getResourceGroupDefaultActions(name);
239            }
240    
241            public static List<String> getResourceGuestUnsupportedActions(
242                    String portletResource, String modelResource) {
243    
244                    return getResourceActions().getResourceGuestUnsupportedActions(
245                            portletResource, modelResource);
246            }
247    
248            /**
249             * @deprecated As of 6.1.0, replaced by {@link #getRoles(long, Group,
250             *             String, int[])}
251             */
252            @Deprecated
253            public static List<Role> getRoles(
254                    long companyId, Group group, String modelResource) {
255    
256                    return getResourceActions().getRoles(companyId, group, modelResource);
257            }
258    
259            public static List<Role> getRoles(
260                    long companyId, Group group, String modelResource, int[] roleTypes) {
261    
262                    return getResourceActions().getRoles(
263                            companyId, group, modelResource, roleTypes);
264            }
265    
266            public static boolean hasModelResourceActions(String name) {
267                    return getResourceActions().hasModelResourceActions(name);
268            }
269    
270            /**
271             * @deprecated As of 6.1.0
272             */
273            @Deprecated
274            public static void init() {
275            }
276    
277            public static boolean isOrganizationModelResource(String modelResource) {
278                    return getResourceActions().isOrganizationModelResource(modelResource);
279            }
280    
281            public static boolean isPortalModelResource(String modelResource) {
282                    return getResourceActions().isPortalModelResource(modelResource);
283            }
284    
285            public static void read(
286                            String servletContextName, ClassLoader classLoader, String source)
287                    throws Exception {
288    
289                    getResourceActions().read(servletContextName, classLoader, source);
290            }
291    
292            /**
293             * @deprecated As of 7.0.0
294             */
295            @Deprecated
296            public static void read(String servletContextName, InputStream inputStream)
297                    throws Exception {
298    
299                    getResourceActions().read(servletContextName, inputStream);
300            }
301    
302            public void setResourceActions(ResourceActions resourceActions) {
303                    PortalRuntimePermission.checkSetBeanProperty(getClass());
304    
305                    _resourceActions = resourceActions;
306            }
307    
308            private static ResourceActions _resourceActions;
309    
310    }