001    /**
002     * Copyright (c) 2000-2010 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.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.model.Account;
022    import com.liferay.portal.model.Contact;
023    import com.liferay.portal.model.Organization;
024    import com.liferay.portal.model.User;
025    import com.liferay.portal.security.auth.PrincipalException;
026    import com.liferay.portal.security.permission.PermissionChecker;
027    import com.liferay.portal.service.UserLocalServiceUtil;
028    import com.liferay.portal.util.PortalUtil;
029    
030    /**
031     * @author Charles May
032     */
033    public class CommonPermissionImpl implements CommonPermission {
034    
035            public void check(
036                            PermissionChecker permissionChecker, long classNameId, long classPK,
037                            String actionId)
038                    throws PortalException, SystemException {
039    
040                    String className = PortalUtil.getClassName(classNameId);
041    
042                    check(permissionChecker, className, classPK, actionId);
043            }
044    
045            public void check(
046                            PermissionChecker permissionChecker, String className, long classPK,
047                            String actionId)
048                    throws PortalException, SystemException {
049    
050                    if (className.equals(Account.class.getName())) {
051                    }
052                    else if (className.equals(Contact.class.getName())) {
053                            User user = UserLocalServiceUtil.getUserByContactId(classPK);
054    
055                            UserPermissionUtil.check(
056                                    permissionChecker, user.getUserId(), user.getOrganizationIds(),
057                                    actionId);
058                    }
059                    else if (className.equals(Organization.class.getName())) {
060                            OrganizationPermissionUtil.check(
061                                    permissionChecker, classPK, actionId);
062                    }
063                    else {
064                            if (_log.isWarnEnabled()) {
065                                    _log.warn("Invalid class name " + className);
066                            }
067    
068                            throw new PrincipalException();
069                    }
070            }
071    
072            private static Log _log = LogFactoryUtil.getLog(CommonPermissionImpl.class);
073    
074    }