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