001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.expando.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.auth.PrincipalException;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portlet.expando.model.ExpandoColumn;
022    import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil;
023    
024    /**
025     * @author Raymond Augé
026     */
027    public class ExpandoColumnPermission {
028    
029            public static void check(
030                            PermissionChecker permissionChecker, ExpandoColumn column,
031                            String actionId)
032                    throws PortalException {
033    
034                    if (!contains(permissionChecker, column, actionId)) {
035                            throw new PrincipalException();
036                    }
037            }
038    
039            public static void check(
040                            PermissionChecker permissionChecker, long columnId, String actionId)
041                    throws PortalException, SystemException {
042    
043                    if (!contains(permissionChecker, columnId, actionId)) {
044                            throw new PrincipalException();
045                    }
046            }
047    
048            public static void check(
049                            PermissionChecker permissionChecker, long companyId,
050                            String className, String tableName, String columnName,
051                            String actionId)
052                    throws PortalException, SystemException {
053    
054                    if (!contains(
055                                    permissionChecker, companyId, className, tableName, columnName,
056                                    actionId)) {
057    
058                            throw new PrincipalException();
059                    }
060            }
061    
062            public static boolean contains(
063                    PermissionChecker permissionChecker, ExpandoColumn column,
064                    String actionId) {
065    
066                    return permissionChecker.hasPermission(
067                            0, ExpandoColumn.class.getName(), column.getColumnId(), actionId);
068            }
069    
070            public static boolean contains(
071                            PermissionChecker permissionChecker, long columnId, String actionId)
072                    throws PortalException, SystemException {
073    
074                    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
075                            columnId);
076    
077                    return contains(permissionChecker, column, actionId);
078            }
079    
080            public static boolean contains(
081                            PermissionChecker permissionChecker, long companyId,
082                            String className, String tableName, String columnName,
083                            String actionId)
084                    throws SystemException {
085    
086                    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
087                            companyId, className, tableName, columnName);
088    
089                    return contains(permissionChecker, column, actionId);
090            }
091    
092    }