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.portal.model.User;
018    import com.liferay.registry.Registry;
019    import com.liferay.registry.RegistryUtil;
020    import com.liferay.registry.ServiceTracker;
021    
022    /**
023     * Provides utility methods for determining if a user is a universal
024     * administrator. Universal administrators have administrator permissions in
025     * every company.
026     *
027     * <p>
028     * A user can be made a universal administrator by adding their primary key to
029     * the list in <code>portal.properties</code> under the key
030     * <code>omniadmin.users</key>. If this property is left blank, administrators
031     * of the default company will automatically be universal administrators.
032     * </p>
033     *
034     * @author Brian Wing Shun Chan
035     */
036    public class OmniadminUtil {
037    
038            public static boolean isOmniadmin(long userId) {
039                    return getInstance().isOmniadmin(userId);
040            }
041    
042            public static boolean isOmniadmin(User user) {
043                    return getInstance().isOmniadmin(user);
044            }
045    
046            private static Omniadmin getInstance() {
047                    return _instance._serviceTracker.getService();
048            }
049    
050            private OmniadminUtil() {
051                    Registry registry = RegistryUtil.getRegistry();
052    
053                    _serviceTracker = registry.trackServices(Omniadmin.class);
054    
055                    _serviceTracker.open();
056            }
057    
058            private static final OmniadminUtil _instance = new OmniadminUtil();
059    
060            private final ServiceTracker<?, Omniadmin> _serviceTracker;
061    
062    }