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
42 public abstract class BasePermissionChecker implements PermissionChecker {
43
44 public long getCompanyId() {
45 return user.getCompanyId();
46 }
47
48 public long getOwnerRoleId () {
49 return ownerRole.getRoleId();
50 }
51
52 public long getUserId() {
53 return user.getUserId();
54 }
55
56 public boolean hasOwnerPermission(
57 long companyId, String name, long primKey, long ownerId,
58 String actionId) {
59
60 return hasOwnerPermission(
61 companyId, name, String.valueOf(primKey), ownerId, actionId);
62 }
63
64 public boolean hasPermission(
65 long groupId, String name, long primKey, String actionId) {
66
67 return hasPermission(groupId, name, String.valueOf(primKey), actionId);
68 }
69
70 public void init(User user, boolean checkGuest) {
71 this.user = user;
72
73 if (user.isDefaultUser()) {
74 this.defaultUserId = user.getUserId();
75 this.signedIn = false;
76 }
77 else {
78 try {
79 this.defaultUserId = UserLocalServiceUtil.getDefaultUserId(
80 user.getCompanyId());
81 }
82 catch (Exception e) {
83 _log.error(e, e);
84 }
85
86 this.signedIn = true;
87 }
88
89 this.checkGuest = checkGuest;
90
91 try {
92 this.ownerRole = RoleLocalServiceUtil.getRole(
93 user.getCompanyId(), RoleConstants.OWNER);
94 }
95 catch (Exception e) {
96 _log.error(e, e);
97 }
98 }
99
100 public boolean isOmniadmin() {
101 if (omniadmin == null) {
102 omniadmin = Boolean.valueOf(OmniadminUtil.isOmniadmin(getUserId()));
103 }
104
105 return omniadmin.booleanValue();
106 }
107
108 public void resetValues() {
109 }
110
111 public void setCheckGuest(boolean checkGuest) {
112 this.checkGuest = checkGuest;
113 }
114
115 public void setValues(PortletRequest portletRequest) {
116
117
123 }
124
125 protected User user;
126 protected long defaultUserId;
127 protected boolean signedIn;
128 protected boolean checkGuest;
129 protected Boolean omniadmin;
130 protected Role ownerRole;
131
132 private static Log _log =
133 LogFactoryUtil.getLog(BasePermissionChecker.class);
134
135 }