|
88 | 88 | import com.cloud.offerings.NetworkOfferingVO; |
89 | 89 | import com.cloud.offerings.dao.NetworkOfferingDao; |
90 | 90 | import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; |
| 91 | +import com.cloud.projects.dao.ProjectAccountDao; |
91 | 92 | import com.cloud.user.Account; |
| 93 | +import com.cloud.user.AccountVO; |
92 | 94 | import com.cloud.user.DomainManager; |
93 | 95 | import com.cloud.user.dao.AccountDao; |
94 | 96 | import com.cloud.utils.component.AdapterBase; |
@@ -177,7 +179,8 @@ public void setNetworkElements(List<NetworkElement> _networkElements) { |
177 | 179 | PrivateIpDao _privateIpDao; |
178 | 180 | @Inject |
179 | 181 | UserIpv6AddressDao _ipv6Dao; |
180 | | - |
| 182 | + @Inject |
| 183 | + private ProjectAccountDao _projectAccountDao; |
181 | 184 |
|
182 | 185 | private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5); |
183 | 186 | static Long _privateOfferingId = null; |
@@ -1461,9 +1464,18 @@ public void checkCapabilityForProvider(Set<Provider> providers, Service service, |
1461 | 1464 | public void checkNetworkPermissions(Account owner, Network network) { |
1462 | 1465 | // Perform account permission check |
1463 | 1466 | 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 | + } |
1467 | 1479 | } |
1468 | 1480 | } else { |
1469 | 1481 | if (!isNetworkAvailableInDomain(network.getId(), owner.getDomainId())) { |
|
0 commit comments