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();
037                    }
038            }
039    
040            @Override
041            public void check(
042                            PermissionChecker permissionChecker, long layoutSetBranchId,
043                            String actionId)
044                    throws PortalException {
045    
046                    if (!contains(permissionChecker, layoutSetBranchId, actionId)) {
047                            throw new PrincipalException();
048                    }
049            }
050    
051            @Override
052            public boolean contains(
053                    PermissionChecker permissionChecker, LayoutSetBranch layoutSetBranch,
054                    String actionId) {
055    
056                    return permissionChecker.hasPermission(
057                            layoutSetBranch.getGroupId(), LayoutSetBranch.class.getName(),
058                            layoutSetBranch.getLayoutSetBranchId(), actionId);
059            }
060    
061            @Override
062            public boolean contains(
063                            PermissionChecker permissionChecker, long layoutSetBranchId,
064                            String actionId)
065                    throws PortalException {
066    
067                    LayoutSetBranch layoutSetBranch =
068                            LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
069                                    layoutSetBranchId);
070    
071                    return contains(permissionChecker, layoutSetBranch, actionId);
072            }
073    
074    }