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