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 recycle() {
106 user = null;
107 defaultUserId = 0;
108 signedIn = false;
109 checkGuest = false;
110 omniadmin = null;
111 resetValues();
112 }
113
114 public void resetValues() {
115 }
116
117 public void setCheckGuest(boolean checkGuest) {
118 this.checkGuest = checkGuest;
119 }
120
121 public void setValues(PortletRequest portletRequest) {
122
123
129 }
130
131 protected User user;
132 protected long defaultUserId;
133 protected boolean signedIn;
134 protected boolean checkGuest;
135 protected Boolean omniadmin;
136 protected Role ownerRole;
137
138 private static Log _log =
139 LogFactoryUtil.getLog(BasePermissionChecker.class);
140
141 }