use of org.ovirt.engine.core.common.businessentities.Permission in project ovirt-engine by oVirt.
the class AddQuotaCommand method copyQuotaPermissions.
private void copyQuotaPermissions() {
UniquePermissionsSet permissionsToAdd = new UniquePermissionsSet();
List<Permission> vmPermissions = permissionDao.getAllForEntity(getParameters().getQuotaId(), getEngineSessionSeqId(), false);
for (Permission vmPermission : vmPermissions) {
permissionsToAdd.addPermission(vmPermission.getAdElementId(), vmPermission.getRoleId(), getQuotaId(), vmPermission.getObjectType());
}
if (!permissionsToAdd.isEmpty()) {
List<Permission> permissionsList = permissionsToAdd.asPermissionList();
multiLevelAdministrationHandler.addPermission(permissionsList.toArray(new Permission[permissionsList.size()]));
}
}
use of org.ovirt.engine.core.common.businessentities.Permission in project ovirt-engine by oVirt.
the class AddPermissionCommand method validate.
@Override
protected boolean validate() {
Permission perm = getParameters().getPermission();
if (perm == null) {
addValidationMessage(EngineMessage.PERMISSION_ADD_FAILED_PERMISSION_NOT_SENT);
return false;
}
// Try to find the requested role, first by id and then by name:
Role role = null;
Guid roleId = perm.getRoleId();
String roleName = perm.getRoleName();
if (!Guid.isNullOrEmpty(roleId)) {
role = roleDao.get(roleId);
if (role != null) {
roleName = role.getName();
perm.setRoleName(roleName);
}
} else if (roleName != null) {
role = roleDao.getByName(roleName);
if (role != null) {
roleId = role.getId();
perm.setRoleId(roleId);
}
}
if (role == null) {
addValidationMessage(EngineMessage.PERMISSION_ADD_FAILED_INVALID_ROLE_ID);
return false;
}
Guid adElementId = perm.getAdElementId();
if (perm.getObjectType() == null || getVdcObjectName() == null) {
addValidationMessage(EngineMessage.PERMISSION_ADD_FAILED_INVALID_OBJECT_ID);
return false;
}
// give permission
if (getParameters().getUser() == null && getParameters().getGroup() == null && dbUserDao.get(adElementId) == null && dbGroupDao.get(adElementId) == null) {
return failValidation(EngineMessage.USER_MUST_EXIST_IN_DB);
}
// only system super user can give permissions with admin roles
if (!isSystemSuperUser() && role.getType() == RoleType.ADMIN) {
return failValidation(EngineMessage.PERMISSION_ADD_FAILED_ONLY_SYSTEM_SUPER_USER_CAN_GIVE_ADMIN_ROLES);
}
// don't allow adding permissions to vms from pool externally
if (!isInternalExecution() && perm.getObjectType() == VdcObjectType.VM) {
VM vm = vmDao.get(perm.getObjectId());
if (vm != null && vm.getVmPoolId() != null) {
return failValidation(EngineMessage.PERMISSION_ADD_FAILED_VM_IN_POOL);
}
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.Permission in project ovirt-engine by oVirt.
the class AddPermissionCommand method executeCommand.
@Override
protected void executeCommand() {
// Get the parameters:
T parameters = getParameters();
// The user or group given in the parameters may haven't been added to the database yet, if this is the case
// then they need to be added to the database now, before the permission:
DbUser user = parameters.getUser();
if (user != null) {
Guid id = user.getId();
String directory = user.getDomain();
String externalId = user.getExternalId();
DbUser existing = dbUserDao.getByIdOrExternalId(id, directory, externalId);
if (existing != null) {
user = existing;
} else {
user = addUser(user);
if (user == null) {
setSucceeded(false);
return;
}
}
}
DbGroup group = parameters.getGroup();
if (group != null) {
Guid id = group.getId();
String directory = group.getDomain();
String externalId = group.getExternalId();
DbGroup existing = dbGroupDao.getByIdOrExternalId(id, directory, externalId);
if (existing != null) {
group = existing;
} else {
group = addGroup(group);
if (group == null) {
setSucceeded(false);
return;
}
}
}
// The identifier of the principal of the permission can come from the parameters directly or from the
// user/group objects:
Guid principalId;
if (user != null) {
principalId = user.getId();
} else if (group != null) {
principalId = group.getId();
} else {
principalId = parameters.getPermission().getAdElementId();
}
final Permission paramPermission = parameters.getPermission();
Permission permission = permissionDao.getForRoleAndAdElementAndObject(paramPermission.getRoleId(), principalId, paramPermission.getObjectId());
if (permission == null) {
paramPermission.setAdElementId(principalId);
TransactionSupport.executeInNewTransaction(() -> {
permissionDao.save(paramPermission);
getCompensationContext().snapshotNewEntity(paramPermission);
getCompensationContext().stateChanged();
return null;
});
permission = paramPermission;
}
getReturnValue().setActionReturnValue(permission.getId());
if (user != null) {
updateAdminStatus(permission);
}
vmStaticDao.incrementDbGeneration(paramPermission.getObjectId());
setSucceeded(true);
}
use of org.ovirt.engine.core.common.businessentities.Permission in project ovirt-engine by oVirt.
the class SubTabQuotaPermissionView method initTable.
private void initTable() {
// $NON-NLS-1$
getTable().addColumn(new PermissionTypeColumn(), constants.empty(), "30px");
AbstractTextColumn<Permission> userColumn = new AbstractTextColumn<Permission>() {
@Override
public String getValue(Permission object) {
return object.getOwnerName();
}
};
userColumn.makeSortable();
getTable().addColumn(userColumn, constants.userPermission());
AbstractTextColumn<Permission> roleColumn = new AbstractTextColumn<Permission>() {
@Override
public String getValue(Permission object) {
return object.getRoleName();
}
};
roleColumn.makeSortable();
getTable().addColumn(roleColumn, constants.rolePermission());
AbstractTextColumn<Permission> permissionColumn = new AbstractObjectNameColumn<Permission>() {
@Override
protected Object[] getRawValue(Permission object) {
return new Object[] { object.getObjectType(), object.getObjectName(), getDetailModel().getEntity(), object.getObjectId() };
}
};
permissionColumn.makeSortable();
getTable().addColumn(permissionColumn, constants.inheretedFromPermission());
}
Aggregations