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.exception.PortalException;
018    import com.liferay.registry.collections.ServiceTrackerCollections;
019    import com.liferay.registry.collections.ServiceTrackerMap;
020    
021    /**
022     * @author Roberto D??az
023     */
024    public class ResourcePermissionCheckerUtil {
025    
026            public static Boolean containsResourcePermission(
027                            PermissionChecker permissionChecker, String className, long classPK,
028                            String actionId)
029                    throws PortalException {
030    
031                    ResourcePermissionChecker resourcePermissionChecker =
032                            _serviceTrackerMap.getService(className);
033    
034                    if (resourcePermissionChecker == null) {
035                            return null;
036                    }
037    
038                    Boolean resource = resourcePermissionChecker.checkResource(
039                            permissionChecker, classPK, actionId);
040    
041                    if (resource != null) {
042                            return resource.booleanValue();
043                    }
044    
045                    return null;
046            }
047    
048            private static final ServiceTrackerMap<String, ResourcePermissionChecker>
049                    _serviceTrackerMap = ServiceTrackerCollections.singleValueMap(
050                            ResourcePermissionChecker.class, "resource.name");
051    
052            static {
053                    _serviceTrackerMap.open();
054            }
055    
056    }