Search in sources :

Example 21 with ActionGroup

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

the class AddRoleWithActionGroupsCommand method validate.

@Override
protected boolean validate() {
    if (getParameters().getActionGroups().isEmpty()) {
        addValidationMessage(EngineMessage.ACTION_LIST_CANNOT_BE_EMPTY);
        return false;
    }
    if (roleDao.getByName(getRoleName()) != null) {
        addValidationMessage(EngineMessage.VAR__ACTION__ADD);
        addValidationMessage(EngineMessage.VAR__TYPE__ROLE);
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_NAME_ALREADY_USED);
        return false;
    }
    RoleType roleType = getRole().getType();
    if (roleType == null) {
        addValidationMessage(EngineMessage.ROLE_TYPE_CANNOT_BE_EMPTY);
        return false;
    }
    if (roleType != RoleType.ADMIN) {
        List<ActionGroup> actionGroups = getParameters().getActionGroups();
        for (ActionGroup group : actionGroups) {
            if (group.getRoleType() == RoleType.ADMIN) {
                addValidationMessage(EngineMessage.CANNOT_ADD_ACTION_GROUPS_TO_ROLE_TYPE);
                return false;
            }
        }
    }
    return true;
}
Also used : ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) RoleType(org.ovirt.engine.core.common.businessentities.RoleType)

Example 22 with ActionGroup

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

the class CommandBase method checkSinglePermission.

public final boolean checkSinglePermission(PermissionSubject permSubject, Collection<String> messages) {
    final Guid objectId = permSubject.getObjectId();
    final VdcObjectType objectType = permSubject.getObjectType();
    final ActionGroup objectActionGroup = permSubject.getActionGroup();
    // if objectId is null we can't check permission
    if (objectId == null) {
        if (log.isDebugEnabled()) {
            log.debug("The object to check is null for action '{}'.", getActionType());
        }
        messages.add(EngineMessage.USER_NOT_AUTHORIZED_TO_PERFORM_ACTION.name());
        return false;
    }
    // Check that an action group is defined for this action;
    if (objectActionGroup == null) {
        if (log.isDebugEnabled()) {
            log.debug("No action group is defined for action '{}'.", getActionType());
        }
        return false;
    }
    // Check the authorization:
    if (!checkUserAuthorization(getCurrentUser().getId(), objectActionGroup, objectId, objectType)) {
        messages.add(permSubject.getMessage().name());
        return false;
    }
    return true;
}
Also used : ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Guid(org.ovirt.engine.core.compat.Guid) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType)

Example 23 with ActionGroup

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

the class DetachActionGroupsFromRoleCommand method validate.

@Override
protected boolean validate() {
    if (getRole() == null) {
        addValidationMessage(EngineMessage.ERROR_CANNOT_ATTACH_ACTION_GROUP_TO_ROLE_ATTACHED);
        return false;
    }
    List<String> validationMessages = getReturnValue().getValidationMessages();
    if (checkIfRoleIsReadOnly(validationMessages)) {
        validationMessages.add(EngineMessage.VAR__TYPE__ROLE.toString());
        validationMessages.add(EngineMessage.VAR__ACTION__DETACH_ACTION_TO.toString());
        return false;
    }
    Guid roleId = getParameters().getRoleId();
    List<ActionGroup> allGroups = getActionGroupsByRoleId(roleId);
    List<ActionGroup> groupsToDetach = getParameters().getActionGroups();
    // Check that target action group exists for this role
    for (ActionGroup group : groupsToDetach) {
        if (!allGroups.contains(group)) {
            validationMessages.add(EngineMessage.ERROR_CANNOT_DETACH_ACTION_GROUP_TO_ROLE_NOT_ATTACHED.toString());
            return false;
        }
    }
    return true;
}
Also used : ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Guid(org.ovirt.engine.core.compat.Guid)

Example 24 with ActionGroup

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

the class PermitMapperTest method postPopulate.

@Override
protected Permit postPopulate(Permit from) {
    ActionGroup actionGroup = MappingTestHelper.shuffle(ActionGroup.class);
    from.setId(Integer.toString(actionGroup.getId()));
    from.setName(actionGroup.name().toLowerCase());
    from.setAdministrative(actionGroup.getRoleType() == RoleType.ADMIN);
    return from;
}
Also used : ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup)

Aggregations

ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)24 ArrayList (java.util.ArrayList)9 Guid (org.ovirt.engine.core.compat.Guid)8 ActionGroupsToRoleParameter (org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter)6 Role (org.ovirt.engine.core.common.businessentities.Role)6 HashMap (java.util.HashMap)3 List (java.util.List)3 RoleGroupMap (org.ovirt.engine.core.common.businessentities.RoleGroupMap)3 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Test (org.junit.Test)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 NameableComparator (org.ovirt.engine.core.common.businessentities.comparators.NameableComparator)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2