001 /** 002 * Copyright (c) 2000-present Liferay, Inc. All rights reserved. 003 * 004 * This library is free software; you can redistribute it and/or modify it under 005 * the terms of the GNU Lesser General Public License as published by the Free 006 * Software Foundation; either version 2.1 of the License, or (at your option) 007 * any later version. 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 */ 014 015 package com.liferay.portlet.admin.util; 016 017 import com.liferay.admin.kernel.util.Omniadmin; 018 import com.liferay.portal.model.User; 019 import com.liferay.registry.Registry; 020 import com.liferay.registry.RegistryUtil; 021 import com.liferay.registry.ServiceTracker; 022 023 /** 024 * Provides utility methods for determining if a user is a universal 025 * administrator. Universal administrators have administrator permissions in 026 * every company. 027 * 028 * <p> 029 * A user can be made a universal administrator by adding their primary key to 030 * the list in <code>portal.properties</code> under the key 031 * <code>omniadmin.users</key>. If this property is left blank, administrators 032 * of the default company will automatically be universal administrators. 033 * </p> 034 * 035 * @author Brian Wing Shun Chan 036 */ 037 public class OmniadminUtil { 038 039 public static boolean isOmniadmin(long userId) { 040 return getInstance().isOmniadmin(userId); 041 } 042 043 public static boolean isOmniadmin(User user) { 044 return getInstance().isOmniadmin(user); 045 } 046 047 private static Omniadmin getInstance() { 048 return _instance._serviceTracker.getService(); 049 } 050 051 private OmniadminUtil() { 052 Registry registry = RegistryUtil.getRegistry(); 053 054 _serviceTracker = registry.trackServices(Omniadmin.class); 055 056 _serviceTracker.open(); 057 } 058 059 private static final OmniadminUtil _instance = new OmniadminUtil(); 060 061 private final ServiceTracker<?, Omniadmin> _serviceTracker; 062 063 }