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.portlet.expando.service.permission;
016    
017    import com.liferay.expando.kernel.model.ExpandoColumn;
018    import com.liferay.expando.kernel.service.ExpandoColumnLocalServiceUtil;
019    import com.liferay.expando.kernel.service.permission.ExpandoColumnPermission;
020    import com.liferay.portal.kernel.exception.PortalException;
021    import com.liferay.portal.kernel.security.auth.PrincipalException;
022    import com.liferay.portal.kernel.security.permission.PermissionChecker;
023    
024    /**
025     * @author Raymond Augé
026     */
027    public class ExpandoColumnPermissionImpl implements ExpandoColumnPermission {
028    
029            @Override
030            public void check(
031                            PermissionChecker permissionChecker, ExpandoColumn column,
032                            String actionId)
033                    throws PortalException {
034    
035                    if (!contains(permissionChecker, column, actionId)) {
036                            throw new PrincipalException.MustHavePermission(
037                                    permissionChecker, ExpandoColumn.class.getName(),
038                                    column.getColumnId(), actionId);
039                    }
040            }
041    
042            @Override
043            public void check(
044                            PermissionChecker permissionChecker, long columnId, String actionId)
045                    throws PortalException {
046    
047                    if (!contains(permissionChecker, columnId, actionId)) {
048                            throw new PrincipalException.MustHavePermission(
049                                    permissionChecker, ExpandoColumn.class.getName(), columnId,
050                                    actionId);
051                    }
052            }
053    
054            @Override
055            public void check(
056                            PermissionChecker permissionChecker, long companyId,
057                            String className, String tableName, String columnName,
058                            String actionId)
059                    throws PortalException {
060    
061                    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
062                            companyId, className, tableName, columnName);
063    
064                    check(permissionChecker, column, actionId);
065            }
066    
067            @Override
068            public boolean contains(
069                    PermissionChecker permissionChecker, ExpandoColumn column,
070                    String actionId) {
071    
072                    return permissionChecker.hasPermission(
073                            0, ExpandoColumn.class.getName(), column.getColumnId(), actionId);
074            }
075    
076            @Override
077            public boolean contains(
078                            PermissionChecker permissionChecker, long columnId, String actionId)
079                    throws PortalException {
080    
081                    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
082                            columnId);
083    
084                    return contains(permissionChecker, column, actionId);
085            }
086    
087            @Override
088            public boolean contains(
089                    PermissionChecker permissionChecker, long companyId, String className,
090                    String tableName, String columnName, String actionId) {
091    
092                    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
093                            companyId, className, tableName, columnName);
094    
095                    return contains(permissionChecker, column, actionId);
096            }
097    
098    }