001
014
015 package com.liferay.portal.security.permission;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.model.Role;
020 import com.liferay.portal.model.RoleConstants;
021 import com.liferay.portal.model.User;
022 import com.liferay.portal.service.RoleLocalServiceUtil;
023 import com.liferay.portal.service.UserLocalServiceUtil;
024 import com.liferay.portlet.admin.util.OmniadminUtil;
025
026 import javax.portlet.PortletRequest;
027
028
031 public abstract class BasePermissionChecker implements PermissionChecker {
032
033 public long getCompanyId() {
034 return user.getCompanyId();
035 }
036
037 public long getOwnerRoleId() {
038 return ownerRole.getRoleId();
039 }
040
041 public long[] getRoleIds(long userId, long groupId) {
042 return PermissionChecker.DEFAULT_ROLE_IDS;
043 }
044
045 public long getUserId() {
046 return user.getUserId();
047 }
048
049 public boolean hasOwnerPermission(
050 long companyId, String name, long primKey, long ownerId,
051 String actionId) {
052
053 return hasOwnerPermission(
054 companyId, name, String.valueOf(primKey), ownerId, actionId);
055 }
056
057 public boolean hasPermission(
058 long groupId, String name, long primKey, String actionId) {
059
060 return hasPermission(groupId, name, String.valueOf(primKey), actionId);
061 }
062
063 public void init(User user, boolean checkGuest) {
064 this.user = user;
065
066 if (user.isDefaultUser()) {
067 this.defaultUserId = user.getUserId();
068 this.signedIn = false;
069 }
070 else {
071 try {
072 this.defaultUserId = UserLocalServiceUtil.getDefaultUserId(
073 user.getCompanyId());
074 }
075 catch (Exception e) {
076 _log.error(e, e);
077 }
078
079 this.signedIn = true;
080 }
081
082 this.checkGuest = checkGuest;
083
084 try {
085 this.ownerRole = RoleLocalServiceUtil.getRole(
086 user.getCompanyId(), RoleConstants.OWNER);
087 }
088 catch (Exception e) {
089 _log.error(e, e);
090 }
091 }
092
093 public boolean isOmniadmin() {
094 if (omniadmin == null) {
095 omniadmin = Boolean.valueOf(OmniadminUtil.isOmniadmin(getUserId()));
096 }
097
098 return omniadmin.booleanValue();
099 }
100
101 public void resetValues() {
102 }
103
104 public void setCheckGuest(boolean checkGuest) {
105 this.checkGuest = checkGuest;
106 }
107
108 public void setValues(PortletRequest portletRequest) {
109
110
111
112
113
114
115
116 }
117
118 protected User user;
119 protected long defaultUserId;
120 protected boolean signedIn;
121 protected boolean checkGuest;
122 protected Boolean omniadmin;
123 protected Role ownerRole;
124
125 private static Log _log = LogFactoryUtil.getLog(
126 BasePermissionChecker.class);
127
128 }