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