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