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.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.model.Account;
019    import com.liferay.portal.kernel.security.auth.PrincipalException;
020    import com.liferay.portal.kernel.security.permission.PermissionChecker;
021    import com.liferay.portal.kernel.service.AccountLocalServiceUtil;
022    import com.liferay.portal.kernel.service.permission.AccountPermission;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class AccountPermissionImpl implements AccountPermission {
028    
029            @Override
030            public void check(
031                            PermissionChecker permissionChecker, Account account,
032                            String actionId)
033                    throws PortalException {
034    
035                    if (!contains(permissionChecker, account, actionId)) {
036                            throw new PrincipalException.MustHavePermission(
037                                    permissionChecker, Account.class.getName(),
038                                    account.getAccountId(), actionId);
039                    }
040            }
041    
042            @Override
043            public void check(
044                            PermissionChecker permissionChecker, long accountId,
045                            String actionId)
046                    throws PortalException {
047    
048                    if (!contains(permissionChecker, accountId, actionId)) {
049                            throw new PrincipalException.MustHavePermission(
050                                    permissionChecker, Account.class.getName(), accountId,
051                                    actionId);
052                    }
053            }
054    
055            @Override
056            public boolean contains(
057                    PermissionChecker permissionChecker, Account account, String actionId) {
058    
059                    //long groupId = account.getGroupId();
060                    long groupId = 0;
061    
062                    return permissionChecker.hasPermission(
063                            groupId, Account.class.getName(), account.getAccountId(), actionId);
064            }
065    
066            @Override
067            public boolean contains(
068                            PermissionChecker permissionChecker, long accountId,
069                            String actionId)
070                    throws PortalException {
071    
072                    Account account = AccountLocalServiceUtil.getAccount(accountId);
073    
074                    return contains(permissionChecker, account, actionId);
075            }
076    
077    }