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());
}
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;
}
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;
}
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;
}
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);
}
Aggregations