1
22
23 package com.liferay.portlet.shopping.service.permission;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.security.permission.PermissionChecker;
28 import com.liferay.portal.security.auth.PrincipalException;
29 import com.liferay.portal.service.permission.PortletPermissionUtil;
30 import com.liferay.portal.util.PortletKeys;
31 import com.liferay.portlet.shopping.model.ShoppingCategory;
32 import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
33 import com.liferay.portlet.shopping.service.ShoppingCategoryLocalServiceUtil;
34
35
41 public class ShoppingCategoryPermission {
42
43 public static void check(
44 PermissionChecker permissionChecker, long plid, long categoryId,
45 String actionId)
46 throws PortalException, SystemException {
47
48 if (!contains(permissionChecker, plid, categoryId, actionId)) {
49 throw new PrincipalException();
50 }
51 }
52
53 public static void check(
54 PermissionChecker permissionChecker, long categoryId,
55 String actionId)
56 throws PortalException, SystemException {
57
58 if (!contains(permissionChecker, categoryId, actionId)) {
59 throw new PrincipalException();
60 }
61 }
62
63 public static void check(
64 PermissionChecker permissionChecker, ShoppingCategory category,
65 String actionId)
66 throws PortalException, SystemException {
67
68 if (!contains(permissionChecker, category, actionId)) {
69 throw new PrincipalException();
70 }
71 }
72
73 public static boolean contains(
74 PermissionChecker permissionChecker, long plid, long categoryId,
75 String actionId)
76 throws PortalException, SystemException {
77
78 if (categoryId == ShoppingCategoryImpl.DEFAULT_PARENT_CATEGORY_ID) {
79 return PortletPermissionUtil.contains(
80 permissionChecker, plid, PortletKeys.SHOPPING, actionId);
81 }
82 else {
83 return contains(permissionChecker, categoryId, actionId);
84 }
85 }
86
87 public static boolean contains(
88 PermissionChecker permissionChecker, long categoryId,
89 String actionId)
90 throws PortalException, SystemException {
91
92 ShoppingCategory category =
93 ShoppingCategoryLocalServiceUtil.getCategory(categoryId);
94
95 return contains(permissionChecker, category, actionId);
96 }
97
98 public static boolean contains(
99 PermissionChecker permissionChecker, ShoppingCategory category,
100 String actionId)
101 throws PortalException, SystemException {
102
103 long categoryId = category.getCategoryId();
104
105 while (categoryId != ShoppingCategoryImpl.DEFAULT_PARENT_CATEGORY_ID) {
106 category = ShoppingCategoryLocalServiceUtil.getCategory(categoryId);
107
108 categoryId = category.getParentCategoryId();
109
110 if (permissionChecker.hasPermission(
111 category.getGroupId(), ShoppingCategory.class.getName(),
112 category.getCategoryId(), actionId)) {
113
114 return true;
115 }
116 }
117
118 return false;
119 }
120
121 }