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