1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.admin.util;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.model.RoleConstants;
20  import com.liferay.portal.model.User;
21  import com.liferay.portal.security.auth.CompanyThreadLocal;
22  import com.liferay.portal.service.RoleLocalServiceUtil;
23  import com.liferay.portal.service.UserLocalServiceUtil;
24  import com.liferay.portal.util.PortalInstances;
25  import com.liferay.portal.util.PropsValues;
26  
27  /**
28   * <a href="OmniadminUtil.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class OmniadminUtil {
33  
34      public static boolean isOmniadmin(long userId) {
35          if (CompanyThreadLocal.getCompanyId() !=
36                  PortalInstances.getDefaultCompanyId()) {
37  
38              return false;
39          }
40  
41          if (userId <= 0) {
42              return false;
43          }
44  
45          try {
46              if (PropsValues.OMNIADMIN_USERS.length > 0) {
47                  for (int i = 0; i < PropsValues.OMNIADMIN_USERS.length; i++) {
48                      if (PropsValues.OMNIADMIN_USERS[i] == userId) {
49                          User user = UserLocalServiceUtil.getUserById(userId);
50  
51                          if (user.getCompanyId() !=
52                                  PortalInstances.getDefaultCompanyId()) {
53  
54                              return false;
55                          }
56  
57                          return true;
58                      }
59                  }
60  
61                  return false;
62              }
63              else {
64                  User user = UserLocalServiceUtil.getUserById(userId);
65  
66                  if (user.getCompanyId() !=
67                          PortalInstances.getDefaultCompanyId()) {
68  
69                      return false;
70                  }
71  
72                  return RoleLocalServiceUtil.hasUserRole(
73                      userId, user.getCompanyId(), RoleConstants.ADMINISTRATOR,
74                      true);
75              }
76          }
77          catch (Exception e) {
78              _log.error(e);
79  
80              return false;
81          }
82      }
83  
84      private static Log _log = LogFactoryUtil.getLog(OmniadminUtil.class);
85  
86  }