Skip to content

Commit 845a454

Browse files
committed
update checks
1 parent fd732a7 commit 845a454

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

api/src/main/java/org/apache/cloudstack/acl/SecurityChecker.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,5 @@ boolean checkAccess(Account caller, AccessType accessType, String action, Contro
148148

149149
boolean checkAccess(Account account, VpcOffering vof, DataCenter zone) throws PermissionDeniedException;
150150

151-
default boolean checkAccess(Account account, BackupOffering bof) throws PermissionDeniedException {
152-
return true;
153-
}
151+
boolean checkAccess(Account account, BackupOffering bof) throws PermissionDeniedException;
154152
}

engine/schema/src/main/java/org/apache/cloudstack/backup/BackupOfferingVO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.cloudstack.backup;
1919

20+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
21+
2022
import java.util.Date;
2123
import java.util.UUID;
2224

@@ -131,4 +133,9 @@ public void setDescription(String description) {
131133
public Date getCreated() {
132134
return created;
133135
}
136+
137+
@Override
138+
public String toString() {
139+
return String.format("Backup offering %s.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "name", "uuid"));
140+
}
134141
}

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,11 @@ public boolean assignVMToBackupOffering(Long vmId, Long offeringId) {
539539
throw new CloudRuntimeException("Provided backup offering does not exist");
540540
}
541541

542-
accountManager.checkAccess(CallContext.current().getCallingAccount(), offering);
542+
Account owner = accountManager.getAccount(vm.getAccountId());
543+
if (owner == null) {
544+
throw new CloudRuntimeException("Unable to find the owner of the VM");
545+
}
546+
accountManager.checkAccess(owner, offering);
543547

544548
final BackupProvider backupProvider = getBackupProvider(offering.getProvider());
545549
if (backupProvider == null) {
@@ -602,8 +606,6 @@ public boolean removeVMFromBackupOffering(final Long vmId, final boolean forced)
602606
throw new CloudRuntimeException("No previously configured backup offering found for the VM");
603607
}
604608

605-
accountManager.checkAccess(CallContext.current().getCallingAccount(), offering);
606-
607609
final BackupProvider backupProvider = getBackupProvider(offering.getProvider());
608610
if (backupProvider == null) {
609611
throw new CloudRuntimeException("Failed to get the backup provider for the zone, please contact the administrator");
@@ -867,7 +869,6 @@ public boolean createBackup(CreateBackupCmd cmd, Object job) throws ResourceAllo
867869
if (offering == null) {
868870
throw new CloudRuntimeException("VM backup offering not found");
869871
}
870-
accountManager.checkAccess(caller, offering);
871872

872873
final BackupProvider backupProvider = getBackupProvider(offering.getProvider());
873874
if (backupProvider == null) {

server/src/test/java/com/cloud/acl/DomainCheckerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public void testBackupOfferingAccessDomainAdmin() {
189189
AccountVO owner = Mockito.mock(AccountVO.class);
190190
Mockito.when(_accountService.isDomainAdmin(domainAdmin.getId())).thenReturn(true);
191191
Mockito.when(domainAdmin.getDomainId()).thenReturn(10L);
192-
Mockito.when(owner.getDomainId()).thenReturn(101L);
193192
Mockito.when(_domainDao.isChildDomain(100L, 10L)).thenReturn(true);
194193
Mockito.when(backupOfferingDetailsDao.findDomainIds(backupOfferingVO.getId())).thenReturn(Collections.singletonList(100L));
195194

@@ -204,7 +203,6 @@ public void testBackupOfferingAccessNoAccess() {
204203
BackupOfferingVO backupOfferingVO = Mockito.mock(BackupOfferingVO.class);
205204
Mockito.when(_accountService.isRootAdmin(normalUser.getId())).thenReturn(false);
206205
Mockito.when(_accountService.isDomainAdmin(normalUser.getId())).thenReturn(false);
207-
Mockito.when(backupOfferingDetailsDao.findDomainIds(backupOfferingVO.getId())).thenReturn(Collections.singletonList(100L));
208206

209207
boolean hasAccess = domainChecker.checkAccess(normalUser, backupOfferingVO);
210208
Assert.assertFalse(hasAccess);

server/src/test/java/org/apache/cloudstack/backup/BackupManagerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,8 @@ public void testAssignVMToBackupOffering() {
11551155
VMInstanceVO vm = mock(VMInstanceVO.class);
11561156
when(vm.getId()).thenReturn(vmId);
11571157
BackupOfferingVO offering = mock(BackupOfferingVO.class);
1158+
Account owner = mock(Account.class);
1159+
11581160

11591161
overrideBackupFrameworkConfigValue();
11601162

@@ -1165,6 +1167,8 @@ public void testAssignVMToBackupOffering() {
11651167
when(vm.getBackupOfferingId()).thenReturn(null);
11661168
when(offering.getProvider()).thenReturn("testbackupprovider");
11671169
when(backupProvider.assignVMToBackupOffering(vm, offering)).thenReturn(true);
1170+
when(vm.getAccountId()).thenReturn(3L);
1171+
when(accountManager.getAccount(vm.getAccountId())).thenReturn(owner);
11681172
when(vmInstanceDao.update(1L, vm)).thenReturn(true);
11691173

11701174
try (MockedStatic<UsageEventUtils> ignored2 = Mockito.mockStatic(UsageEventUtils.class)) {

0 commit comments

Comments
 (0)