001
014
015 package com.liferay.portlet.admin.util;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.model.RoleConstants;
020 import com.liferay.portal.model.User;
021 import com.liferay.portal.security.auth.CompanyThreadLocal;
022 import com.liferay.portal.service.RoleLocalServiceUtil;
023 import com.liferay.portal.service.UserLocalServiceUtil;
024 import com.liferay.portal.util.PortalInstances;
025 import com.liferay.portal.util.PropsValues;
026
027
030 public class OmniadminUtil {
031
032 public static boolean isOmniadmin(long userId) {
033 if (CompanyThreadLocal.getCompanyId() !=
034 PortalInstances.getDefaultCompanyId()) {
035
036 return false;
037 }
038
039 if (userId <= 0) {
040 return false;
041 }
042
043 try {
044 if (PropsValues.OMNIADMIN_USERS.length > 0) {
045 for (int i = 0; i < PropsValues.OMNIADMIN_USERS.length; i++) {
046 if (PropsValues.OMNIADMIN_USERS[i] == userId) {
047 User user = UserLocalServiceUtil.getUserById(userId);
048
049 if (user.getCompanyId() !=
050 PortalInstances.getDefaultCompanyId()) {
051
052 return false;
053 }
054
055 return true;
056 }
057 }
058
059 return false;
060 }
061 else {
062 User user = UserLocalServiceUtil.getUserById(userId);
063
064 if (user.getCompanyId() !=
065 PortalInstances.getDefaultCompanyId()) {
066
067 return false;
068 }
069
070 return RoleLocalServiceUtil.hasUserRole(
071 userId, user.getCompanyId(), RoleConstants.ADMINISTRATOR,
072 true);
073 }
074 }
075 catch (Exception e) {
076 _log.error(e);
077
078 return false;
079 }
080 }
081
082 private static Log _log = LogFactoryUtil.getLog(OmniadminUtil.class);
083
084 }