1
22
23 package com.liferay.portal.security.permission;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.model.Role;
28 import com.liferay.portal.model.RoleConstants;
29 import com.liferay.portal.model.User;
30 import com.liferay.portal.service.RoleLocalServiceUtil;
31 import com.liferay.portal.service.UserLocalServiceUtil;
32 import com.liferay.portlet.admin.util.OmniadminUtil;
33
34 import javax.portlet.PortletRequest;
35
36
41 public abstract class BasePermissionChecker implements PermissionChecker {
42
43 public long getCompanyId() {
44 return user.getCompanyId();
45 }
46
47 public long getOwnerRoleId () {
48 return ownerRole.getRoleId();
49 }
50
51 public long getUserId() {
52 return user.getUserId();
53 }
54
55 public boolean hasOwnerPermission(
56 long companyId, String name, long primKey, long ownerId,
57 String actionId) {
58
59 return hasOwnerPermission(
60 companyId, name, String.valueOf(primKey), ownerId, actionId);
61 }
62
63 public boolean hasPermission(
64 long groupId, String name, long primKey, String actionId) {
65
66 return hasPermission(groupId, name, String.valueOf(primKey), actionId);
67 }
68
69 public void init(User user, boolean checkGuest) {
70 this.user = user;
71
72 if (user.isDefaultUser()) {
73 this.defaultUserId = user.getUserId();
74 this.signedIn = false;
75 }
76 else {
77 try {
78 this.defaultUserId = UserLocalServiceUtil.getDefaultUserId(
79 user.getCompanyId());
80 }
81 catch (Exception e) {
82 _log.error(e, e);
83 }
84
85 this.signedIn = true;
86 }
87
88 this.checkGuest = checkGuest;
89
90 try {
91 this.ownerRole = RoleLocalServiceUtil.getRole(
92 user.getCompanyId(), RoleConstants.OWNER);
93 }
94 catch (Exception e) {
95 _log.error(e, e);
96 }
97 }
98
99 public boolean isOmniadmin() {
100 if (omniadmin == null) {
101 omniadmin = Boolean.valueOf(OmniadminUtil.isOmniadmin(getUserId()));
102 }
103
104 return omniadmin.booleanValue();
105 }
106
107 public void recycle() {
108 user = null;
109 defaultUserId = 0;
110 signedIn = false;
111 checkGuest = false;
112 omniadmin = null;
113 resetValues();
114 }
115
116 public void resetValues() {
117 }
118
119 public void setCheckGuest(boolean checkGuest) {
120 this.checkGuest = checkGuest;
121 }
122
123 public void setValues(PortletRequest portletRequest) {
124
125
131 }
132
133 protected User user;
134 protected long defaultUserId;
135 protected boolean signedIn;
136 protected boolean checkGuest;
137 protected Boolean omniadmin;
138 protected Role ownerRole;
139
140 private static Log _log =
141 LogFactoryUtil.getLog(BasePermissionChecker.class);
142
143 }