Search in sources :

Example 1 with VdcObjectType

use of org.ovirt.engine.core.common.VdcObjectType 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 VdcObjectType

use of org.ovirt.engine.core.common.VdcObjectType in project ovirt-engine by oVirt.

the class ObjectNameRenderer method render.

@Override
public String render(Object[] arg) {
    VdcObjectType vdcObjectType = (VdcObjectType) arg[0];
    // $NON-NLS-1$ //$NON-NLS-2$
    String objectType = "(" + new EnumRenderer<VdcObjectType>().render(vdcObjectType) + ")";
    String objectName = (String) arg[1];
    if (arg.length == 4 && AsyncDataProvider.getInstance().getEntityGuid(arg[2]).equals(arg[3])) {
        // $NON-NLS-1$
        return "";
    }
    if (vdcObjectType.equals(VdcObjectType.System)) {
        return objectType;
    }
    // $NON-NLS-1$
    return objectName + " " + objectType;
}
Also used : VdcObjectType(org.ovirt.engine.core.common.VdcObjectType)

Example 3 with VdcObjectType

use of org.ovirt.engine.core.common.VdcObjectType in project ovirt-engine by oVirt.

the class CommandBase method getJobMessageProperties.

/**
 * Returns the properties which used to populate the job message. The default properties resolving will use
 * {@link #getPermissionCheckSubjects()} to get the entities associated with the command. The property key is the
 * type of the entity by {@code VdcObjectType.name()} and the value is the name of the entity or the entity
 * {@code Guid} in case non-resolvable entity name.
 *
 * @return A map which contains the data to be used to populate the {@code Job} description.
 */
public Map<String, String> getJobMessageProperties() {
    jobProperties = new HashMap<>();
    List<PermissionSubject> subjects = getPermissionCheckSubjects();
    if (!subjects.isEmpty()) {
        VdcObjectType entityType;
        Guid entityId;
        String value;
        for (PermissionSubject permSubject : subjects) {
            entityType = permSubject.getObjectType();
            entityId = permSubject.getObjectId();
            if (entityType != null && entityId != null) {
                value = entityDao.getEntityNameByIdAndType(entityId, entityType);
                if (value == null) {
                    value = entityId.toString();
                }
                jobProperties.put(entityType.name().toLowerCase(), value);
            }
        }
    }
    return jobProperties;
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) Guid(org.ovirt.engine.core.compat.Guid) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType)

Example 4 with VdcObjectType

use of org.ovirt.engine.core.common.VdcObjectType in project ovirt-engine by oVirt.

the class JobSubjectEntityDaoImpl method getJobSubjectEntityByJobId.

@Override
public Map<Guid, VdcObjectType> getJobSubjectEntityByJobId(Guid jobId) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("job_id", jobId);
    List<SubjectEntity> list = getCallsHandler().executeReadList("GetJobSubjectEntityByJobId", jobSubjectEntityRowMapper, parameterSource);
    Map<Guid, VdcObjectType> entityMap = new HashMap<>();
    for (SubjectEntity jobSubjectEntity : list) {
        entityMap.put(jobSubjectEntity.getEntityId(), jobSubjectEntity.getEntityType());
    }
    return entityMap;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SubjectEntity(org.ovirt.engine.core.common.businessentities.SubjectEntity) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType)

Example 5 with VdcObjectType

use of org.ovirt.engine.core.common.VdcObjectType in project ovirt-engine by oVirt.

the class StepSubjectEntityDaoTest method saveStepSubjectEntities.

@Test
public void saveStepSubjectEntities() {
    VdcObjectType type = VdcObjectType.VmPool;
    Guid entityId = Guid.newGuid();
    StepSubjectEntity stepSubjectEntity = new StepSubjectEntity(FixturesTool.STEP_ID, type, entityId, 50);
    Guid entityId2 = Guid.newGuid();
    StepSubjectEntity stepSubjectEntity2 = new StepSubjectEntity(FixturesTool.STEP_ID, type, entityId2, 50);
    dao.saveAll(Arrays.asList(stepSubjectEntity, stepSubjectEntity2));
    List<StepSubjectEntity> entities = dao.getStepSubjectEntitiesByStepId(FixturesTool.STEP_ID);
    assertEquals("StepSubjectEntity list not in the expected size", 4, entities.size());
    assertSubjectEntityPresence(stepSubjectEntity, entities, true);
    assertSubjectEntityPresence(stepSubjectEntity2, entities, true);
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) StepSubjectEntity(org.ovirt.engine.core.common.job.StepSubjectEntity) Test(org.junit.Test)

Aggregations

VdcObjectType (org.ovirt.engine.core.common.VdcObjectType)13 Guid (org.ovirt.engine.core.compat.Guid)7 StepSubjectEntity (org.ovirt.engine.core.common.job.StepSubjectEntity)3 Test (org.junit.Test)2 PermissionSubject (org.ovirt.engine.core.bll.utils.PermissionSubject)2 Job (org.ovirt.engine.core.common.job.Job)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)1 SubjectEntity (org.ovirt.engine.core.common.businessentities.SubjectEntity)1 BaseDisk (org.ovirt.engine.core.common.businessentities.storage.BaseDisk)1 Step (org.ovirt.engine.core.common.job.Step)1 GetPermissionsForObjectParameters (org.ovirt.engine.core.common.queries.GetPermissionsForObjectParameters)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 QueryType (org.ovirt.engine.core.common.queries.QueryType)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1