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