001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.permission;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.Account;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.AccountLocalServiceUtil;
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();
037                    }
038            }
039    
040            @Override
041            public void check(
042                            PermissionChecker permissionChecker, long accountId,
043                            String actionId)
044                    throws PortalException, SystemException {
045    
046                    if (!contains(permissionChecker, accountId, actionId)) {
047                            throw new PrincipalException();
048                    }
049            }
050    
051            @Override
052            public boolean contains(
053                    PermissionChecker permissionChecker, Account account, String actionId) {
054    
055                    //long groupId = account.getGroupId();
056                    long groupId = 0;
057    
058                    return permissionChecker.hasPermission(
059                            groupId, Account.class.getName(), account.getAccountId(), actionId);
060            }
061    
062            @Override
063            public boolean contains(
064                            PermissionChecker permissionChecker, long accountId,
065                            String actionId)
066                    throws PortalException, SystemException {
067    
068                    Account account = AccountLocalServiceUtil.getAccount(accountId);
069    
070                    return contains(permissionChecker, account, actionId);
071            }
072    
073    }