001
014
015 package com.liferay.portlet.admin.util;
016
017 import com.liferay.portal.kernel.exception.SystemException;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
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.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 try {
045 User user = UserLocalServiceUtil.fetchUser(userId);
046
047 if (user == null) {
048 return false;
049 }
050
051 return isOmniadmin(user);
052 }
053 catch (SystemException se) {
054 return false;
055 }
056 }
057
058 public static boolean isOmniadmin(User user) {
059 long userId = user.getUserId();
060
061 if (userId <= 0) {
062 return false;
063 }
064
065 try {
066 if (PropsValues.OMNIADMIN_USERS.length > 0) {
067 for (int i = 0; i < PropsValues.OMNIADMIN_USERS.length; i++) {
068 if (PropsValues.OMNIADMIN_USERS[i] == userId) {
069 if (user.getCompanyId() !=
070 PortalInstances.getDefaultCompanyId()) {
071
072 return false;
073 }
074
075 return true;
076 }
077 }
078
079 return false;
080 }
081
082 if (user.getCompanyId() != PortalInstances.getDefaultCompanyId()) {
083 return false;
084 }
085
086 return RoleLocalServiceUtil.hasUserRole(
087 userId, user.getCompanyId(), RoleConstants.ADMINISTRATOR, true);
088 }
089 catch (Exception e) {
090 _log.error(e);
091
092 return false;
093 }
094 }
095
096 private static Log _log = LogFactoryUtil.getLog(OmniadminUtil.class);
097
098 }