001    /**
002     * Copyright (c) 2000-2010 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.portlet.journal.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.auth.PrincipalException;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portlet.journal.model.JournalStructure;
022    import com.liferay.portlet.journal.service.JournalStructureLocalServiceUtil;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     * @author Raymond Augé
027     */
028    public class JournalStructurePermission {
029    
030            public static void check(
031                            PermissionChecker permissionChecker, JournalStructure structure,
032                            String actionId)
033                    throws PortalException {
034    
035                    if (!contains(permissionChecker, structure, actionId)) {
036                            throw new PrincipalException();
037                    }
038            }
039    
040            public static void check(
041                            PermissionChecker permissionChecker, long id, String actionId)
042                    throws PortalException, SystemException {
043    
044                    if (!contains(permissionChecker, id, actionId)) {
045                            throw new PrincipalException();
046                    }
047            }
048    
049            public static void check(
050                            PermissionChecker permissionChecker, long groupId,
051                            String structureId, String actionId)
052                    throws PortalException, SystemException {
053    
054                    if (!contains(permissionChecker, groupId, structureId, actionId)) {
055                            throw new PrincipalException();
056                    }
057            }
058    
059            public static boolean contains(
060                    PermissionChecker permissionChecker, JournalStructure structure,
061                    String actionId) {
062    
063                    if (permissionChecker.hasOwnerPermission(
064                                    structure.getCompanyId(), JournalStructure.class.getName(),
065                                    structure.getId(), structure.getUserId(), actionId)) {
066    
067                            return true;
068                    }
069    
070                    return permissionChecker.hasPermission(
071                            structure.getGroupId(), JournalStructure.class.getName(),
072                            structure.getId(), actionId);
073            }
074    
075            public static boolean contains(
076                            PermissionChecker permissionChecker, long id, String actionId)
077                    throws PortalException, SystemException {
078    
079                    JournalStructure structure =
080                            JournalStructureLocalServiceUtil.getStructure(id);
081    
082                    return contains(permissionChecker, structure, actionId);
083            }
084    
085            public static boolean contains(
086                            PermissionChecker permissionChecker, long groupId,
087                            String structureId, String actionId)
088                    throws PortalException, SystemException {
089    
090                    JournalStructure structure =
091                            JournalStructureLocalServiceUtil.getStructure(groupId, structureId);
092    
093                    return contains(permissionChecker, structure, actionId);
094            }
095    
096    }