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.journal.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.journal.model.JournalArticle;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    @OSGiBeanProperties(property = {"resource.name=com.liferay.portlet.journal"})
030    public class JournalPermission extends BaseResourcePermissionChecker {
031    
032            public static final String RESOURCE_NAME = "com.liferay.portlet.journal";
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();
040                    }
041            }
042    
043            public static boolean contains(
044                    PermissionChecker permissionChecker, long classPK, String actionId) {
045    
046                    String portletId = PortletProviderUtil.getPortletId(
047                            JournalArticle.class.getName(), PortletProvider.Action.EDIT);
048    
049                    return contains(
050                            permissionChecker, RESOURCE_NAME, portletId, classPK, actionId);
051            }
052    
053            @Override
054            public Boolean checkResource(
055                    PermissionChecker permissionChecker, long classPK, String actionId) {
056    
057                    return contains(permissionChecker, classPK, actionId);
058            }
059    
060    }