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