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