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.softwarecatalog.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.softwarecatalog.model.SCProductEntry;
022    import com.liferay.portlet.softwarecatalog.service.SCProductEntryLocalServiceUtil;
023    
024    /**
025     * @author Jorge Ferrer
026     * @author Brian Wing Shun Chan
027     */
028    public class SCProductEntryPermission {
029    
030            public static void check(
031                            PermissionChecker permissionChecker, long productEntryId,
032                            String actionId)
033                    throws PortalException, SystemException {
034    
035                    if (!contains(permissionChecker, productEntryId, actionId)) {
036                            throw new PrincipalException();
037                    }
038            }
039    
040            public static void check(
041                            PermissionChecker permissionChecker, SCProductEntry productEntry,
042                            String actionId)
043                    throws PortalException {
044    
045                    if (!contains(permissionChecker, productEntry, actionId)) {
046                            throw new PrincipalException();
047                    }
048            }
049    
050            public static boolean contains(
051                            PermissionChecker permissionChecker, long productEntryId,
052                            String actionId)
053                    throws PortalException, SystemException {
054    
055                    SCProductEntry productEntry =
056                            SCProductEntryLocalServiceUtil.getProductEntry(productEntryId);
057    
058                    return contains(permissionChecker, productEntry, actionId);
059            }
060    
061            public static boolean contains(
062                    PermissionChecker permissionChecker, SCProductEntry productEntry,
063                    String actionId) {
064    
065                    if (permissionChecker.hasOwnerPermission(
066                                    productEntry.getCompanyId(), SCProductEntry.class.getName(),
067                                    productEntry.getProductEntryId(), productEntry.getUserId(),
068                                    actionId)) {
069    
070                            return true;
071                    }
072    
073                    return permissionChecker.hasPermission(
074                            productEntry.getGroupId(), SCProductEntry.class.getName(),
075                            productEntry.getProductEntryId(), actionId);
076            }
077    
078    }