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