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.portal.security.permission;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
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     * @author Charles May
025     * @author Brian Wing Shun Chan
026     */
027    public class PermissionCheckerFactoryUtil {
028    
029            public static PermissionChecker create(User user) throws Exception {
030                    return getPermissionCheckerFactory().create(user);
031            }
032    
033            /**
034             * @deprecated As of 6.2.0, replaced by {@link #create(User)}
035             */
036            @Deprecated
037            public static PermissionChecker create(User user, boolean checkGuest)
038                    throws Exception {
039    
040                    return getPermissionCheckerFactory().create(user);
041            }
042    
043            public static PermissionCheckerFactory getPermissionCheckerFactory() {
044                    PortalRuntimePermission.checkGetBeanProperty(
045                            PermissionCheckerFactoryUtil.class);
046    
047                    return _instance._serviceTracker.getService();
048            }
049    
050            private PermissionCheckerFactoryUtil() {
051                    Registry registry = RegistryUtil.getRegistry();
052    
053                    _serviceTracker = registry.trackServices(
054                            PermissionCheckerFactory.class);
055    
056                    _serviceTracker.open();
057            }
058    
059            private static final PermissionCheckerFactoryUtil _instance =
060                    new PermissionCheckerFactoryUtil();
061    
062            private final ServiceTracker<?, PermissionCheckerFactory> _serviceTracker;
063    
064    }