Skip to content

Commit abbe8ce

Browse files
Mice Xiachipchilders
authored andcommitted
Fix CLOUDSTACK-1894 User is not able to deploy VMs in a project[permission denied to access the guest network)
Signed-off-by: Mice Xia <mice_xia@tcloudcomputing.com>
1 parent 2c501d1 commit abbe8ce

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

‎server/src/com/cloud/network/NetworkModelImpl.java‎

100644100755
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@
8888
import com.cloud.offerings.NetworkOfferingVO;
8989
import com.cloud.offerings.dao.NetworkOfferingDao;
9090
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
91+
import com.cloud.projects.dao.ProjectAccountDao;
9192
import com.cloud.user.Account;
93+
import com.cloud.user.AccountVO;
9294
import com.cloud.user.DomainManager;
9395
import com.cloud.user.dao.AccountDao;
9496
import com.cloud.utils.component.AdapterBase;
@@ -177,7 +179,8 @@ public void setNetworkElements(List<NetworkElement> _networkElements) {
177179
PrivateIpDao _privateIpDao;
178180
@Inject
179181
UserIpv6AddressDao _ipv6Dao;
180-
182+
@Inject
183+
private ProjectAccountDao _projectAccountDao;
181184

182185
private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5);
183186
static Long _privateOfferingId = null;
@@ -1461,9 +1464,18 @@ public void checkCapabilityForProvider(Set<Provider> providers, Service service,
14611464
public void checkNetworkPermissions(Account owner, Network network) {
14621465
// Perform account permission check
14631466
if (network.getGuestType() != Network.GuestType.Shared) {
1464-
List<NetworkVO> networkMap = _networksDao.listBy(owner.getId(), network.getId());
1465-
if (networkMap == null || networkMap.isEmpty()) {
1466-
throw new PermissionDeniedException("Unable to use network with id= " + network.getId() + ", permission denied");
1467+
AccountVO networkOwner = _accountDao.findById(network.getAccountId());
1468+
if(networkOwner == null)
1469+
throw new PermissionDeniedException("Unable to use network with id= " + network.getId() + ", network does not have an owner");
1470+
if(owner.getType() != Account.ACCOUNT_TYPE_PROJECT && networkOwner.getType() == Account.ACCOUNT_TYPE_PROJECT){
1471+
if(!_projectAccountDao.canAccessProjectAccount(owner.getAccountId(), network.getAccountId())){
1472+
throw new PermissionDeniedException("Unable to use network with id= " + network.getId() + ", permission denied");
1473+
}
1474+
}else{
1475+
List<NetworkVO> networkMap = _networksDao.listBy(owner.getId(), network.getId());
1476+
if (networkMap == null || networkMap.isEmpty()) {
1477+
throw new PermissionDeniedException("Unable to use network with id= " + network.getId() + ", permission denied");
1478+
}
14671479
}
14681480
} else {
14691481
if (!isNetworkAvailableInDomain(network.getId(), owner.getDomainId())) {

0 commit comments

Comments
 (0)