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