1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.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  }