Search in sources :

Example 1 with PermissionSubject

use of org.ovirt.engine.core.bll.utils.PermissionSubject in project ovirt-engine by oVirt.

the class AddVmCommand method checkCreateInstancePermission.

/**
 * To create a vm either {@link ActionGroup#CREATE_VM} or {@link ActionGroup#CREATE_INSTANCE} permissions is
 * required for selected {@link VdcObjectType}s. However {@link #getPermissionCheckSubjects()} returns only
 * {@link ActionGroup#CREATE_VM} based permissions subjects. This method helps to mitigate this problem.
 * @param permSubject permission subject
 * @return true if {@link ActionGroup#CREATE_INSTANCE} based permission is sufficient, false otherwise
 */
private boolean checkCreateInstancePermission(PermissionSubject permSubject) {
    final List<VdcObjectType> overriddenPermissionObjectTypes = Arrays.asList(VdcObjectType.Cluster, VdcObjectType.VmTemplate);
    final boolean instanceCreateObjectType = overriddenPermissionObjectTypes.contains(permSubject.getObjectType());
    if (!instanceCreateObjectType) {
        return false;
    }
    final PermissionSubject alteredPermissionSubject = new PermissionSubject(permSubject.getObjectId(), permSubject.getObjectType(), ActionGroup.CREATE_INSTANCE, permSubject.getMessage());
    return checkSinglePermission(alteredPermissionSubject, getReturnValue().getValidationMessages());
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType)

Example 2 with PermissionSubject

use of org.ovirt.engine.core.bll.utils.PermissionSubject in project ovirt-engine by oVirt.

the class AddVmCommand method addPermissionSubjectForAdminLevelProperties.

