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