1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.service.permission;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.model.Account;
22  import com.liferay.portal.model.Contact;
23  import com.liferay.portal.model.Organization;
24  import com.liferay.portal.model.User;
25  import com.liferay.portal.security.auth.PrincipalException;
26  import com.liferay.portal.security.permission.PermissionChecker;
27  import com.liferay.portal.service.UserLocalServiceUtil;
28  import com.liferay.portal.util.PortalUtil;
29  
30  /**
31   * <a href="CommonPermissionImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Charles May
34   */
35  public class CommonPermissionImpl implements CommonPermission {
36  
37      public void check(
38              PermissionChecker permissionChecker, long classNameId, long classPK,
39              String actionId)
40          throws PortalException, SystemException {
41  
42          String className = PortalUtil.getClassName(classNameId);
43  
44          check(permissionChecker, className, classPK, actionId);
45      }
46  
47      public void check(
48              PermissionChecker permissionChecker, String className, long classPK,
49              String actionId)
50          throws PortalException, SystemException {
51  
52          if (className.equals(Account.class.getName())) {
53          }
54          else if (className.equals(Contact.class.getName())) {
55              User user = UserLocalServiceUtil.getUserByContactId(classPK);
56  
57              UserPermissionUtil.check(
58                  permissionChecker, user.getUserId(), user.getOrganizationIds(),
59                  actionId);
60          }
61          else if (className.equals(Organization.class.getName())) {
62              OrganizationPermissionUtil.check(
63                  permissionChecker, classPK, actionId);
64          }
65          else {
66              if (_log.isWarnEnabled()) {
67                  _log.warn("Invalid class name " + className);
68              }
69  
70              throw new PrincipalException();
71          }
72      }
73  
74      private static Log _log = LogFactoryUtil.getLog(CommonPermissionImpl.class);
75  
76  }