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