147147
148148public class NetworkModelImpl extends ManagerBase implements NetworkModel , Configurable {
149149 static final Logger s_logger = Logger .getLogger (NetworkModelImpl .class );
150+ public static final String UNABLE_TO_USE_NETWORK = "Unable to use network with id= %s, permission denied" ;
150151 @ Inject
151152 EntityManager _entityMgr ;
152153 @ Inject
@@ -1665,39 +1666,49 @@ public void checkCapabilityForProvider(Set<Provider> providers, Service service,
16651666 }
16661667
16671668 @ Override
1668- public void checkNetworkPermissions (Account caller , Network network ) {
1669- // dahn 20140310: I was thinking of making this an assert but
1670- // as we hardly ever test with asserts I think
1671- // we better make sure at runtime.
1672- if (network == null ) {
1673- throw new CloudRuntimeException ("cannot check permissions on (Network) <null>" );
1674- }
1675- // Perform account permission check
1676- if (network .getGuestType () != GuestType .Shared || network .getAclType () == ACLType .Account ) {
1677- AccountVO networkOwner = _accountDao .findById (network .getAccountId ());
1678- if (networkOwner == null )
1679- throw new PermissionDeniedException ("Unable to use network with id= " + ((NetworkVO )network ).getUuid () +
1680- ", network does not have an owner" );
1681- if (!Account .Type .PROJECT .equals (caller .getType ()) && Account .Type .PROJECT .equals (networkOwner .getType ())) {
1682- checkProjectNetworkPermissions (caller , networkOwner , network );
1669+ public final void checkNetworkPermissions (Account caller , Network network ) {
1670+ if (_accountMgr .isRootAdmin (caller .getAccountId ()) && Boolean .TRUE .equals (AdminIsAllowedToDeployAnywhere .value ())) {
1671+ if (s_logger .isDebugEnabled ()) {
1672+ s_logger .debug ("root admin is permitted to do stuff on every network" );
1673+ }
1674+ } else {
1675+ if (network == null ) {
1676+ throw new CloudRuntimeException ("cannot check permissions on (Network) <null>" );
1677+ }
1678+ s_logger .info (String .format ("Checking permission for account %s (%s) on network %s (%s)" , caller .getAccountName (), caller .getUuid (), network .getName (), network .getUuid ()));
1679+ if (network .getGuestType () != GuestType .Shared || network .getAclType () == ACLType .Account ) {
1680+ checkAccountNetworkPermissions (caller , network );
1681+
16831682 } else {
1684- List <NetworkVO > networkMap = _networksDao .listBy (caller .getId (), network .getId ());
1685- NetworkPermissionVO networkPermission = _networkPermissionDao .findByNetworkAndAccount (network .getId (), caller .getId ());
1686- if (CollectionUtils .isEmpty (networkMap ) && networkPermission == null ) {
1687- throw new PermissionDeniedException ("Unable to use network with id= " + ((NetworkVO )network ).getUuid () +
1688- ", permission denied" );
1689- }
1683+ checkDomainNetworkPermissions (caller , network );
16901684 }
1685+ }
1686+ }
16911687
1688+ private void checkAccountNetworkPermissions (Account caller , Network network ) {
1689+ AccountVO networkOwner = _accountDao .findById (network .getAccountId ());
1690+ if (networkOwner == null )
1691+ throw new PermissionDeniedException ("Unable to use network with id= " + ((NetworkVO ) network ).getUuid () +
1692+ ", network does not have an owner" );
1693+ if (!Account .Type .PROJECT .equals (caller .getType ()) && Account .Type .PROJECT .equals (networkOwner .getType ())) {
1694+ checkProjectNetworkPermissions (caller , networkOwner , network );
16921695 } else {
1693- if (!isNetworkAvailableInDomain (network .getId (), caller .getDomainId ())) {
1694- DomainVO callerDomain = _domainDao .findById (caller .getDomainId ());
1695- if (callerDomain == null ) {
1696- throw new CloudRuntimeException ("cannot check permission on account " + caller .getAccountName () + " whose domain does not exist" );
1697- }
1698- throw new PermissionDeniedException ("Shared network id=" + ((NetworkVO )network ).getUuid () + " is not available in domain id=" +
1699- callerDomain .getUuid ());
1696+ List <NetworkVO > networkMap = _networksDao .listBy (caller .getId (), network .getId ());
1697+ NetworkPermissionVO networkPermission = _networkPermissionDao .findByNetworkAndAccount (network .getId (), caller .getId ());
1698+ if (CollectionUtils .isEmpty (networkMap ) && networkPermission == null ) {
1699+ throw new PermissionDeniedException (String .format (UNABLE_TO_USE_NETWORK , ((NetworkVO ) network ).getUuid ()));
1700+ }
1701+ }
1702+ }
1703+
1704+ private void checkDomainNetworkPermissions (Account caller , Network network ) {
1705+ if (!isNetworkAvailableInDomain (network .getId (), caller .getDomainId ())) {
1706+ DomainVO callerDomain = _domainDao .findById (caller .getDomainId ());
1707+ if (callerDomain == null ) {
1708+ throw new CloudRuntimeException ("cannot check permission on account " + caller .getAccountName () + " whose domain does not exist" );
17001709 }
1710+ throw new PermissionDeniedException ("Shared network id=" + ((NetworkVO ) network ).getUuid () + " is not available in domain id=" +
1711+ callerDomain .getUuid ());
17011712 }
17021713 }
17031714
@@ -1710,13 +1721,11 @@ private void checkProjectNetworkPermissions(Account owner, Account networkOwner,
17101721 ProjectAccount projectAccountUser = _projectAccountDao .findByProjectIdUserId (project .getId (), user .getAccountId (), user .getId ());
17111722 if (projectAccountUser != null ) {
17121723 if (!_projectAccountDao .canUserAccessProjectAccount (user .getAccountId (), user .getId (), networkOwner .getId ())) {
1713- throw new PermissionDeniedException ("Unable to use network with id= " + ((NetworkVO )network ).getUuid () +
1714- ", permission denied" );
1724+ throw new PermissionDeniedException (String .format (UNABLE_TO_USE_NETWORK , ((NetworkVO )network ).getUuid ()));
17151725 }
17161726 } else {
17171727 if (!_projectAccountDao .canAccessProjectAccount (owner .getAccountId (), networkOwner .getId ())) {
1718- throw new PermissionDeniedException ("Unable to use network with id= " + ((NetworkVO ) network ).getUuid () +
1719- ", permission denied" );
1728+ throw new PermissionDeniedException (String .format (UNABLE_TO_USE_NETWORK , ((NetworkVO ) network ).getUuid ()));
17201729 }
17211730 }
17221731 }
@@ -2663,7 +2672,7 @@ public String getConfigComponentName() {
26632672
26642673 @ Override
26652674 public ConfigKey <?>[] getConfigKeys () {
2666- return new ConfigKey <?>[] {MACIdentifier };
2675+ return new ConfigKey <?>[] {MACIdentifier , AdminIsAllowedToDeployAnywhere };
26672676 }
26682677
26692678 @ Override
0 commit comments