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();
036                    }
037            }
038    
039            @Override
040            public void check(
041                            PermissionChecker permissionChecker, long columnId, String actionId)
042                    throws PortalException {
043    
044                    if (!contains(permissionChecker, columnId, actionId)) {
045                            throw new PrincipalException();
046                    }
047            }
048    
049            @Override
050            public void check(
051                            PermissionChecker permissionChecker, long companyId,
052                            String className, String tableName, String columnName,
053                            String actionId)
054                    throws PortalException {
055    
056                    if (!contains(
057                                    permissionChecker, companyId, className, tableName, columnName,
058                                    actionId)) {
059    
060                            throw new PrincipalException();
061                    }
062            }
063    
064            @Override
065            public boolean contains(
066                    PermissionChecker permissionChecker, ExpandoColumn column,
067                    String actionId) {
068    
069                    return permissionChecker.hasPermission(
070                            0, ExpandoColumn.class.getName(), column.getColumnId(), actionId);
071            }
072    
073            @Override
074            public boolean contains(
075                            PermissionChecker permissionChecker, long columnId, String actionId)
076                    throws PortalException {
077    
078                    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
079                            columnId);
080    
081                    return contains(permissionChecker, column, actionId);
082            }
083    
084            @Override
085            public boolean contains(
086                    PermissionChecker permissionChecker, long companyId, String className,
087                    String tableName, String columnName, String actionId) {
088    
089                    ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(
090                            companyId, className, tableName, columnName);
091    
092                    return contains(permissionChecker, column, actionId);
093            }
094    
095    }