protected void addPermissionSubjectForAdminLevelProperties(List<PermissionSubject> permissionList) {
    VmStatic vmFromParams = getParameters().getVmStaticData();
    VmTemplate vmTemplate = getVmTemplate();
    if (vmFromParams != null && vmTemplate != null) {
        // user needs specific permission to change custom properties
        if (!Objects.equals(vmFromParams.getCustomProperties(), vmTemplate.getCustomProperties())) {
            permissionList.add(new PermissionSubject(getClusterId(), VdcObjectType.Cluster, ActionGroup.CHANGE_VM_CUSTOM_PROPERTIES));
        }
        // if the template is blank we ignore his pinned hosts
        if (vmTemplate.isBlank()) {
            return;
        }
        Set<Guid> dedicatedVmForVdsFromUser = new HashSet<>(vmFromParams.getDedicatedVmForVdsList());
        Set<Guid> dedicatedVmForVdsFromTemplate = new HashSet<>(vmTemplate.getDedicatedVmForVdsList());
        // host-specific parameters can be changed by administration role only
        if (!dedicatedVmForVdsFromUser.equals(dedicatedVmForVdsFromTemplate) || !StringUtils.isEmpty(vmFromParams.getCpuPinning())) {
            permissionList.add(new PermissionSubject(getClusterId(), VdcObjectType.Cluster, ActionGroup.EDIT_ADMIN_VM_PROPERTIES));
        }
    }
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 3 with PermissionSubject

use of org.ovirt.engine.core.bll.utils.PermissionSubject in project ovirt-engine by oVirt.

the class AddVmCommand method getPermissionCheckSubjects.

@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
    List<PermissionSubject> permissionList = new ArrayList<>();
    permissionList.add(new PermissionSubject(getClusterId(), VdcObjectType.Cluster, getActionType().getActionGroup()));
    permissionList.add(new PermissionSubject(getVmTemplateId(), VdcObjectType.VmTemplate, getActionType().getActionGroup()));
    if (getVmTemplate() != null && !getVmTemplate().getDiskList().isEmpty()) {
        permissionList.addAll(getParameters().getDiskInfoDestinationMap().values().stream().filter(disk -> disk.getStorageIds() != null && !disk.getStorageIds().isEmpty()).map(disk -> new PermissionSubject(disk.getStorageIds().get(0), VdcObjectType.Storage, ActionGroup.CREATE_DISK)).collect(Collectors.toList()));
    }
    addPermissionSubjectForAdminLevelProperties(permissionList);
    return permissionList;
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) VmInitDao(org.ovirt.engine.core.dao.VmInitDao) EngineException(org.ovirt.engine.core.common.errors.EngineException) RngDeviceParameters(org.ovirt.engine.core.common.action.RngDeviceParameters) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) AddVmParameters(org.ovirt.engine.core.common.action.AddVmParameters) VmNicDao(org.ovirt.engine.core.dao.network.VmNicDao) Base64(org.apache.commons.codec.binary.Base64) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) VdsDao(org.ovirt.engine.core.dao.VdsDao) CinderDisksValidator(org.ovirt.engine.core.bll.validator.storage.CinderDisksValidator) Map(java.util.Map) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) Instance(javax.enterprise.inject.Instance) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) VmWatchdogValidator(org.ovirt.engine.core.bll.validator.VmWatchdogValidator) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Set(java.util.Set) CreateSnapshotFromTemplateParameters(org.ovirt.engine.core.common.action.CreateSnapshotFromTemplateParameters) StandardCharsets(java.nio.charset.StandardCharsets) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Label(org.ovirt.engine.core.common.businessentities.Label) LabelDao(org.ovirt.engine.core.dao.LabelDao) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) QuotaConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter) VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) CreateVm(org.ovirt.engine.core.common.validation.group.CreateVm) VmStatisticsDao(org.ovirt.engine.core.dao.VmStatisticsDao) QuotaSanityParameter(org.ovirt.engine.core.bll.quota.QuotaSanityParameter) QuotaStorageDependent(org.ovirt.engine.core.bll.quota.QuotaStorageDependent) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) DiskProfileHelper(org.ovirt.engine.core.bll.profiles.DiskProfileHelper) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) VmNumaNodeOperationParameters(org.ovirt.engine.core.common.action.VmNumaNodeOperationParameters) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) CpuPinningValidator.isCpuPinningValid(org.ovirt.engine.core.bll.validator.CpuPinningValidator.isCpuPinningValid) Permission(org.ovirt.engine.core.common.businessentities.Permission) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) Pair(org.ovirt.engine.core.common.utils.Pair) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) Scope(org.ovirt.engine.core.common.action.LockProperties.Scope) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) ImageType(org.ovirt.engine.core.common.businessentities.ImageType) EngineError(org.ovirt.engine.core.common.errors.EngineError) AddVmToPoolParameters(org.ovirt.engine.core.common.action.AddVmToPoolParameters) VM(org.ovirt.engine.core.common.businessentities.VM) InClusterUpgradeValidator(org.ovirt.engine.core.bll.validator.InClusterUpgradeValidator) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback) VmValidationUtils(org.ovirt.engine.core.bll.validator.VmValidationUtils) VmInit(org.ovirt.engine.core.common.businessentities.VmInit) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) VmInterfaceManager(org.ovirt.engine.core.bll.network.VmInterfaceManager) IconValidator(org.ovirt.engine.core.bll.validator.IconValidator) UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) WatchdogParameters(org.ovirt.engine.core.common.action.WatchdogParameters) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) Date(java.util.Date) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) VmDynamicDao(org.ovirt.engine.core.dao.VmDynamicDao) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmCpuCountHelper(org.ovirt.engine.core.common.utils.VmCpuCountHelper) OriginType(org.ovirt.engine.core.common.businessentities.OriginType) VmNetworkStatisticsDao(org.ovirt.engine.core.dao.network.VmNetworkStatisticsDao) StorageDomainValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) Version(org.ovirt.engine.core.compat.Version) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) BlockStorageDiscardFunctionalityHelper(org.ovirt.engine.core.bll.storage.utils.BlockStorageDiscardFunctionalityHelper) IconUtils(org.ovirt.engine.core.bll.utils.IconUtils) DiskVmElementDao(org.ovirt.engine.core.dao.DiskVmElementDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmValidator(org.ovirt.engine.core.bll.validator.VmValidator) AuditLogType(org.ovirt.engine.core.common.AuditLogType) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QuotaVdsDependent(org.ovirt.engine.core.bll.quota.QuotaVdsDependent) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) LockProperties(org.ovirt.engine.core.common.action.LockProperties) HashMap(java.util.HashMap) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) DiskProfileDao(org.ovirt.engine.core.dao.profiles.DiskProfileDao) HashSet(java.util.HashSet) Inject(javax.inject.Inject) NetworkHelper(org.ovirt.engine.core.bll.network.cluster.NetworkHelper) CollectionUtils(org.apache.commons.collections.CollectionUtils) Network(org.ovirt.engine.core.common.businessentities.network.Network) VmStatistics(org.ovirt.engine.core.common.businessentities.VmStatistics) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) Config(org.ovirt.engine.core.common.config.Config) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) ImagesContainterParametersBase(org.ovirt.engine.core.common.action.ImagesContainterParametersBase) VmInitToOpenStackMetadataAdapter(org.ovirt.engine.core.common.utils.VmInitToOpenStackMetadataAdapter) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) Typed(javax.enterprise.inject.Typed) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) QuotaStorageConsumptionParameter(org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter) GraphicsParameters(org.ovirt.engine.core.common.action.GraphicsParameters) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Collections(java.util.Collections) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) ArrayList(java.util.ArrayList)

