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.portal.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.model.LayoutSetBranch;
019    import com.liferay.portal.security.auth.PrincipalException;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class LayoutSetBranchPermissionImpl
027            implements LayoutSetBranchPermission {
028    
029            @Override
030            public void check(
031                            PermissionChecker permissionChecker,
032                            LayoutSetBranch layoutSetBranch, String actionId)
033                    throws PortalException {
034    
035                    if (!contains(permissionChecker, layoutSetBranch, actionId)) {
036                            throw new PrincipalException.MustHavePermission(
037                                    permissionChecker, LayoutSetBranch.class.getName(),
038                                    layoutSetBranch.getLayoutSetBranchId(), actionId);
039                    }
040            }
041    
042            @Override
043            public void check(
044                            PermissionChecker permissionChecker, long layoutSetBranchId,
045                            String actionId)
046                    throws PortalException {
047    
048                    if (!contains(permissionChecker, layoutSetBranchId, actionId)) {
049                            throw new PrincipalException.MustHavePermission(
050                                    permissionChecker, LayoutSetBranch.class.getName(),
051                                    layoutSetBranchId, actionId);
052                    }
053            }
054    
055            @Override
056            public boolean contains(
057                    PermissionChecker permissionChecker, LayoutSetBranch layoutSetBranch,
058                    String actionId) {
059    
060                    return permissionChecker.hasPermission(
061                            layoutSetBranch.getGroupId(), LayoutSetBranch.class.getName(),
062                            layoutSetBranch.getLayoutSetBranchId(), actionId);
063            }
064    
065            @Override
066            public boolean contains(
067                            PermissionChecker permissionChecker, long layoutSetBranchId,
068                            String actionId)
069                    throws PortalException {
070    
071                    LayoutSetBranch layoutSetBranch =
072                            LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
073                                    layoutSetBranchId);
074    
075                    return contains(permissionChecker, layoutSetBranch, actionId);
076            }
077    
078    }