|
23 | 23 |
|
24 | 24 | import org.apache.cloudstack.api.ApiCommandResourceType; |
25 | 25 | import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal; |
26 | | -import org.apache.logging.log4j.Logger; |
27 | 26 | import org.apache.logging.log4j.LogManager; |
| 27 | +import org.apache.logging.log4j.Logger; |
| 28 | +import org.apache.logging.log4j.ThreadContext; |
| 29 | +import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
28 | 30 |
|
29 | 31 | import com.cloud.exception.CloudAuthenticationException; |
30 | 32 | import com.cloud.projects.Project; |
31 | 33 | import com.cloud.user.Account; |
32 | 34 | import com.cloud.user.AccountService; |
33 | 35 | import com.cloud.user.User; |
34 | 36 | import com.cloud.utils.UuidUtils; |
| 37 | +import com.cloud.utils.component.ComponentContext; |
35 | 38 | import com.cloud.utils.db.EntityManager; |
36 | 39 | import com.cloud.utils.exception.CloudRuntimeException; |
37 | | -import org.apache.logging.log4j.ThreadContext; |
38 | 40 |
|
39 | 41 | /** |
40 | 42 | * CallContext records information about the environment the call is made. This |
@@ -69,11 +71,9 @@ protected Stack<CallContext> initialValue() { |
69 | 71 | private String apiName; |
70 | 72 |
|
71 | 73 | static EntityManager s_entityMgr; |
72 | | - static AccountService accountService; |
73 | 74 |
|
74 | | - public static void init(EntityManager entityMgr, AccountService accountService) { |
| 75 | + public static void init(EntityManager entityMgr) { |
75 | 76 | s_entityMgr = entityMgr; |
76 | | - CallContext.accountService = accountService; |
77 | 77 | } |
78 | 78 |
|
79 | 79 | protected CallContext() { |
@@ -140,7 +140,15 @@ public Account getCallingAccount() { |
140 | 140 |
|
141 | 141 | public boolean isCallingAccountRootAdmin() { |
142 | 142 | if (isAccountRootAdmin == null) { |
143 | | - accountService.isRootAdmin(getCallingAccount()); |
| 143 | + AccountService accountService; |
| 144 | + try { |
| 145 | + accountService = ComponentContext.getDelegateComponentOfType(AccountService.class); |
| 146 | + } catch (NoSuchBeanDefinitionException e) { |
| 147 | + LOGGER.warn("Falling back to account type check for isRootAdmin for account ID: {} as no AccountService bean found: {}", accountId, e.getMessage()); |
| 148 | + Account caller = getCallingAccount(); |
| 149 | + return caller != null && caller.getType() == Account.Type.ADMIN; |
| 150 | + } |
| 151 | + isAccountRootAdmin = accountService.isRootAdmin(getCallingAccount()); |
144 | 152 | } |
145 | 153 | return Boolean.TRUE.equals(isAccountRootAdmin); |
146 | 154 | } |
|
0 commit comments