1
22
23 package com.liferay.portal.service.impl;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.model.Group;
28 import com.liferay.portal.model.Role;
29 import com.liferay.portal.model.User;
30 import com.liferay.portal.security.permission.ActionKeys;
31 import com.liferay.portal.service.base.RoleServiceBaseImpl;
32 import com.liferay.portal.service.permission.PortalPermissionUtil;
33 import com.liferay.portal.service.permission.RolePermissionUtil;
34
35 import java.util.List;
36
37
42 public class RoleServiceImpl extends RoleServiceBaseImpl {
43
44 public Role addRole(String name, String description, int type)
45 throws PortalException, SystemException {
46
47 User user = getUser();
48
49 PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE);
50
51 return roleLocalService.addRole(
52 user.getUserId(), user.getCompanyId(), name, description, type);
53 }
54
55 public void addUserRoles(long userId, long[] roleIds)
56 throws PortalException, SystemException {
57
58 checkUserRolesPermission(userId, roleIds);
59
60 roleLocalService.addUserRoles(userId, roleIds);
61 }
62
63 public void deleteRole(long roleId)
64 throws PortalException, SystemException {
65
66 RolePermissionUtil.check(
67 getPermissionChecker(), roleId, ActionKeys.DELETE);
68
69 roleLocalService.deleteRole(roleId);
70 }
71
72 public Role getGroupRole(long companyId, long groupId)
73 throws PortalException, SystemException {
74
75 return roleLocalService.getGroupRole(companyId, groupId);
76 }
77
78 public List<Role> getGroupRoles(long groupId) throws SystemException {
79 return roleLocalService.getGroupRoles(groupId);
80 }
81
82 public Role getRole(long roleId)
83 throws PortalException, SystemException {
84
85 return roleLocalService.getRole(roleId);
86 }
87
88 public Role getRole(long companyId, String name)
89 throws PortalException, SystemException {
90
91 return roleLocalService.getRole(companyId, name);
92 }
93
94 public List<Role> getUserGroupRoles(long userId, long groupId)
95 throws SystemException {
96
97 return roleLocalService.getUserGroupRoles(userId, groupId);
98 }
99
100 public List<Role> getUserRelatedRoles(long userId, List<Group> groups)
101 throws SystemException {
102
103 return roleLocalService.getUserRelatedRoles(userId, groups);
104 }
105
106 public List<Role> getUserRoles(long userId) throws SystemException {
107 return roleLocalService.getUserRoles(userId);
108 }
109
110 public boolean hasUserRole(
111 long userId, long companyId, String name, boolean inherited)
112 throws PortalException, SystemException {
113
114 return roleLocalService.hasUserRole(userId, companyId, name, inherited);
115 }
116
117 public boolean hasUserRoles(
118 long userId, long companyId, String[] names, boolean inherited)
119 throws PortalException, SystemException {
120
121 return roleLocalService.hasUserRoles(
122 userId, companyId, names, inherited);
123 }
124
125 public void unsetUserRoles(long userId, long[] roleIds)
126 throws PortalException, SystemException {
127
128 checkUserRolesPermission(userId, roleIds);
129
130 roleLocalService.unsetUserRoles(userId, roleIds);
131 }
132
133 public Role updateRole(long roleId, String name, String description)
134 throws PortalException, SystemException {
135
136 RolePermissionUtil.check(
137 getPermissionChecker(), roleId, ActionKeys.UPDATE);
138
139 return roleLocalService.updateRole(roleId, name, description);
140 }
141
142 protected void checkUserRolesPermission(long userId, long[] roleIds)
143 throws PortalException {
144
145 for (int i = 0; i < roleIds.length; i++) {
146 RolePermissionUtil.check(
147 getPermissionChecker(), roleIds[i], ActionKeys.ASSIGN_MEMBERS);
148 }
149 }
150
151 }