3232import javax .inject .Inject ;
3333import javax .naming .ConfigurationException ;
3434
35- import com .cloud .deploy .DeployDestination ;
36- import com .cloud .storage .ImageStoreUploadMonitorImpl ;
37- import com .cloud .utils .StringUtils ;
38- import com .cloud .utils .EncryptionUtil ;
39- import com .cloud .utils .DateUtil ;
40- import com .cloud .utils .Pair ;
41- import com .cloud .utils .EnumUtils ;
42- import com .google .common .base .Joiner ;
43- import com .google .gson .Gson ;
44- import com .google .gson .GsonBuilder ;
45-
46- import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
47- import org .apache .cloudstack .api .command .user .template .GetUploadParamsForTemplateCmd ;
48- import org .apache .cloudstack .framework .async .AsyncCallFuture ;
49- import org .apache .cloudstack .storage .command .TemplateOrVolumePostUploadCommand ;
50- import org .apache .cloudstack .storage .datastore .db .ImageStoreDao ;
51- import org .apache .cloudstack .storage .datastore .db .ImageStoreVO ;
52- import org .apache .cloudstack .utils .imagestore .ImageStoreUtil ;
53- import org .apache .commons .collections .CollectionUtils ;
54- import org .apache .commons .collections .MapUtils ;
55- import org .apache .log4j .Logger ;
5635import org .apache .cloudstack .acl .SecurityChecker .AccessType ;
5736import org .apache .cloudstack .api .ApiConstants ;
5837import org .apache .cloudstack .api .BaseListTemplateOrIsoPermissionsCmd ;
5938import org .apache .cloudstack .api .BaseUpdateTemplateOrIsoCmd ;
6039import org .apache .cloudstack .api .BaseUpdateTemplateOrIsoPermissionsCmd ;
6140import org .apache .cloudstack .api .command .user .iso .DeleteIsoCmd ;
6241import org .apache .cloudstack .api .command .user .iso .ExtractIsoCmd ;
42+ import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
6343import org .apache .cloudstack .api .command .user .iso .ListIsoPermissionsCmd ;
6444import org .apache .cloudstack .api .command .user .iso .RegisterIsoCmd ;
6545import org .apache .cloudstack .api .command .user .iso .UpdateIsoCmd ;
6848import org .apache .cloudstack .api .command .user .template .CreateTemplateCmd ;
6949import org .apache .cloudstack .api .command .user .template .DeleteTemplateCmd ;
7050import org .apache .cloudstack .api .command .user .template .ExtractTemplateCmd ;
51+ import org .apache .cloudstack .api .command .user .template .GetUploadParamsForTemplateCmd ;
7152import org .apache .cloudstack .api .command .user .template .ListTemplatePermissionsCmd ;
7253import org .apache .cloudstack .api .command .user .template .RegisterTemplateCmd ;
7354import org .apache .cloudstack .api .command .user .template .UpdateTemplateCmd ;
9475import org .apache .cloudstack .engine .subsystem .api .storage .VolumeDataFactory ;
9576import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
9677import org .apache .cloudstack .engine .subsystem .api .storage .ZoneScope ;
78+ import org .apache .cloudstack .framework .async .AsyncCallFuture ;
9779import org .apache .cloudstack .framework .config .ConfigKey ;
9880import org .apache .cloudstack .framework .config .Configurable ;
9981import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
10385import org .apache .cloudstack .storage .command .AttachCommand ;
10486import org .apache .cloudstack .storage .command .CommandResult ;
10587import org .apache .cloudstack .storage .command .DettachCommand ;
88+ import org .apache .cloudstack .storage .command .TemplateOrVolumePostUploadCommand ;
89+ import org .apache .cloudstack .storage .datastore .db .ImageStoreDao ;
90+ import org .apache .cloudstack .storage .datastore .db .ImageStoreVO ;
10691import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
10792import org .apache .cloudstack .storage .datastore .db .SnapshotDataStoreDao ;
10893import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
10994import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreDao ;
11095import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreVO ;
11196import org .apache .cloudstack .storage .image .datastore .ImageStoreEntity ;
11297import org .apache .cloudstack .storage .to .TemplateObjectTO ;
98+ import org .apache .cloudstack .utils .imagestore .ImageStoreUtil ;
99+ import org .apache .commons .collections .CollectionUtils ;
100+ import org .apache .commons .collections .MapUtils ;
101+ import org .apache .log4j .Logger ;
102+ import org .joda .time .DateTime ;
103+ import org .joda .time .DateTimeZone ;
113104
114105import com .cloud .agent .AgentManager ;
115106import com .cloud .agent .api .Answer ;
128119import com .cloud .dc .DataCenter ;
129120import com .cloud .dc .DataCenterVO ;
130121import com .cloud .dc .dao .DataCenterDao ;
122+ import com .cloud .deploy .DeployDestination ;
131123import com .cloud .domain .Domain ;
132124import com .cloud .domain .dao .DomainDao ;
133125import com .cloud .event .ActionEvent ;
147139import com .cloud .projects .ProjectManager ;
148140import com .cloud .storage .DataStoreRole ;
149141import com .cloud .storage .GuestOSVO ;
142+ import com .cloud .storage .ImageStoreUploadMonitorImpl ;
150143import com .cloud .storage .LaunchPermissionVO ;
151144import com .cloud .storage .Snapshot ;
152145import com .cloud .storage .SnapshotVO ;
185178import com .cloud .user .ResourceLimitService ;
186179import com .cloud .user .dao .AccountDao ;
187180import com .cloud .uservm .UserVm ;
181+ import com .cloud .utils .DateUtil ;
182+ import com .cloud .utils .EncryptionUtil ;
183+ import com .cloud .utils .EnumUtils ;
184+ import com .cloud .utils .Pair ;
185+ import com .cloud .utils .StringUtils ;
188186import com .cloud .utils .component .AdapterBase ;
189187import com .cloud .utils .component .ManagerBase ;
190188import com .cloud .utils .concurrency .NamedThreadFactory ;
201199import com .cloud .vm .VirtualMachineProfile ;
202200import com .cloud .vm .dao .UserVmDao ;
203201import com .cloud .vm .dao .VMInstanceDao ;
204-
205- import org . joda . time . DateTime ;
206- import org . joda . time . DateTimeZone ;
202+ import com . google . common . base . Joiner ;
203+ import com . google . gson . Gson ;
204+ import com . google . gson . GsonBuilder ;
207205
208206public class TemplateManagerImpl extends ManagerBase implements TemplateManager , TemplateApiService , Configurable {
209207 private final static Logger s_logger = Logger .getLogger (TemplateManagerImpl .class );
@@ -1541,14 +1539,23 @@ public boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissions
15411539 //Derive the domain id from the template owner as updateTemplatePermissions is not cross domain operation
15421540 Account owner = _accountMgr .getAccount (ownerId );
15431541 final Domain domain = _domainDao .findById (owner .getDomainId ());
1542+ final boolean isCallerRootAdmin = _accountMgr .isRootAdmin (caller .getAccountId ());
15441543 if ("add" .equalsIgnoreCase (operation )) {
15451544 final List <String > accountNamesFinal = accountNames ;
15461545 final List <Long > accountIds = new ArrayList <Long >();
15471546 Transaction .execute (new TransactionCallbackNoReturn () {
15481547 @ Override
15491548 public void doInTransactionWithoutResult (TransactionStatus status ) {
15501549 for (String accountName : accountNamesFinal ) {
1551- Account permittedAccount = _accountDao .findActiveAccount (accountName , domain .getId ());
1550+ Account permittedAccount = null ;
1551+ if (isCallerRootAdmin ) {
1552+ List <AccountVO > accountsWthName = _accountDao .findAccountsLike (accountName );
1553+ if (accountsWthName .size () > 0 ) {
1554+ permittedAccount = accountsWthName .get (0 );
1555+ }
1556+ } else {
1557+ permittedAccount = _accountDao .findActiveAccount (accountName , domain .getId ());
1558+ }
15521559 if (permittedAccount != null ) {
15531560 if (permittedAccount .getId () == caller .getId ()) {
15541561 continue ; // don't grant permission to the template
@@ -1563,8 +1570,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
15631570 } else {
15641571 throw new InvalidParameterValueException ("Unable to grant a launch permission to account " + accountName + " in domain id=" +
15651572 domain .getUuid () + ", account not found. " + "No permissions updated, please verify the account names and retry." );
1566- }
1567- }
1573+ }
1574+ }
15681575 }
15691576 });
15701577
@@ -1578,7 +1585,15 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
15781585 } else if ("remove" .equalsIgnoreCase (operation )) {
15791586 List <Long > accountIds = new ArrayList <Long >();
15801587 for (String accountName : accountNames ) {
1581- Account permittedAccount = _accountDao .findActiveAccount (accountName , domain .getId ());
1588+ Account permittedAccount = null ;
1589+ if (isCallerRootAdmin ) {
1590+ List <AccountVO > accountsWthName = _accountDao .findAccountsLike (accountName );
1591+ if (accountsWthName .size () > 0 ) {
1592+ permittedAccount = accountsWthName .get (0 );
1593+ }
1594+ } else {
1595+ permittedAccount = _accountDao .findActiveAccount (accountName , domain .getId ());
1596+ }
15821597 if (permittedAccount != null ) {
15831598 accountIds .add (permittedAccount .getId ());
15841599 }
0 commit comments