1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.permission;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.model.Team;
20  import com.liferay.portal.security.auth.PrincipalException;
21  import com.liferay.portal.security.permission.ActionKeys;
22  import com.liferay.portal.security.permission.PermissionChecker;
23  import com.liferay.portal.service.TeamLocalServiceUtil;
24  
25  /**
26   * <a href="TeamPermissionImpl.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class TeamPermissionImpl implements TeamPermission {
31  
32      public void check(
33              PermissionChecker permissionChecker, long teamId, String actionId)
34          throws PortalException, SystemException {
35  
36          if (!contains(permissionChecker, teamId, actionId)) {
37              throw new PrincipalException();
38          }
39      }
40  
41      public void check(
42              PermissionChecker permissionChecker, Team team, String actionId)
43          throws PortalException, SystemException {
44  
45          if (!contains(permissionChecker, team, actionId)) {
46              throw new PrincipalException();
47          }
48      }
49  
50      public boolean contains(
51              PermissionChecker permissionChecker, long teamId, String actionId)
52          throws PortalException, SystemException {
53  
54          Team team = TeamLocalServiceUtil.getTeam(teamId);
55  
56          return contains(permissionChecker, team, actionId);
57      }
58  
59      public boolean contains(
60              PermissionChecker permissionChecker, Team team, String actionId)
61          throws PortalException, SystemException {
62  
63          if (GroupPermissionUtil.contains(
64                  permissionChecker, team.getGroupId(),
65                  ActionKeys.MANAGE_TEAMS)) {
66  
67              return true;
68          }
69  
70          if (permissionChecker.hasOwnerPermission(
71                  team.getCompanyId(), Team.class.getName(), team.getTeamId(),
72                  team.getUserId(), actionId)) {
73  
74              return true;
75          }
76  
77          return permissionChecker.hasPermission(
78              team.getGroupId(), Team.class.getName(), team.getTeamId(),
79              actionId);
80      }
81  
82  }