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.portlet.mobiledevicerules.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.mobiledevicerules.model.MDRRuleGroupInstance;
022    import com.liferay.portlet.mobiledevicerules.service.MDRRuleGroupInstanceLocalServiceUtil;
023    
024    /**
025     * @author Michael C. Han
026     */
027    public class MDRRuleGroupInstancePermissionImpl
028            implements MDRRuleGroupInstancePermission {
029    
030            public void check(
031                            PermissionChecker permissionChecker, long ruleGroupInstanceId,
032                            String actionId)
033                    throws PortalException, SystemException {
034    
035                    if (!contains(permissionChecker, ruleGroupInstanceId, actionId)) {
036                            throw new PrincipalException();
037                    }
038            }
039    
040            public void check(
041                            PermissionChecker permissionChecker,
042                            MDRRuleGroupInstance ruleGroupInstance, String actionId)
043                    throws PortalException {
044    
045                    if (!contains(permissionChecker, ruleGroupInstance, actionId)) {
046                            throw new PrincipalException();
047                    }
048            }
049    
050            public boolean contains(
051                            PermissionChecker permissionChecker, long ruleGroupInstanceId,
052                            String actionId)
053                    throws PortalException, SystemException {
054    
055                    MDRRuleGroupInstance ruleGroupInstance =
056                            MDRRuleGroupInstanceLocalServiceUtil.getMDRRuleGroupInstance(
057                                    ruleGroupInstanceId);
058    
059                    return contains(permissionChecker, ruleGroupInstance, actionId);
060            }
061    
062            public boolean contains(
063                    PermissionChecker permissionChecker,
064                    MDRRuleGroupInstance ruleGroupInstance, String actionId) {
065    
066                    return permissionChecker.hasPermission(
067                            ruleGroupInstance.getGroupId(),
068                            MDRRuleGroupInstance.class.getName(),
069                            ruleGroupInstance.getRuleGroupInstanceId(), actionId);
070            }
071    
072    }