1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.security.auth.PrincipalException;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.security.permission.PermissionChecker;
22  import com.liferay.portal.service.base.UserGroupRoleServiceBaseImpl;
23  import com.liferay.portal.service.permission.GroupPermissionUtil;
24  
25  /**
26   * <a href="UserGroupRoleServiceImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class UserGroupRoleServiceImpl extends UserGroupRoleServiceBaseImpl {
31  
32      public void addUserGroupRoles(long userId, long groupId, long[] roleIds)
33          throws PortalException, SystemException {
34  
35          PermissionChecker permissionChecker = getPermissionChecker();
36  
37          if (!permissionChecker.isCommunityOwner(groupId) &&
38              !GroupPermissionUtil.contains(
39                  permissionChecker, groupId, ActionKeys.ASSIGN_USER_ROLES)) {
40  
41              throw new PrincipalException();
42          }
43  
44          userGroupRoleLocalService.addUserGroupRoles(userId, groupId, roleIds);
45      }
46  
47      public void addUserGroupRoles(long[] userIds, long groupId, long roleId)
48          throws PortalException, SystemException {
49  
50          PermissionChecker permissionChecker = getPermissionChecker();
51  
52          if (!permissionChecker.isCommunityOwner(groupId) &&
53              !GroupPermissionUtil.contains(
54                  permissionChecker, groupId, ActionKeys.ASSIGN_USER_ROLES)) {
55  
56              throw new PrincipalException();
57          }
58  
59          userGroupRoleLocalService.addUserGroupRoles(userIds, groupId, roleId);
60      }
61  
62      public void deleteUserGroupRoles(long userId, long groupId, long[] roleIds)
63          throws PortalException, SystemException {
64  
65          PermissionChecker permissionChecker = getPermissionChecker();
66  
67          if (!permissionChecker.isCommunityOwner(groupId)) {
68              throw new PrincipalException();
69          }
70  
71          userGroupRoleLocalService.deleteUserGroupRoles(
72              userId, groupId, roleIds);
73      }
74  
75      public void deleteUserGroupRoles(long[] userIds, long groupId, long roleId)
76          throws PortalException, SystemException {
77  
78          PermissionChecker permissionChecker = getPermissionChecker();
79  
80          if (!permissionChecker.isCommunityOwner(groupId) &&
81              !GroupPermissionUtil.contains(
82                  permissionChecker, groupId, ActionKeys.ASSIGN_USER_ROLES)) {
83  
84              throw new PrincipalException();
85          }
86  
87          userGroupRoleLocalService.deleteUserGroupRoles(
88              userIds, groupId, roleId);
89      }
90  
91  }