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.portal.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.ActionKeys;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Julio Camarero
026     */
027    public class UserGroupRolePermissionImpl implements UserGroupRolePermission {
028    
029            public void check(
030                            PermissionChecker permissionChecker, long groupId, long roleId)
031                    throws PortalException, SystemException {
032    
033                    if (!contains(permissionChecker, groupId, roleId)) {
034                            throw new PrincipalException();
035                    }
036            }
037    
038            public boolean contains(
039                            PermissionChecker permissionChecker, long groupId, long roleId)
040                    throws PortalException, SystemException {
041    
042                    if (permissionChecker.isGroupOwner(groupId) ||
043                            GroupPermissionUtil.contains(
044                                    permissionChecker, groupId, ActionKeys.ASSIGN_USER_ROLES) ||
045                            RolePermissionUtil.contains(
046                                    permissionChecker, roleId, ActionKeys.ASSIGN_MEMBERS)) {
047    
048                            return true;
049                    }
050                    else {
051                            return false;
052                    }
053            }
054    
055    }