Search in sources :

Example 1 with Permission

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

the class BackendAssignedPermissionsResource method mapCollection.

protected Permissions mapCollection(Set<org.ovirt.engine.core.common.businessentities.Permission> entities) {
    Permissions collection = new Permissions();
    for (org.ovirt.engine.core.common.businessentities.Permission entity : entities) {
        castEveryonePermissionsToUser(entity);
        Permission permission = map(entity, getUserById(entity.getAdElementId()));
        collection.getPermissions().add(addLinks(permission, permission.getUser() != null ? suggestedParentType : Group.class));
    }
    return collection;
}
Also used : Permissions(org.ovirt.engine.api.model.Permissions) Permission(org.ovirt.engine.api.model.Permission)

Example 2 with Permission

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

the class CompletenessAssertorTest method testMissingBothAlternatives.

@Test
public void testMissingBothAlternatives() throws Exception {
    Permission permission = new Permission();
    permission.setVm(new Vm());
    try {
        CompletenessAssertor.validateParameters(permission, "user|vm.name|id");
        fail("expected WebApplicationException on incomplete model");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Permission", "user|vm.name|id");
    }
}
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)

Example 3 with Permission

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

the class BackendUserAssignedPermissionsResourceTest method testAddIncompletePermission.

@Test
public void testAddIncompletePermission() throws Exception {
    Permission model = new Permission();
    model.setUser(new User());
    model.getUser().setId(GUIDS[1].toString());
    model.setRole(new Role());
    model.getRole().setId(GUIDS[3].toString());
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Permission", "add", "dataCenter|cluster|host|storageDomain|vm|vmPool|template.id");
    }
}
Also used : Role(org.ovirt.engine.api.model.Role) User(org.ovirt.engine.api.model.User) WebApplicationException(javax.ws.rs.WebApplicationException) Permission(org.ovirt.engine.api.model.Permission) Test(org.junit.Test)

Example 4 with Permission

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

the class BackendEntityAssignedPermissionsResourceTest method testAddIncompletePermission.

@Test
public void testAddIncompletePermission() throws Exception {
    Permission model = new Permission();
    model.setDataCenter(new DataCenter());
    model.getDataCenter().setId(GUIDS[2].toString());
    model.setRole(new Role());
    model.getRole().setId(GUIDS[3].toString());
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Permission", "add", "user|group.id");
    }
}
Also used : Role(org.ovirt.engine.api.model.Role) DataCenter(org.ovirt.engine.api.model.DataCenter) WebApplicationException(javax.ws.rs.WebApplicationException) Permission(org.ovirt.engine.api.model.Permission) Test(org.junit.Test)

Example 5 with Permission

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

the class BackendEntityAssignedPermissionsResourceTest method testAddGroupPermission.

@Test
public void testAddGroupPermission() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpCreationExpectations(ActionType.AddPermission, PermissionsOperationsParameters.class, new String[] { "Group.Id", "Permission.AdElementId", "Permission.ObjectId", "Permission.RoleId" }, new Object[] { GUIDS[1], GUIDS[1], targetId, GUIDS[3] }, true, true, GUIDS[0], QueryType.GetPermissionById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Permission model = new Permission();
    model.setRole(new Role());
    model.getRole().setId(GUIDS[3].toString());
    model.setGroup(new Group());
    model.getGroup().setId(GUIDS[1].toString());
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Permission);
    verifyModel((Permission) response.getEntity(), 0);
}
Also used : Role(org.ovirt.engine.api.model.Role) Response(javax.ws.rs.core.Response) Group(org.ovirt.engine.api.model.Group) 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