Search in sources :

Example 6 with Permission

use of org.ovirt.engine.api.model.Permission in project ovirt-engine by oVirt.

the class BackendAssignedPermissionsResource method map.

/**
 * injects user/group base on permission owner type
 * @param entity the permission to map
 * @param user the permission owner
 * @return permission
 */
public Permission map(org.ovirt.engine.core.common.businessentities.Permission entity, DbUser user) {
    Permission template = new Permission();
    if (entity.getAdElementId() != null) {
        if (isUser(user)) {
            template.setUser(new User());
            template.getUser().setId(entity.getAdElementId().toString());
        } else {
            template.setGroup(new Group());
            template.getGroup().setId(entity.getAdElementId().toString());
        }
    }
    return map(entity, template);
}
Also used : Group(org.ovirt.engine.api.model.Group) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) User(org.ovirt.engine.api.model.User) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) Permission(org.ovirt.engine.api.model.Permission)

Example 7 with Permission

use of org.ovirt.engine.api.model.Permission in project ovirt-engine by oVirt.

the class PermissionMapper method map.

@Mapping(from = org.ovirt.engine.core.common.businessentities.Permission.class, to = Permission.class)
public static Permission map(org.ovirt.engine.core.common.businessentities.Permission entity, Permission template) {
    Permission model = template != null ? template : new Permission();
    model.setId(entity.getId().toString());
    if (entity.getRoleId() != null) {
        model.setRole(new Role());
        model.getRole().setId(entity.getRoleId().toString());
    }
    if (entity.getAdElementId() != null && (template == null || !template.isSetGroup())) {
        model.setUser(new User());
        model.getUser().setId(entity.getAdElementId().toString());
    }
    if (entity.getObjectId() != null) {
        setObjectId(model, entity);
    }
    return model;
}
Also used : Role(org.ovirt.engine.api.model.Role) User(org.ovirt.engine.api.model.User) Permission(org.ovirt.engine.api.model.Permission)

Example 8 with Permission

use of org.ovirt.engine.api.model.Permission in project ovirt-engine by oVirt.

the class CompletenessAssertorTest method testCompleteSuperFieldAlternatives.

@Test
public void testCompleteSuperFieldAlternatives() throws Exception {
    Permission permission = new Permission();
    permission.setUser(new User());
    permission.getUser().setName("joe");
    CompletenessAssertor.validateParameters(permission, "vm|user.name");
}
Also used : User(org.ovirt.engine.api.model.User) Permission(org.ovirt.engine.api.model.Permission) Test(org.junit.Test)

Example 9 with Permission

use of org.ovirt.engine.api.model.Permission in project ovirt-engine by oVirt.

the class CompletenessAssertorTest method testCompleteBothAlternatives.

@Test
public void testCompleteBothAlternatives() throws Exception {
    Permission permission = new Permission();
    permission.setUser(new User());
    permission.getUser().setName("joe");
    CompletenessAssertor.validateParameters(permission, "vm|user.name|id");
}
Also used : User(org.ovirt.engine.api.model.User) Permission(org.ovirt.engine.api.model.Permission) Test(org.junit.Test)

Example 10 with Permission

use of org.ovirt.engine.api.model.Permission in project ovirt-engine by oVirt.

the class CompletenessAssertorTest method testMissingSuperFieldAlternatives.

@Test
public void testMissingSuperFieldAlternatives() throws Exception {
    Permission permission = new Permission();
    permission.setVm(new Vm());
    try {
        CompletenessAssertor.validateParameters(permission, "user|vm.name");
        fail("expected WebApplicationException on incomplete model");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Permission", "user|vm.name");
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Vm(org.ovirt.engine.api.model.Vm) Permission(org.ovirt.engine.api.model.Permission) Test(org.junit.Test)

Aggregations

Permission (org.ovirt.engine.api.model.Permission)15 Test (org.junit.Test)9 Role (org.ovirt.engine.api.model.Role)8 User (org.ovirt.engine.api.model.User)6 WebApplicationException (javax.ws.rs.WebApplicationException)5 DataCenter (org.ovirt.engine.api.model.DataCenter)3 Group (org.ovirt.engine.api.model.Group)3 Response (javax.ws.rs.core.Response)2 Vm (org.ovirt.engine.api.model.Vm)2 Permissions (org.ovirt.engine.api.model.Permissions)1 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)1 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)1