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
041 public class OmniadminUtil {
042
043 public static boolean isOmniadmin(long userId) {
044 if (CompanyThreadLocal.getCompanyId() !=
045 PortalInstances.getDefaultCompanyId()) {
046
047 return false;
048 }
049
050 if (userId <= 0) {
051 return false;
052 }
053
054 try {
055 if (PropsValues.OMNIADMIN_USERS.length > 0) {
056 for (int i = 0; i < PropsValues.OMNIADMIN_USERS.length; i++) {
057 if (PropsValues.OMNIADMIN_USERS[i] == userId) {
058 User user = UserLocalServiceUtil.getUserById(userId);
059
060 if (user.getCompanyId() !=
061 PortalInstances.getDefaultCompanyId()) {
062
063 return false;
064 }
065
066 return true;
067 }
068 }
069
070 return false;
071 }
072 else {
073 User user = UserLocalServiceUtil.getUserById(userId);
074
075 if (user.getCompanyId() !=
076 PortalInstances.getDefaultCompanyId()) {
077
078 return false;
079 }
080
081 return RoleLocalServiceUtil.hasUserRole(
082 userId, user.getCompanyId(), RoleConstants.ADMINISTRATOR,
083 true);
084 }
085 }
086 catch (Exception e) {
087 _log.error(e);
088
089 return false;
090 }
091 }
092
093 private static Log _log = LogFactoryUtil.getLog(OmniadminUtil.class);
094
095 }