|
50 | 50 | import com.cloud.configuration.Config; |
51 | 51 | import com.cloud.configuration.dao.ConfigurationDao; |
52 | 52 | import com.cloud.exception.InvalidParameterValueException; |
| 53 | +import com.cloud.exception.PermissionDeniedException; |
53 | 54 | import com.cloud.user.Account; |
| 55 | +import com.cloud.user.AccountManager; |
54 | 56 | import com.cloud.user.UserContext; |
55 | 57 | import com.cloud.user.dao.AccountDao; |
56 | 58 | import com.cloud.utils.DateUtil; |
@@ -80,7 +82,8 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe |
80 | 82 |
|
81 | 83 | private AsyncJobExecutorContext _context; |
82 | 84 | private SyncQueueManager _queueMgr; |
83 | | - private ClusterManager _clusterMgr; |
| 85 | + private ClusterManager _clusterMgr; |
| 86 | + private AccountManager _accountMgr; |
84 | 87 | private AccountDao _accountDao; |
85 | 88 | private AsyncJobDao _jobDao; |
86 | 89 | private long _jobExpireSeconds = 86400; // 1 day |
@@ -273,10 +276,24 @@ public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObj |
273 | 276 |
|
274 | 277 | @Override |
275 | 278 | public AsyncJobResult queryAsyncJobResult(QueryAsyncJobResultCmd cmd) { |
| 279 | + Account caller = UserContext.current().getCaller(); |
| 280 | + |
276 | 281 | AsyncJobVO job = _jobDao.findById(cmd.getId()); |
277 | 282 | if (job == null) { |
278 | 283 | throw new InvalidParameterValueException("Unable to find a job by id " + cmd.getId()); |
279 | 284 | } |
| 285 | + Account jobOwner = _accountMgr.getAccount(job.getAccountId()); |
| 286 | + |
| 287 | + //check permissions |
| 288 | + if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) { |
| 289 | + //regular user can see only jobs he owns |
| 290 | + if (caller.getId() != jobOwner.getId()) { |
| 291 | + throw new PermissionDeniedException("Account " + caller + " is not authorized to see job id=" + job.getId()); |
| 292 | + } |
| 293 | + } else if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) { |
| 294 | + _accountMgr.checkAccess(caller, jobOwner); |
| 295 | + } |
| 296 | + |
280 | 297 | return queryAsyncJobResult(cmd.getId()); |
281 | 298 | } |
282 | 299 |
|
@@ -658,6 +675,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu |
658 | 675 | } |
659 | 676 |
|
660 | 677 | _clusterMgr = locator.getManager(ClusterManager.class); |
| 678 | + |
| 679 | + _accountMgr = locator.getManager(AccountManager.class); |
661 | 680 |
|
662 | 681 | _dispatcher = ApiDispatcher.getInstance(); |
663 | 682 |
|
|
0 commit comments