|
29 | 29 | import com.cloud.exception.ConcurrentOperationException; |
30 | 30 | import com.cloud.exception.InsufficientCapacityException; |
31 | 31 | import com.cloud.exception.ResourceUnavailableException; |
| 32 | +import com.cloud.user.Account; |
| 33 | +import com.cloud.user.User; |
32 | 34 |
|
33 | 35 | public class AsyncJobExecutionContext { |
34 | 36 | private static final Logger s_logger = Logger.getLogger(AsyncJobExecutionContext.class); |
@@ -167,10 +169,15 @@ public void completeJobAndJoin(JobInfo.Status joinStatus, String joinResult) { |
167 | 169 | public static AsyncJobExecutionContext getCurrentExecutionContext() { |
168 | 170 | AsyncJobExecutionContext context = s_currentExectionContext.get(); |
169 | 171 | if (context == null) { |
170 | | - // TODO, this has security implicitions |
| 172 | + // TODO, this has security implications, operations carried from API layer should always |
| 173 | + // set its context, otherwise, the fall-back here will use system security context |
| 174 | + // |
171 | 175 | s_logger.warn("Job is executed without a context, setup psudo job for the executing thread"); |
172 | | - context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(), |
173 | | - CallContext.current().getCallingUserId()); |
| 176 | + if (CallContext.current() != null) |
| 177 | + context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(), |
| 178 | + CallContext.current().getCallingUserId()); |
| 179 | + else |
| 180 | + context = registerPseudoExecutionContext(Account.ACCOUNT_ID_SYSTEM, User.UID_SYSTEM); |
174 | 181 | } |
175 | 182 | return context; |
176 | 183 | } |
|
0 commit comments