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