001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.security.permission.ActionKeys;
026: import com.liferay.portal.model.Role;
027: import com.liferay.portal.model.User;
028: import com.liferay.portal.service.base.RoleServiceBaseImpl;
029: import com.liferay.portal.service.permission.PortalPermissionUtil;
030: import com.liferay.portal.service.permission.RolePermissionUtil;
031:
032: import java.util.List;
033:
034: /**
035: * <a href="RoleServiceImpl.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class RoleServiceImpl extends RoleServiceBaseImpl {
041:
042: public Role addRole(String name, String description, int type)
043: throws PortalException, SystemException {
044:
045: User user = getUser();
046:
047: PortalPermissionUtil.check(getPermissionChecker(),
048: ActionKeys.ADD_ROLE);
049:
050: return roleLocalService.addRole(user.getUserId(), user
051: .getCompanyId(), name, description, type);
052: }
053:
054: public void addUserRoles(long userId, long[] roleIds)
055: throws PortalException, SystemException {
056:
057: checkUserRolesPermission(userId, roleIds);
058:
059: roleLocalService.addUserRoles(userId, roleIds);
060: }
061:
062: public void deleteRole(long roleId) throws PortalException,
063: SystemException {
064:
065: RolePermissionUtil.check(getPermissionChecker(), roleId,
066: ActionKeys.DELETE);
067:
068: roleLocalService.deleteRole(roleId);
069: }
070:
071: public Role getGroupRole(long companyId, long groupId)
072: throws PortalException, SystemException {
073:
074: return roleLocalService.getGroupRole(companyId, groupId);
075: }
076:
077: public List getGroupRoles(long groupId) throws PortalException,
078: SystemException {
079:
080: return roleLocalService.getGroupRoles(groupId);
081: }
082:
083: public Role getRole(long roleId) throws PortalException,
084: SystemException {
085:
086: return roleLocalService.getRole(roleId);
087: }
088:
089: public Role getRole(long companyId, String name)
090: throws PortalException, SystemException {
091:
092: return roleLocalService.getRole(companyId, name);
093: }
094:
095: public List getUserGroupRoles(long userId, long groupId)
096: throws PortalException, SystemException {
097:
098: return roleLocalService.getUserGroupRoles(userId, groupId);
099: }
100:
101: public List getUserRelatedRoles(long userId, List groups)
102: throws PortalException, SystemException {
103:
104: return roleLocalService.getUserRelatedRoles(userId, groups);
105: }
106:
107: public List getUserRoles(long userId) throws PortalException,
108: SystemException {
109:
110: return roleLocalService.getUserRoles(userId);
111: }
112:
113: public boolean hasUserRole(long userId, long companyId,
114: String name, boolean inherited) throws PortalException,
115: SystemException {
116:
117: return roleLocalService.hasUserRole(userId, companyId, name,
118: inherited);
119: }
120:
121: public boolean hasUserRoles(long userId, long companyId,
122: String[] names, boolean inherited) throws PortalException,
123: SystemException {
124:
125: return roleLocalService.hasUserRoles(userId, companyId, names,
126: 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(getPermissionChecker(), roleId,
141: 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(getPermissionChecker(),
151: roleIds[i], ActionKeys.ASSIGN_MEMBERS);
152: }
153: }
154:
155: }
|