001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.model.Group;
020 import com.liferay.portal.model.Role;
021 import com.liferay.portal.model.User;
022 import com.liferay.portal.security.permission.ActionKeys;
023 import com.liferay.portal.service.base.RoleServiceBaseImpl;
024 import com.liferay.portal.service.permission.PortalPermissionUtil;
025 import com.liferay.portal.service.permission.RolePermissionUtil;
026
027 import java.util.List;
028 import java.util.Locale;
029 import java.util.Map;
030
031
034 public class RoleServiceImpl extends RoleServiceBaseImpl {
035
036 public Role addRole(
037 String name, Map<Locale, String> titleMap, String description,
038 int type)
039 throws PortalException, SystemException {
040
041 User user = getUser();
042
043 PortalPermissionUtil.check(getPermissionChecker(), ActionKeys.ADD_ROLE);
044
045 return roleLocalService.addRole(
046 user.getUserId(), user.getCompanyId(), name, titleMap, description,
047 type);
048 }
049
050 public void addUserRoles(long userId, long[] roleIds)
051 throws PortalException, SystemException {
052
053 checkUserRolesPermission(userId, roleIds);
054
055 roleLocalService.addUserRoles(userId, roleIds);
056 }
057
058 public void deleteRole(long roleId)
059 throws PortalException, SystemException {
060
061 RolePermissionUtil.check(
062 getPermissionChecker(), roleId, ActionKeys.DELETE);
063
064 roleLocalService.deleteRole(roleId);
065 }
066
067 public List<Role> getGroupRoles(long groupId) throws SystemException {
068 return roleLocalService.getGroupRoles(groupId);
069 }
070
071 public Role getRole(long roleId)
072 throws PortalException, SystemException {
073
074 return roleLocalService.getRole(roleId);
075 }
076
077 public Role getRole(long companyId, String name)
078 throws PortalException, SystemException {
079
080 return roleLocalService.getRole(companyId, name);
081 }
082
083 public List<Role> getUserGroupGroupRoles(long userId, long groupId)
084 throws SystemException {
085
086 return roleLocalService.getUserGroupGroupRoles(userId, groupId);
087 }
088
089 public List<Role> getUserGroupRoles(long userId, long groupId)
090 throws SystemException {
091
092 return roleLocalService.getUserGroupRoles(userId, groupId);
093 }
094
095 public List<Role> getUserRelatedRoles(long userId, List<Group> groups)
096 throws SystemException {
097
098 return roleLocalService.getUserRelatedRoles(userId, groups);
099 }
100
101 public List<Role> getUserRoles(long userId) throws SystemException {
102 return roleLocalService.getUserRoles(userId);
103 }
104
105 public boolean hasUserRole(
106 long userId, long companyId, String name, boolean inherited)
107 throws PortalException, SystemException {
108
109 return roleLocalService.hasUserRole(userId, companyId, name, inherited);
110 }
111
112 public boolean hasUserRoles(
113 long userId, long companyId, String[] names, boolean inherited)
114 throws PortalException, SystemException {
115
116 return roleLocalService.hasUserRoles(
117 userId, companyId, names, inherited);
118 }
119
120 public void unsetUserRoles(long userId, long[] roleIds)
121 throws PortalException, SystemException {
122
123 checkUserRolesPermission(userId, roleIds);
124
125 roleLocalService.unsetUserRoles(userId, roleIds);
126 }
127
128 public Role updateRole(
129 long roleId, String name, Map<Locale, String> titleMap,
130 String description, String subtype)
131 throws PortalException, SystemException {
132
133 RolePermissionUtil.check(
134 getPermissionChecker(), roleId, ActionKeys.UPDATE);
135
136 return roleLocalService.updateRole(
137 roleId, name, titleMap, description, subtype);
138 }
139
140 protected void checkUserRolesPermission(long userId, long[] roleIds)
141 throws PortalException {
142
143 for (int i = 0; i < roleIds.length; i++) {
144 RolePermissionUtil.check(
145 getPermissionChecker(), roleIds[i], ActionKeys.ASSIGN_MEMBERS);
146 }
147 }
148
149 }