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