Skip to content

Commit b9ec1de

Browse files
author
Sina Kashipazha
committed
Move settings to domain.
1 parent 5e2372f commit b9ec1de

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
*/
8989
public interface QueryService {
9090

91+
static final String RestrictPublicTemplateAccessToDomainCK = "restrict.public.template.access.to.domain";
92+
9193
// Config keys
9294
ConfigKey<Boolean> AllowUserViewDestroyedVM = new ConfigKey<>("Advanced", Boolean.class, "allow.user.view.destroyed.vm", "false",
9395
"Determines whether users can view their destroyed or expunging vm ", true, ConfigKey.Scope.Account);
@@ -109,6 +111,9 @@ public interface QueryService {
109111
"allow.user.view.all.domain.accounts", "false",
110112
"Determines whether users can view all user accounts within the same domain", true, ConfigKey.Scope.Domain);
111113

114+
static final ConfigKey<Boolean> RestrictPublicTemplateAccessToDomain = new ConfigKey<>("Advanced", Boolean.class, RestrictPublicTemplateAccessToDomainCK, "false",
115+
"If true, other domains public templates will not visible in this domain.", true, ConfigKey.Scope.Domain);
116+
112117
ListResponse<UserResponse> searchForUsers(ListUsersCmd cmd) throws PermissionDeniedException;
113118

114119
ListResponse<UserResponse> searchForUsers(Long domainId, boolean recursive) throws PermissionDeniedException;

engine/components-api/src/main/java/com/cloud/template/TemplateManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@
4141
public interface TemplateManager {
4242
static final String AllowPublicUserTemplatesCK = "allow.public.user.templates";
4343
static final String TemplatePreloaderPoolSizeCK = "template.preloader.pool.size";
44-
static final String RestrictPublicTemplateAccessToDomainCK = "restrict.public.template.access.to.domain";
4544

4645
static final ConfigKey<Boolean> AllowPublicUserTemplates = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowPublicUserTemplatesCK, "true",
4746
"If false, users will not be able to create public templates.", true, ConfigKey.Scope.Account);
4847

4948
static final ConfigKey<Integer> TemplatePreloaderPoolSize = new ConfigKey<Integer>("Advanced", Integer.class, TemplatePreloaderPoolSizeCK, "8",
5049
"Size of the TemplateManager threadpool", false, ConfigKey.Scope.Global);
5150

52-
static final ConfigKey<Boolean> RestrictPublicTemplateAccessToDomain = new ConfigKey<>("Advanced", Boolean.class, RestrictPublicTemplateAccessToDomainCK, "false",
53-
"If true, the public template wouldn't share between domains", true, ConfigKey.Scope.Global);
51+
5452

5553
static final String VMWARE_TOOLS_ISO = "vmware-tools.iso";
5654
static final String XS_TOOLS_ISO = "xs-tools.iso";

server/src/main/java/com/cloud/acl/DomainChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.cloudstack.acl.SecurityChecker;
2929
import org.apache.cloudstack.affinity.AffinityGroup;
3030
import org.apache.cloudstack.context.CallContext;
31+
import org.apache.cloudstack.query.QueryService;
3132
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
3233
import org.apache.log4j.Logger;
3334
import org.springframework.stereotype.Component;
@@ -55,7 +56,6 @@
5556
import com.cloud.service.dao.ServiceOfferingDetailsDao;
5657
import com.cloud.storage.LaunchPermissionVO;
5758
import com.cloud.storage.dao.LaunchPermissionDao;
58-
import com.cloud.template.TemplateManager;
5959
import com.cloud.template.VirtualMachineTemplate;
6060
import com.cloud.user.Account;
6161
import com.cloud.user.AccountService;
@@ -168,7 +168,7 @@ public boolean checkAccess(Account caller, ControlledEntity entity, AccessType a
168168
throw new PermissionDeniedException("Domain Admin and regular users can modify only their own Public templates");
169169
}
170170
}
171-
} else if (TemplateManager.RestrictPublicTemplateAccessToDomain.value() && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { // public template can be used by other accounts in the same domain or in sub-domains, and domain admin of parent domains
171+
} else if (QueryService.RestrictPublicTemplateAccessToDomain.valueIn(caller.getDomainId()) && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { // public template can be used by other accounts in the same domain or in sub-domains, and domain admin of parent domains
172172
if (caller.getDomainId() != owner.getDomainId() && !_domainDao.isChildDomain(owner.getDomainId(), caller.getDomainId())) {
173173
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_PROJECT) {
174174
throw new PermissionDeniedException(caller + "is not allowed to access the template " + template);

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@
221221
import com.cloud.storage.dao.VMTemplateDetailsDao;
222222
import com.cloud.tags.ResourceTagVO;
223223
import com.cloud.tags.dao.ResourceTagDao;
224-
import com.cloud.template.TemplateManager;
225224
import com.cloud.template.VirtualMachineTemplate.State;
226225
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
227226
import com.cloud.user.Account;
@@ -3486,7 +3485,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
34863485
}
34873486
SearchCriteria<TemplateJoinVO> sc = sb.create();
34883487

3489-
boolean restrictPublicTemplatesToDomain = TemplateManager.RestrictPublicTemplateAccessToDomain.value();
3488+
boolean restrictPublicTemplatesToDomain = QueryService.RestrictPublicTemplateAccessToDomain.valueIn(caller.getDomainId());
34903489

34913490
// verify templateId parameter and specially handle it
34923491
if (templateId != null) {
@@ -4253,6 +4252,6 @@ public String getConfigComponentName() {
42534252

42544253
@Override
42554254
public ConfigKey<?>[] getConfigKeys() {
4256-
return new ConfigKey<?>[] {AllowUserViewDestroyedVM, UserVMDeniedDetails, UserVMReadOnlyDetails, SortKeyAscending, AllowUserViewAllDomainAccounts};
4255+
return new ConfigKey<?>[] {AllowUserViewDestroyedVM, UserVMDeniedDetails, UserVMReadOnlyDetails, SortKeyAscending, AllowUserViewAllDomainAccounts, RestrictPublicTemplateAccessToDomain};
42574256
}
42584257
}

server/src/main/java/com/cloud/template/TemplateManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@ public String getConfigComponentName() {
22272227

22282228
@Override
22292229
public ConfigKey<?>[] getConfigKeys() {
2230-
return new ConfigKey<?>[] {AllowPublicUserTemplates, TemplatePreloaderPoolSize, RestrictPublicTemplateAccessToDomain};
2230+
return new ConfigKey<?>[] {AllowPublicUserTemplates, TemplatePreloaderPoolSize};
22312231
}
22322232

22332233
public List<TemplateAdapter> getTemplateAdapters() {

0 commit comments

Comments
 (0)