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