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