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.model.GroupConstants;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portlet.softwarecatalog.model.SCLicense;
023    import com.liferay.portlet.softwarecatalog.service.SCLicenseLocalServiceUtil;
024    
025    /**
026     * @author Jorge Ferrer
027     * @author Brian Wing Shun Chan
028     */
029    public class SCLicensePermission {
030    
031            public static void check(
032                            PermissionChecker permissionChecker, long productEntryId,
033                            String actionId)
034                    throws PortalException, SystemException {
035    
036                    if (!contains(permissionChecker, productEntryId, actionId)) {
037                            throw new PrincipalException();
038                    }
039            }
040    
041            public static void check(
042                            PermissionChecker permissionChecker, SCLicense license,
043                            String actionId)
044                    throws PortalException {
045    
046                    if (!contains(permissionChecker, license, actionId)) {
047                            throw new PrincipalException();
048                    }
049            }
050    
051            public static boolean contains(
052                            PermissionChecker permissionChecker, long licenseId,
053                            String actionId)
054                    throws PortalException, SystemException {
055    
056                    SCLicense license = SCLicenseLocalServiceUtil.getLicense(licenseId);
057    
058                    return contains(permissionChecker, license, actionId);
059            }
060    
061            public static boolean contains(
062                    PermissionChecker permissionChecker, SCLicense license,
063                    String actionId) {
064    
065                    return permissionChecker.hasPermission(
066                            GroupConstants.DEFAULT_PARENT_GROUP_ID, SCLicense.class.getName(),
067                            license.getLicenseId(), actionId);
068            }
069    
070    }