com.liferay.portlet.admin.util.OmniadminUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of portal-impl Show documentation
Show all versions of portal-impl Show documentation
Contains implementation for the portal services.
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portlet.admin.util;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.model.RoleConstants;
import com.liferay.portal.model.User;
import com.liferay.portal.security.auth.CompanyThreadLocal;
import com.liferay.portal.service.RoleLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.util.PortalInstances;
import com.liferay.portal.util.PropsValues;
/**
* Provides utility methods for determining if a user is a universal
* administrator. Universal administrators have administrator permissions in
* every company.
*
*
* A user can be made a universal administrator by adding their primary key to
* the list in portal.properties
under the key
* omniadmin.users. If this property is left blank, administrators
* of the default company will automatically be universal administrators.
*
*
* @author Brian Wing Shun Chan
*/
public class OmniadminUtil {
public static boolean isOmniadmin(long userId) {
try {
User user = UserLocalServiceUtil.fetchUser(userId);
if (user == null) {
return false;
}
return isOmniadmin(user);
}
catch (SystemException se) {
return false;
}
}
public static boolean isOmniadmin(User user) {
if (CompanyThreadLocal.getCompanyId() !=
PortalInstances.getDefaultCompanyId()) {
return false;
}
long userId = user.getUserId();
if (userId <= 0) {
return false;
}
try {
if (PropsValues.OMNIADMIN_USERS.length > 0) {
for (int i = 0; i < PropsValues.OMNIADMIN_USERS.length; i++) {
if (PropsValues.OMNIADMIN_USERS[i] == userId) {
if (user.getCompanyId() !=
PortalInstances.getDefaultCompanyId()) {
return false;
}
return true;
}
}
return false;
}
if (user.getCompanyId() !=
PortalInstances.getDefaultCompanyId()) {
return false;
}
return RoleLocalServiceUtil.hasUserRole(
userId, user.getCompanyId(), RoleConstants.ADMINISTRATOR, true);
}
catch (Exception e) {
_log.error(e);
return false;
}
}
private static Log _log = LogFactoryUtil.getLog(OmniadminUtil.class);
}