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.portlet.journal.service.permission;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.security.auth.PrincipalException;
20  import com.liferay.portal.security.permission.PermissionChecker;
21  import com.liferay.portlet.journal.model.JournalFeed;
22  import com.liferay.portlet.journal.service.JournalFeedLocalServiceUtil;
23  
24  /**
25   * <a href="JournalFeedPermission.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Raymond Augé
28   */
29  public class JournalFeedPermission {
30  
31      public static void check(
32              PermissionChecker permissionChecker, JournalFeed feed,
33              String actionId)
34          throws PortalException {
35  
36          if (!contains(permissionChecker, feed, actionId)) {
37              throw new PrincipalException();
38          }
39      }
40  
41      public static void check(
42              PermissionChecker permissionChecker, long id, String actionId)
43          throws PortalException, SystemException {
44  
45          if (!contains(permissionChecker, id, actionId)) {
46              throw new PrincipalException();
47          }
48      }
49  
50      public static void check(
51              PermissionChecker permissionChecker, long groupId, String feedId,
52              String actionId)
53          throws PortalException, SystemException {
54  
55          if (!contains(permissionChecker, groupId, feedId, actionId)) {
56              throw new PrincipalException();
57          }
58      }
59  
60      public static boolean contains(
61          PermissionChecker permissionChecker, JournalFeed feed,
62          String actionId) {
63  
64          if (permissionChecker.hasOwnerPermission(
65                  feed.getCompanyId(), JournalFeed.class.getName(),
66                  feed.getId(), feed.getUserId(), actionId)) {
67  
68              return true;
69          }
70  
71          return permissionChecker.hasPermission(
72              feed.getGroupId(), JournalFeed.class.getName(), feed.getId(),
73              actionId);
74      }
75  
76      public static boolean contains(
77              PermissionChecker permissionChecker, long feedId, String actionId)
78          throws PortalException, SystemException {
79  
80          JournalFeed feed = JournalFeedLocalServiceUtil.getFeed(feedId);
81  
82          return contains(permissionChecker, feed, actionId);
83      }
84  
85      public static boolean contains(
86              PermissionChecker permissionChecker, long groupId, String feedId,
87              String actionId)
88          throws PortalException, SystemException {
89  
90          JournalFeed feed = JournalFeedLocalServiceUtil.getFeed(groupId, feedId);
91  
92          return contains(permissionChecker, feed, actionId);
93      }
94  
95  }