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