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