Skip to content

Commit a4619c8

Browse files
committed
bug 9859: added missing permission checks to queryAsyncJobResult API
status 9859: resolved fixed Conflicts: server/src/com/cloud/async/AsyncJobManagerImpl.java
1 parent 28297b6 commit a4619c8

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎server/src/com/cloud/async/AsyncJobManagerImpl.java‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
import com.cloud.configuration.Config;
5151
import com.cloud.configuration.dao.ConfigurationDao;
5252
import com.cloud.exception.InvalidParameterValueException;
53+
import com.cloud.exception.PermissionDeniedException;
5354
import com.cloud.user.Account;
55+
import com.cloud.user.AccountManager;
5456
import com.cloud.user.UserContext;
5557
import com.cloud.user.dao.AccountDao;
5658
import com.cloud.utils.DateUtil;
@@ -80,7 +82,8 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
8082

8183
private AsyncJobExecutorContext _context;
8284
private SyncQueueManager _queueMgr;
83-
private ClusterManager _clusterMgr;
85+
private ClusterManager _clusterMgr;
86+
private AccountManager _accountMgr;
8487
private AccountDao _accountDao;
8588
private AsyncJobDao _jobDao;
8689
private long _jobExpireSeconds = 86400; // 1 day
@@ -273,10 +276,24 @@ public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObj
273276

274277
@Override
275278
public AsyncJobResult queryAsyncJobResult(QueryAsyncJobResultCmd cmd) {
279+
Account caller = UserContext.current().getCaller();
280+
276281
AsyncJobVO job = _jobDao.findById(cmd.getId());
277282
if (job == null) {
278283
throw new InvalidParameterValueException("Unable to find a job by id " + cmd.getId());
279284
}
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+
280297
return queryAsyncJobResult(cmd.getId());
281298
}
282299

@@ -658,6 +675,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
658675
}
659676

660677
_clusterMgr = locator.getManager(ClusterManager.class);
678+
679+
_accountMgr = locator.getManager(AccountManager.class);
661680

662681
_dispatcher = ApiDispatcher.getInstance();
663682

0 commit comments

Comments
 (0)