|
25 | 25 | import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd; |
26 | 26 | import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd; |
27 | 27 | import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd; |
28 | | -import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; |
29 | 28 | import org.apache.cloudstack.api.command.user.template.ExtractTemplateCmd; |
| 29 | +import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; |
30 | 30 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
31 | 31 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; |
32 | 32 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
|
46 | 46 | import com.cloud.host.dao.HostDao; |
47 | 47 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
48 | 48 | import com.cloud.org.Grouping; |
| 49 | +import com.cloud.projects.ProjectManager; |
49 | 50 | import com.cloud.server.ConfigurationServer; |
50 | 51 | import com.cloud.storage.GuestOS; |
51 | 52 | import com.cloud.storage.Storage.ImageFormat; |
@@ -86,8 +87,9 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat |
86 | 87 | protected @Inject ResourceLimitService _resourceLimitMgr; |
87 | 88 | protected @Inject DataStoreManager storeMgr; |
88 | 89 | @Inject TemplateManager templateMgr; |
89 | | - @Inject ConfigurationServer _configServer; |
90 | | - |
| 90 | + @Inject ConfigurationServer _configServer; |
| 91 | + @Inject ProjectManager _projectMgr; |
| 92 | + |
91 | 93 | @Override |
92 | 94 | public boolean stop() { |
93 | 95 | return true; |
@@ -289,9 +291,16 @@ private Long accountAndUserValidation(Account account, long userId, UserVmVO vmI |
289 | 291 |
|
290 | 292 | if ((template != null) |
291 | 293 | && (!template.isPublicTemplate() && (account.getId() != template.getAccountId()) && (template.getTemplateType() != TemplateType.PERHOST))) { |
292 | | - throw new PermissionDeniedException(msg + ". Permission denied."); |
| 294 | + //special handling for the project case |
| 295 | + Account owner = _accountMgr.getAccount(template.getAccountId()); |
| 296 | + if (owner.getType() == Account.ACCOUNT_TYPE_PROJECT) { |
| 297 | + if (!_projectMgr.canAccessProjectAccount(account, owner.getId())) { |
| 298 | + throw new PermissionDeniedException(msg + ". Permission denied. The caller can't access project's template"); |
| 299 | + } |
| 300 | + } else { |
| 301 | + throw new PermissionDeniedException(msg + ". Permission denied."); |
| 302 | + } |
293 | 303 | } |
294 | | - |
295 | 304 | } else { |
296 | 305 | if ((vmInstanceCheck != null) && !_domainDao.isChildDomain(account.getDomainId(), vmInstanceCheck.getDomainId())) { |
297 | 306 | throw new PermissionDeniedException(msg + ". Permission denied."); |
|
0 commit comments