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