2323
2424import org .apache .cloudstack .api .ApiCommandResourceType ;
2525import org .apache .cloudstack .managed .threadlocal .ManagedThreadLocal ;
26- import org .apache .logging .log4j .Logger ;
2726import 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 ;
2830
2931import com .cloud .exception .CloudAuthenticationException ;
3032import com .cloud .projects .Project ;
3133import com .cloud .user .Account ;
34+ import com .cloud .user .AccountService ;
3235import com .cloud .user .User ;
3336import com .cloud .utils .UuidUtils ;
37+ import com .cloud .utils .component .ComponentContext ;
3438import com .cloud .utils .db .EntityManager ;
3539import com .cloud .utils .exception .CloudRuntimeException ;
36- import org .apache .logging .log4j .ThreadContext ;
3740
3841/**
3942 * CallContext records information about the environment the call is made. This
@@ -53,6 +56,7 @@ protected Stack<CallContext> initialValue() {
5356 private String contextId ;
5457 private Account account ;
5558 private long accountId ;
59+ private Boolean isAccountRootAdmin = null ;
5660 private long startEventId = 0 ;
5761 private String eventDescription ;
5862 private String eventDetails ;
@@ -134,6 +138,21 @@ public Account getCallingAccount() {
134138 return account ;
135139 }
136140
141+ public boolean isCallingAccountRootAdmin () {
142+ if (isAccountRootAdmin == null ) {
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 ());
152+ }
153+ return Boolean .TRUE .equals (isAccountRootAdmin );
154+ }
155+
137156 public static CallContext current () {
138157 CallContext context = s_currentContext .get ();
139158
0 commit comments