Skip to content

Commit b2d4fb6

Browse files
committed
fix and changes
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent e14ffd4 commit b2d4fb6

File tree

13 files changed

+37
-47
lines changed

13 files changed

+37
-47
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ private Pair<List<EventJoinVO>, Integer> searchForEventsInternal(ListEventsCmd c
856856

857857
private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
858858
Account caller = CallContext.current().getCallingAccount();
859-
boolean isRootAdmin = accountMgr.isRootAdmin(caller);
859+
boolean isRootAdmin = CallContext.current().isCallingAccountRootAdmin();
860860
List<Long> permittedAccounts = new ArrayList<>();
861861

862862
Long id = cmd.getId();
@@ -950,7 +950,7 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
950950
accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
951951

952952
// For end users display only enabled events
953-
if (!accountMgr.isRootAdmin(caller)) {
953+
if (!CallContext.current().isCallingAccountRootAdmin()) {
954954
sc.setParameters("displayEvent", true);
955955
}
956956

@@ -1185,8 +1185,7 @@ public ListResponse<UserVmResponse> searchForUserVMs(ListVMsCmd cmd) {
11851185
}
11861186

11871187
ResponseView respView = ResponseView.Restricted;
1188-
Account caller = CallContext.current().getCallingAccount();
1189-
if (accountMgr.isRootAdmin(caller)) {
1188+
if (CallContext.current().isCallingAccountRootAdmin()) {
11901189
respView = ResponseView.Full;
11911190
}
11921191
List<UserVmResponse> vmResponses = ViewResponseHelper.createUserVmResponse(respView, "virtualmachine", cmd.getDetails(), cmd.getAccumulate(), cmd.getShowUserData(),
@@ -1315,7 +1314,7 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
13151314
isAdmin = true;
13161315
}
13171316

1318-
if (accountMgr.isRootAdmin(caller)) {
1317+
if (CallContext.current().isCallingAccountRootAdmin()) {
13191318
isRootAdmin = true;
13201319
podId = (Long) getObjectPossibleMethodValue(cmd, "getPodId");
13211320
clusterId = (Long) getObjectPossibleMethodValue(cmd, "getClusterId");
@@ -2630,7 +2629,7 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
26302629
Boolean display = cmd.getDisplay();
26312630
String state = cmd.getState();
26322631
boolean shouldListSystemVms = Boolean.TRUE.equals(cmd.getListSystemVms()) &&
2633-
CallContext.registerPlaceHolderContext().isCallingAccountRootAdmin();
2632+
CallContext.current().isCallingAccountRootAdmin();
26342633

26352634
Long zoneId = cmd.getZoneId();
26362635
Long podId = cmd.getPodId();
@@ -4009,14 +4008,14 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
40094008

40104009
final Account owner = accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
40114010

4012-
if (!accountMgr.isRootAdmin(caller) && isSystem) {
4011+
if (!CallContext.current().isCallingAccountRootAdmin() && isSystem) {
40134012
throw new InvalidParameterValueException("Only ROOT admins can access system offerings.");
40144013
}
40154014

40164015
// Keeping this logic consistent with domain specific zones
40174016
// if a domainId is provided, we just return the so associated with this
40184017
// domain
4019-
if (domainId != null && !accountMgr.isRootAdmin(caller)) {
4018+
if (domainId != null && !CallContext.current().isCallingAccountRootAdmin()) {
40204019
// check if the user's domain == so's domain || user's domain is a
40214020
// child of so's domain
40224021
if (!isPermissible(owner.getDomainId(), domainId)) {

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
10241024
validateIpAddressRelatedConfigValues(name, value);
10251025
validateConflictingConfigValue(name, value);
10261026

1027-
if (CATEGORY_SYSTEM.equals(category) && !_accountMgr.isRootAdmin(caller)) {
1027+
if (CATEGORY_SYSTEM.equals(category) && !CallContext.current().isCallingAccountRootAdmin()) {
10281028
logger.warn("Only Root Admin is allowed to edit the configuration {}", name);
10291029
throw new CloudRuntimeException("Only Root Admin is allowed to edit this configuration.");
10301030
}
@@ -4934,9 +4934,8 @@ public Vlan createVlanAndPublicIpRange(final CreateVlanIpRangeCmd cmd) throws In
49344934
}
49354935

49364936
// Check if zone is enabled
4937-
final Account caller = CallContext.current().getCallingAccount();
49384937
if (Grouping.AllocationState.Disabled == zone.getAllocationState()
4939-
&& !_accountMgr.isRootAdmin(caller)) {
4938+
&& !CallContext.current().isCallingAccountRootAdmin()) {
49404939
throw new PermissionDeniedException(String.format("Cannot perform this operation, Zone is currently disabled: %s", zone));
49414940
}
49424941

server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ public Vpc createVpc(final long zoneId, final long vpcOffId, final long vpcOwner
12671267
throw new InvalidParameterValueException("Network domain must be specified for region level VPC");
12681268
}
12691269

1270-
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller)) {
1270+
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !CallContext.current().isCallingAccountRootAdmin()) {
12711271
// See DataCenterVO.java
12721272
final PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled");
12731273
ex.addProxyObject(zone.getUuid(), "zoneId");
@@ -2643,8 +2643,7 @@ private void validateVpcPrivateGatewayAssociateNetworkId(NetworkOfferingVO ntwkO
26432643
if (broadcastUri != null && associatedNetworkId != null) {
26442644
throw new InvalidParameterValueException("vlanId and associatedNetworkId are mutually exclusive");
26452645
}
2646-
Account caller = CallContext.current().getCallingAccount();
2647-
if (!_accountMgr.isRootAdmin(caller) && (ntwkOff.isSpecifyVlan() || broadcastUri != null || bypassVlanOverlapCheck)) {
2646+
if (!CallContext.current().isCallingAccountRootAdmin() && (ntwkOff.isSpecifyVlan() || broadcastUri != null || bypassVlanOverlapCheck)) {
26482647
throw new InvalidParameterValueException("Only ROOT admin is allowed to specify vlanId or bypass vlan overlap check");
26492648
}
26502649
if (ntwkOff.isSpecifyVlan() && broadcastUri == null) {
@@ -2767,7 +2766,7 @@ public boolean deleteVpcPrivateGateway(final long gatewayId) throws ConcurrentOp
27672766
}
27682767

27692768
final Account caller = CallContext.current().getCallingAccount();
2770-
if (!_accountMgr.isRootAdmin(caller)) {
2769+
if (!CallContext.current().isCallingAccountRootAdmin()) {
27712770
_accountMgr.checkAccess(caller, null, false, gatewayVO);
27722771
final NetworkVO networkVO = _ntwkDao.findById(gatewayVO.getNetworkId());
27732772
if (networkVO != null) {

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
946946
}
947947

948948
// Check if zone is disabled
949-
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller)) {
949+
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !CallContext.current().isCallingAccountRootAdmin()) {
950950
throw new PermissionDeniedException(String.format("Cannot perform this operation, Zone: %s is currently disabled", zone));
951951
}
952952

@@ -3989,8 +3989,6 @@ private boolean isOperationSupported(VMTemplateVO template, UserVmVO userVm) {
39893989
@Override
39903990
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "allocating snapshot", create = true)
39913991
public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType, List<Long> zoneIds, List<Long> poolIds, Boolean useStorageReplication) throws ResourceAllocationException {
3992-
Account caller = CallContext.current().getCallingAccount();
3993-
39943992
VolumeInfo volume = volFactory.getVolume(volumeId);
39953993
if (volume == null) {
39963994
throw new InvalidParameterValueException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist");
@@ -4059,7 +4057,7 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName,
40594057
if (dataCenter == null) {
40604058
throw new InvalidParameterValueException("Unable to find the specified zone");
40614059
}
4062-
if (Grouping.AllocationState.Disabled.equals(dataCenter.getAllocationState()) && !_accountMgr.isRootAdmin(caller)) {
4060+
if (Grouping.AllocationState.Disabled.equals(dataCenter.getAllocationState()) && !CallContext.current().isCallingAccountRootAdmin()) {
40634061
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + dataCenter.getName());
40644062
}
40654063
if (DataCenter.Type.Edge.equals(dataCenter.getType())) {
@@ -4115,7 +4113,7 @@ public Snapshot allocSnapshotForVm(Long vmId, Long volumeId, String snapshotName
41154113
throw new InvalidParameterValueException("Can't find zone by id " + volume.getDataCenterId());
41164114
}
41174115

4118-
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller)) {
4116+
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !CallContext.current().isCallingAccountRootAdmin()) {
41194117
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getName());
41204118
}
41214119

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public String extractSnapshot(ExtractSnapshotCmd cmd) {
533533
Long snapshotId = cmd.getId();
534534
Long zoneId = cmd.getZoneId();
535535

536-
if (!_accountMgr.isRootAdmin(caller) && ApiDBUtils.isExtractionDisabled()) {
536+
if (!CallContext.current().isCallingAccountRootAdmin() && ApiDBUtils.isExtractionDisabled()) {
537537
logger.error("Extraction is disabled through [{}].", Config.DisableExtraction);
538538
throw new PermissionDeniedException("Extraction could not be completed.");
539539
}
@@ -2264,9 +2264,9 @@ public Snapshot copySnapshot(CopySnapshotCmd cmd) throws StorageUnavailableExcep
22642264
storagePoolIds = snapshotHelper.addStoragePoolsForCopyToPrimary(volume, destZoneIds, storagePoolIds, useStorageReplication);
22652265
boolean canCopyBetweenStoragePools = CollectionUtils.isNotEmpty(storagePoolIds) && canCopyOnPrimary(storagePoolIds, snapshotVO);
22662266
Map<Long, DataCenterVO> dataCenterVOs = new HashMap<>();
2267-
boolean isRootAdminCaller = _accountMgr.isRootAdmin(caller);
22682267
for (Long destZoneId: destZoneIds) {
2269-
DataCenterVO dstZone = getCheckedDestinationZoneForSnapshotCopy(destZoneId, isRootAdminCaller);
2268+
DataCenterVO dstZone = getCheckedDestinationZoneForSnapshotCopy(destZoneId,
2269+
CallContext.current().isCallingAccountRootAdmin());
22702270
dataCenterVOs.put(destZoneId, dstZone);
22712271
}
22722272
_accountMgr.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, true, snapshot);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ public TemplateProfile prepare(boolean isIso, long userId, String name, String d
371371
if (zone == null) {
372372
throw new IllegalArgumentException("Please specify a valid zone.");
373373
}
374-
Account caller = CallContext.current().getCallingAccount();
375-
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller)) {
374+
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !CallContext.current().isCallingAccountRootAdmin()) {
376375
throw new PermissionDeniedException(String.format("Cannot perform this operation, Zone %s is currently disabled", zone));
377376
}
378377
}

server/src/main/java/com/cloud/usage/UsageServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd
193193
accountId = caller.getId();
194194
//List records for all the accounts if the caller account is of type admin.
195195
//If account_id or account_name is explicitly mentioned, list records for the specified account only even if the caller is of type admin
196-
ignoreAccountId = _accountService.isRootAdmin(caller);
196+
ignoreAccountId = CallContext.current().isCallingAccountRootAdmin();
197197
logger.debug("Account details not available. Using userContext account: {}", caller);
198198
}
199199

server/src/main/java/com/cloud/user/DomainManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ public Pair<List<? extends Domain>, Integer> searchForDomains(ListDomainsCmd cmd
721721
}
722722
_accountMgr.checkAccess(caller, domain);
723723
} else {
724-
if (!_accountMgr.isRootAdmin(caller)) {
724+
if (!CallContext.current().isCallingAccountRootAdmin()) {
725725
domainId = caller.getDomainId();
726726
}
727727
if (listAll) {

server/src/main/java/com/cloud/uuididentity/UUIDManagerImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ public <T> void checkUuid(String uuid, Class<T> entityType) {
4747
return;
4848
}
4949

50-
Account caller = CallContext.current().getCallingAccount();
51-
5250
// Only admin and system allowed to do this
53-
if (!(caller.getId() == Account.ACCOUNT_ID_SYSTEM || _accountMgr.isRootAdmin(caller))) {
51+
if (!(CallContext.current().getCallingAccountId() == Account.ACCOUNT_ID_SYSTEM || CallContext.current().isCallingAccountRootAdmin())) {
5452
throw new PermissionDeniedException("Please check your permissions, you are not allowed to create/update custom id");
5553
}
5654

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6930,8 +6930,7 @@ public VirtualMachine getVm(long vmId) {
69306930

69316931
private VMInstanceVO preVmStorageMigrationCheck(Long vmId) {
69326932
// access check - only root admin can migrate VM
6933-
Account caller = CallContext.current().getCallingAccount();
6934-
if (!_accountMgr.isRootAdmin(caller)) {
6933+
if (!CallContext.current().isCallingAccountRootAdmin()) {
69356934
if (logger.isDebugEnabled()) {
69366935
logger.debug("Caller is not a root admin, permission denied to migrate the VM");
69376936
}
@@ -7072,8 +7071,7 @@ public boolean isVMUsingLocalStorage(VMInstanceVO vm) {
70727071
public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException,
70737072
VirtualMachineMigrationException {
70747073
// access check - only root admin can migrate VM
7075-
Account caller = CallContext.current().getCallingAccount();
7076-
if (!_accountMgr.isRootAdmin(caller)) {
7074+
if (!CallContext.current().isCallingAccountRootAdmin()) {
70777075
if (logger.isDebugEnabled()) {
70787076
logger.debug("Caller is not a root admin, permission denied to migrate the VM");
70797077
}

0 commit comments

Comments
 (0)