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.portal.service.impl;
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    import com.liferay.portal.service.base.UserGroupRoleServiceBaseImpl;
023    import com.liferay.portal.service.permission.GroupPermissionUtil;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class UserGroupRoleServiceImpl extends UserGroupRoleServiceBaseImpl {
029    
030            public void addUserGroupRoles(long userId, long groupId, long[] roleIds)
031                    throws PortalException, SystemException {
032    
033                    PermissionChecker permissionChecker = getPermissionChecker();
034    
035                    if (!permissionChecker.isCommunityOwner(groupId) &&
036                            !GroupPermissionUtil.contains(
037                                    permissionChecker, groupId, ActionKeys.ASSIGN_USER_ROLES)) {
038    
039                            throw new PrincipalException();
040                    }
041    
042                    userGroupRoleLocalService.addUserGroupRoles(userId, groupId, roleIds);
043            }
044    
045            public void addUserGroupRoles(long[] userIds, long groupId, long roleId)
046                    throws PortalException, SystemException {
047    
048                    PermissionChecker permissionChecker = getPermissionChecker();
049    
050                    if (!permissionChecker.isCommunityOwner(groupId) &&
051                            !GroupPermissionUtil.contains(
052                                    permissionChecker, groupId, ActionKeys.ASSIGN_USER_ROLES)) {
053    
054                            throw new PrincipalException();
055                    }
056    
057                    userGroupRoleLocalService.addUserGroupRoles(userIds, groupId, roleId);
058            }
059    
060            public void deleteUserGroupRoles(long userId, long groupId, long[] roleIds)
061                    throws PortalException, SystemException {
062    
063                    PermissionChecker permissionChecker = getPermissionChecker();
064    
065                    if (!permissionChecker.isCommunityOwner(groupId)) {
066                            throw new PrincipalException();
067                    }
068    
069                    userGroupRoleLocalService.deleteUserGroupRoles(
070                            userId, groupId, roleIds);
071            }
072    
073            public void deleteUserGroupRoles(long[] userIds, long groupId, long roleId)
074                    throws PortalException, SystemException {
075    
076                    PermissionChecker permissionChecker = getPermissionChecker();
077    
078                    if (!permissionChecker.isCommunityOwner(groupId) &&
079                            !GroupPermissionUtil.contains(
080                                    permissionChecker, groupId, ActionKeys.ASSIGN_USER_ROLES)) {
081    
082                            throw new PrincipalException();
083                    }
084    
085                    userGroupRoleLocalService.deleteUserGroupRoles(
086                            userIds, groupId, roleId);
087            }
088    
089    }