001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.LayoutSetBranch;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.LayoutSetBranchLocalServiceUtil;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class LayoutSetBranchPermissionImpl
028            implements LayoutSetBranchPermission {
029    
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            public void check(
041                            PermissionChecker permissionChecker, long layoutSetBranchId,
042                            String actionId)
043                    throws PortalException, SystemException {
044    
045                    if (!contains(
046                                    permissionChecker, layoutSetBranchId, actionId)) {
047    
048                            throw new PrincipalException();
049                    }
050            }
051    
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            public boolean contains(
062                            PermissionChecker permissionChecker, long layoutSetBranchId,
063                            String actionId)
064                    throws PortalException, SystemException {
065    
066                    LayoutSetBranch layoutSetBranch =
067                            LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(
068                                    layoutSetBranchId);
069    
070                    return contains(permissionChecker, layoutSetBranch, actionId);
071            }
072    
073    }