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.blogs.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.portlet.PortletProvider;
019    import com.liferay.portal.kernel.portlet.PortletProviderUtil;
020    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
021    import com.liferay.portal.security.auth.PrincipalException;
022    import com.liferay.portal.security.permission.BaseResourcePermissionChecker;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portlet.blogs.model.BlogsEntry;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    @OSGiBeanProperties(property = {"resource.name=com.liferay.portlet.blogs"})
030    public class BlogsPermission extends BaseResourcePermissionChecker {
031    
032            public static final String RESOURCE_NAME = "com.liferay.portlet.blogs";
033    
034            public static void check(
035                            PermissionChecker permissionChecker, long groupId, String actionId)
036                    throws PortalException {
037    
038                    if (!contains(permissionChecker, groupId, actionId)) {
039                            throw new PrincipalException.MustHavePermission(
040                                    permissionChecker.getUserId(), RESOURCE_NAME, groupId,
041                                    actionId);
042                    }
043            }
044    
045            public static boolean contains(
046                    PermissionChecker permissionChecker, long classPK, String actionId) {
047    
048                    String portletId = PortletProviderUtil.getPortletId(
049                            BlogsEntry.class.getName(), PortletProvider.Action.EDIT);
050    
051                    return contains(
052                            permissionChecker, RESOURCE_NAME, portletId, classPK, actionId);
053            }
054    
055            @Override
056            public Boolean checkResource(
057                    PermissionChecker permissionChecker, long classPK, String actionId) {
058    
059                    return contains(permissionChecker, classPK, actionId);
060            }
061    
062    }