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