Search in sources :

Example 51 with Permission

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

the class RemoveGroupCommand method executeCommand.

@Override
protected void executeCommand() {
    // Get the identifier of the group from the parameters:
    Guid id = getParameters().getId();
    // TODO: This should be done without invoking the command to avoid the overhead.
    for (Permission permission : permissionDao.getAllDirectPermissionsForAdElement(id)) {
        PermissionsOperationsParameters param = new PermissionsOperationsParameters(permission);
        param.setSessionId(getParameters().getSessionId());
        runInternalActionWithTasksContext(ActionType.RemovePermission, param);
    }
    // Remove the group itself:
    dbGroupDao.remove(id);
    setSucceeded(true);
}
Also used : PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) Permission(org.ovirt.engine.core.common.businessentities.Permission) Guid(org.ovirt.engine.core.compat.Guid)

Example 52 with Permission

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

the class MultiLevelAdministrationHandler method isLastSuperUserGroup.

/**
 * Checks if supplied group is the last (or maybe only)  with super user privileges.
 *
 * @param groupId
 *                the group is
 * @return true if group is the last with Super User privileges, otherwise, false
 */
public boolean isLastSuperUserGroup(Guid groupId) {
    boolean retValue = false;
    // check that there is at least one super-user left in the system
    List<Permission> permissions = permissionDao.getAllForRole(PredefinedRoles.SUPER_USER.getId());
    if (permissions.size() <= 1) {
        // get group role
        permissions = permissionDao.getAllForAdElement(groupId);
        for (Permission permission : permissions) {
            if (permission.getRoleId().equals(PredefinedRoles.SUPER_USER.getId())) {
                retValue = true;
                break;
            }
        }
    }
    return retValue;
}
Also used : Permission(org.ovirt.engine.core.common.businessentities.Permission)

Example 53 with Permission

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

the class RemovePermissionCommand method executeCommand.

@Override
protected void executeCommand() {
    Permission perms = getParameters().getPermission();
    Guid userId = perms.getAdElementId();
    // check if vm is from pool and detach it
    if (perms.getObjectType().equals(VdcObjectType.VM) && perms.getRoleId().equals(PredefinedRoles.ENGINE_USER.getId())) {
        VM vm = vmDao.get(perms.getObjectId());
        if (vm != null && vm.getVmPoolId() != null) {
            runInternalActionWithTasksContext(ActionType.DetachUserFromVmFromPool, new DetachUserFromVmFromPoolParameters(vm.getVmPoolId(), userId, vm.getId(), true));
        }
    }
    vmStaticDao.incrementDbGeneration(perms.getObjectId());
    permissionDao.remove(perms.getId());
    dbUserDao.updateLastAdminCheckStatus(userId);
    setSucceeded(true);
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) Permission(org.ovirt.engine.core.common.businessentities.Permission) Guid(org.ovirt.engine.core.compat.Guid) DetachUserFromVmFromPoolParameters(org.ovirt.engine.core.common.action.DetachUserFromVmFromPoolParameters)

Example 54 with Permission

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

the class PermissionsCommandBase method getPermissionCheckSubjects.

// TODO - this code is shared with addPermissionCommand - check if
// addPermission can extend this command
@Override
public List<PermissionSubject> getPermissionCheckSubjects() {
    List<PermissionSubject> permissionList = new ArrayList<>();
    Permission permission = getParameters().getPermission();
    permissionList.add(new PermissionSubject(permission.getObjectId(), permission.getObjectType(), getActionType().getActionGroup()));
    return permissionList;
}
Also used : PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) ArrayList(java.util.ArrayList) Permission(org.ovirt.engine.core.common.businessentities.Permission)

Example 55 with Permission

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

the class AttachUserToVmFromPoolAndRunCommand method attachUserToVm.

private ActionReturnValue attachUserToVm() {
    Permission perm = new Permission(getAdUserId(), PredefinedRoles.ENGINE_USER.getId(), getVmId(), VdcObjectType.VM);
    PermissionsOperationsParameters permParams = new PermissionsOperationsParameters(perm);
    permParams.setShouldBeLogged(false);
    permParams.setParentCommand(getActionType());
    permParams.setParentParameters(getParameters());
    return runInternalAction(ActionType.AddPermission, permParams, cloneContext().withoutExecutionContext().withoutLock());
}
Also used : PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) Permission(org.ovirt.engine.core.common.businessentities.Permission)

Aggregations

Permission (org.ovirt.engine.core.common.businessentities.Permission)59 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)12 Guid (org.ovirt.engine.core.compat.Guid)12 PermissionsOperationsParameters (org.ovirt.engine.core.common.action.PermissionsOperationsParameters)9 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)8 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)6 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)6 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)5 AdElementListModel (org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel)5 Role (org.ovirt.engine.core.common.businessentities.Role)4 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)3 QueryType (org.ovirt.engine.core.common.queries.QueryType)3 AbstractTextColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn)3 PermissionTypeColumn (org.ovirt.engine.ui.common.widget.table.column.PermissionTypeColumn)3 Frontend (org.ovirt.engine.ui.frontend.Frontend)3 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)3 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)3 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)3 Inject (com.google.inject.Inject)2