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