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.messageboards.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.messageboards.model.MBMessage;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    @OSGiBeanProperties(
030            property = {"resource.name=com.liferay.portlet.messageboards"}
031    )
032    public class MBPermission extends BaseResourcePermissionChecker {
033    
034            public static final String RESOURCE_NAME =
035                    "com.liferay.portlet.messageboards";
036    
037            public static void check(
038                            PermissionChecker permissionChecker, long groupId, String actionId)
039                    throws PortalException {
040    
041                    if (!contains(permissionChecker, groupId, actionId)) {
042                            throw new PrincipalException.MustHavePermission(
043                                    permissionChecker, RESOURCE_NAME, groupId, actionId);
044                    }
045            }
046    
047            public static boolean contains(
048                    PermissionChecker permissionChecker, long classPK, String actionId) {
049    
050                    String portletId = PortletProviderUtil.getPortletId(
051                            MBMessage.class.getName(), PortletProvider.Action.EDIT);
052    
053                    return contains(
054                            permissionChecker, RESOURCE_NAME, portletId, classPK, actionId);
055            }
056    
057            @Override
058            public Boolean checkResource(
059                    PermissionChecker permissionChecker, long classPK, String actionId) {
060    
061                    return contains(permissionChecker, classPK, actionId);
062            }
063    
064    }