001    /**
002     * Copyright (c) 2000-2013 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 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    }