Example 4 with PermissionSubject

use of org.ovirt.engine.core.bll.utils.PermissionSubject in project ovirt-engine by oVirt.

the class AddVmCommand method checkInstanceTypeImagePermissions.

/**
 * If using an instance type/image the user needs to have either CREATE_INSTANCE or the specific
 * getActionType().getActionGroup() on the instance type/image
 */
private boolean checkInstanceTypeImagePermissions(Guid id) {
    Collection<String> createInstanceMessages = new ArrayList<>();
    Collection<String> actionGroupMessages = new ArrayList<>();
    PermissionSubject createInstanceSubject = new PermissionSubject(id, VdcObjectType.VmTemplate, ActionGroup.CREATE_INSTANCE);
    PermissionSubject actionGroupSubject = new PermissionSubject(id, VdcObjectType.VmTemplate, getActionType().getActionGroup());
    // it is enough if at least one of this two permissions are there
    if (!checkSinglePermission(createInstanceSubject, createInstanceMessages) && !checkSinglePermission(actionGroupSubject, actionGroupMessages)) {
        getReturnValue().getValidationMessages().addAll(actionGroupMessages);
        return false;
    }
    return true;
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) ArrayList(java.util.ArrayList)

Example 5 with PermissionSubject

use of org.ovirt.engine.core.bll.utils.PermissionSubject in project ovirt-engine by oVirt.

the class AddVmFromSnapshotCommand method getPermissionCheckSubjects.

@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
    List<PermissionSubject> permissionList = super.getPermissionCheckSubjects();
    permissionList.add(new PermissionSubject(getVmIdFromSnapshot(), VdcObjectType.VM, getActionType().getActionGroup()));
    return permissionList;
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject)

Aggregations

PermissionSubject (org.ovirt.engine.core.bll.utils.PermissionSubject)71 ArrayList (java.util.ArrayList)47 Guid (org.ovirt.engine.core.compat.Guid)15 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 VdcObjectType (org.ovirt.engine.core.common.VdcObjectType)5 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ImagesHandler (org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler)3 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)3 VM (org.ovirt.engine.core.common.businessentities.VM)3 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)3 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)3 VmNic (org.ovirt.engine.core.common.businessentities.network.VmNic)3 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)3 DiskVmElementDao (org.ovirt.engine.core.dao.DiskVmElementDao)3 Arrays (java.util.Arrays)2