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 java.util.Collections;
027 import java.util.List;
028
029 import javax.portlet.PortletRequest;
030
031
034 public abstract class BasePermissionChecker implements PermissionChecker {
035
036 @Override
037 public abstract PermissionChecker clone();
038
039 public long getCompanyId() {
040 return user.getCompanyId();
041 }
042
043 public List<Long> getGuestResourceBlockIds(
044 long companyId, long groupId, String name, String actionId) {
045
046 return Collections.emptyList();
047 }
048
049 public List<Long> getOwnerResourceBlockIds(
050 long companyId, long groupId, String name, String actionId) {
051
052 return Collections.emptyList();
053 }
054
055 public long getOwnerRoleId() {
056 return ownerRole.getRoleId();
057 }
058
059 public List<Long> getResourceBlockIds(
060 long companyId, long groupId, long userId, String name,
061 String actionId) {
062
063 return Collections.emptyList();
064 }
065
066 public long[] getRoleIds(long userId, long groupId) {
067 return PermissionChecker.DEFAULT_ROLE_IDS;
068 }
069
070 public long getUserId() {
071 return user.getUserId();
072 }
073
074 public boolean hasOwnerPermission(
075 long companyId, String name, long primKey, long ownerId,
076 String actionId) {
077
078 return hasOwnerPermission(
079 companyId, name, String.valueOf(primKey), ownerId, actionId);
080 }
081
082 public boolean hasPermission(
083 long groupId, String name, long primKey, String actionId) {
084
085 return hasPermission(groupId, name, String.valueOf(primKey), actionId);
086 }
087
088 public void init(User user, boolean checkGuest) {
089 this.user = user;
090
091 if (user.isDefaultUser()) {
092 this.defaultUserId = user.getUserId();
093 this.signedIn = false;
094 }
095 else {
096 try {
097 this.defaultUserId = UserLocalServiceUtil.getDefaultUserId(
098 user.getCompanyId());
099 }
100 catch (Exception e) {
101 _log.error(e, e);
102 }
103
104 this.signedIn = true;
105 }
106
107 this.checkGuest = checkGuest;
108
109 try {
110 this.ownerRole = RoleLocalServiceUtil.getRole(
111 user.getCompanyId(), RoleConstants.OWNER);
112 }
113 catch (Exception e) {
114 _log.error(e, e);
115 }
116 }
117
118 public boolean isCheckGuest() {
119 return checkGuest;
120 }
121
122
125 public boolean isCommunityAdmin(long groupId) {
126 return isGroupAdmin(groupId);
127 }
128
129
132 public boolean isCommunityOwner(long groupId) {
133 return isGroupOwner(groupId);
134 }
135
136 public boolean isOmniadmin() {
137 if (omniadmin == null) {
138 omniadmin = Boolean.valueOf(OmniadminUtil.isOmniadmin(getUserId()));
139 }
140
141 return omniadmin.booleanValue();
142 }
143
144 public boolean isSignedIn() {
145 return signedIn;
146 }
147
148 public void resetValues() {
149 }
150
151 public void setCheckGuest(boolean checkGuest) {
152 this.checkGuest = checkGuest;
153 }
154
155 public void setValues(PortletRequest portletRequest) {
156 }
157
158 protected User user;
159 protected long defaultUserId;
160 protected boolean signedIn;
161 protected boolean checkGuest;
162 protected Boolean omniadmin;
163 protected Role ownerRole;
164
165 private static Log _log = LogFactoryUtil.getLog(
166 BasePermissionChecker.class);
167
168 }