001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.Team;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.security.permission.PermissionChecker;
023    import com.liferay.portal.service.TeamLocalServiceUtil;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class TeamPermissionImpl implements TeamPermission {
029    
030            public void check(
031                            PermissionChecker permissionChecker, long teamId, String actionId)
032                    throws PortalException, SystemException {
033    
034                    if (!contains(permissionChecker, teamId, actionId)) {
035                            throw new PrincipalException();
036                    }
037            }
038    
039            public void check(
040                            PermissionChecker permissionChecker, Team team, String actionId)
041                    throws PortalException, SystemException {
042    
043                    if (!contains(permissionChecker, team, actionId)) {
044                            throw new PrincipalException();
045                    }
046            }
047    
048            public boolean contains(
049                            PermissionChecker permissionChecker, long teamId, String actionId)
050                    throws PortalException, SystemException {
051    
052                    Team team = TeamLocalServiceUtil.getTeam(teamId);
053    
054                    return contains(permissionChecker, team, actionId);
055            }
056    
057            public boolean contains(
058                            PermissionChecker permissionChecker, Team team, String actionId)
059                    throws PortalException, SystemException {
060    
061                    if (GroupPermissionUtil.contains(
062                                    permissionChecker, team.getGroupId(),
063                                    ActionKeys.MANAGE_TEAMS)) {
064    
065                            return true;
066                    }
067    
068                    if (permissionChecker.hasOwnerPermission(
069                                    team.getCompanyId(), Team.class.getName(), team.getTeamId(),
070                                    team.getUserId(), actionId)) {
071    
072                            return true;
073                    }
074    
075                    return permissionChecker.hasPermission(
076                            team.getGroupId(), Team.class.getName(), team.getTeamId(),
077                            actionId);
078            }
079    
080    }