Search in sources :

Example 1 with Role

use of com.bakdata.conquery.models.auth.entities.Role in project conquery by bakdata.

the class PermissionRoleHandlingTest method execute.

/**
 * This is a longer test that plays through different scenarios of permission
 * and role adding/deleting. Creating many objects here to avoid side effects.
 */
@Override
public void execute(StandaloneSupport conquery) throws Exception {
    MetaStorage storage = conquery.getMetaStorage();
    Role mandator1 = new Role("company", "company", storage);
    TestUser user1 = new TestUser(storage);
    Dataset dataset = conquery.getDataset();
    try {
        storage.addRole(mandator1);
        storage.addUser(user1);
        user1.addRole(mandator1);
        user1.addPermission(dataset.createPermission(Ability.READ.asSet()));
        mandator1.addPermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
        assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isTrue();
        // Delete permission from mandator
        mandator1.removePermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
        assertThat(mandator1.getPermissions()).isEmpty();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
        // Add permission to user
        user1.addPermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
        assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isTrue();
        // Delete permission from mandator
        user1.removePermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
        assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
        // Add permission to mandator, remove mandator from user
        mandator1.addPermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
        user1.removeRole(mandator1);
        assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
        // Add mandator back to user
        user1.addRole(mandator1);
        assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isTrue();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isTrue();
        // Delete all permissions from mandator and user
        user1.removePermission(dataset.createPermission(Ability.READ.asSet()));
        mandator1.removePermission(dataset.createPermission(Ability.DOWNLOAD.asSet()));
        assertThat(user1.isPermitted(dataset.createPermission(Ability.READ.asSet()))).isFalse();
        assertThat(user1.isPermitted(dataset.createPermission(Ability.DOWNLOAD.asSet()))).isFalse();
    } finally {
        storage.removeUser(user1.getId());
        storage.removeRole(mandator1.getId());
    }
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) Dataset(com.bakdata.conquery.models.datasets.Dataset)

Example 2 with Role

use of com.bakdata.conquery.models.auth.entities.Role in project conquery by bakdata.

the class RoleHandlingTest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    Dataset dataset1 = new Dataset();
    dataset1.setLabel("dataset1");
    MetaStorage storage = conquery.getMetaStorage();
    Role mandator1 = new Role("company", "company", storage);
    Role mandator1Copy = new Role("company", "company", storage);
    Role mandator2 = new Role("company2", "company2", storage);
    User user1 = new User("user", "user", storage);
    try {
        storage.addRole(mandator1);
        storage.addRole(mandator2);
        storage.addUser(user1);
        // // ADDING
        user1.addRole(mandator1);
        assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId());
        user1.addRole(mandator1Copy);
        assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId());
        user1.addRole(mandator2);
        assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId(), mandator2.getId());
        // // REMOVING
        user1.removeRole(mandator2);
        assertThat(user1.getRoles()).containsExactlyInAnyOrder(mandator1.getId());
        user1.removeRole(mandator1);
        assertThat(user1.getRoles()).isEmpty();
    } finally {
        storage.removeUser(user1.getId());
        storage.removeRole(mandator1.getId());
        storage.removeRole(mandator2.getId());
    }
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) User(com.bakdata.conquery.models.auth.entities.User) Dataset(com.bakdata.conquery.models.datasets.Dataset) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage)

Example 3 with Role

use of com.bakdata.conquery.models.auth.entities.Role in project conquery by bakdata.

the class RoleUITest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    MetaStorage storage = conquery.getMetaStorage();
    Role mandator = new Role("testMandatorName", "testMandatorLabel", storage);
    RoleId mandatorId = mandator.getId();
    User user = new User("testUser@test.de", "testUserName", storage);
    UserId userId = user.getId();
    try {
        ConqueryPermission permission = DatasetPermission.onInstance(Ability.READ.asSet(), new DatasetId("testDatasetId"));
        storage.addRole(mandator);
        storage.addUser(user);
        // override permission object, because it might have changed by the subject
        // owning the permission
        mandator.addPermission(permission);
        user.addRole(mandator);
        URI classBase = HierarchyHelper.hierarchicalPath(conquery.defaultAdminURIBuilder(), RoleUIResource.class, "getRole").buildFromMap(Map.of(ROLE_ID, mandatorId.toString()));
        Response response = conquery.getClient().target(classBase).request().get();
        assertThat(response.getStatus()).isEqualTo(200);
        // Check for Freemarker Errors
        assertThat(response.readEntity(String.class).toLowerCase()).doesNotContain(List.of("freemarker", "debug"));
    } finally {
        storage.removeRole(mandatorId);
        storage.removeUser(userId);
    }
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Response(javax.ws.rs.core.Response) ConqueryPermission(com.bakdata.conquery.models.auth.permissions.ConqueryPermission) User(com.bakdata.conquery.models.auth.entities.User) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) RoleUIResource(com.bakdata.conquery.resources.admin.ui.RoleUIResource) RoleId(com.bakdata.conquery.models.identifiable.ids.specific.RoleId) URI(java.net.URI) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)

Example 4 with Role

use of com.bakdata.conquery.models.auth.entities.Role in project conquery by bakdata.

the class SuperPermissionTest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    Dataset dataset1 = new Dataset();
    dataset1.setLabel("dataset1");
    MetaStorage storage = conquery.getMetaStorage();
    Role role1 = new Role("company", "company", storage);
    TestUser user1 = new TestUser(storage);
    storage.addRole(role1);
    try {
        user1.addRole(role1);
        // Add SuperPermission to User
        user1.addPermission(SuperPermission.onDomain());
        assertThat(user1.isPermitted(DatasetPermission.onInstance(Ability.READ, dataset1.getId()))).isTrue();
        assertThat(user1.isPermitted(DatasetPermission.onInstance(Ability.DOWNLOAD, dataset1.getId()))).isTrue();
        // Add SuperPermission to mandator and remove from user
        user1.removePermission(SuperPermission.onDomain());
        role1.addPermission(SuperPermission.onDomain());
        assertThat(user1.isPermitted(DatasetPermission.onInstance(Ability.READ, dataset1.getId()))).isTrue();
        assertThat(user1.isPermitted(DatasetPermission.onInstance(Ability.DOWNLOAD, dataset1.getId()))).isTrue();
        // Add SuperPermission to mandator and remove from user
        role1.removePermission(SuperPermission.onDomain());
        assertThat(user1.isPermitted(DatasetPermission.onInstance(Ability.READ, dataset1.getId()))).isFalse();
        assertThat(user1.isPermitted(DatasetPermission.onInstance(Ability.DOWNLOAD, dataset1.getId()))).isFalse();
    } finally {
        storage.removeUser(user1.getId());
        storage.removeRole(role1.getId());
    }
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Dataset(com.bakdata.conquery.models.datasets.Dataset) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage)

Example 5 with Role

use of com.bakdata.conquery.models.auth.entities.Role in project conquery by bakdata.

the class SerializationTests method role.

@Test
public void role() throws IOException, JSONException {
    Role mandator = new Role("company", "company", STORAGE);
    SerializationTestUtil.forType(Role.class).injectables(STORAGE).test(mandator);
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Aggregations

Role (com.bakdata.conquery.models.auth.entities.Role)13 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)8 User (com.bakdata.conquery.models.auth.entities.User)8 Group (com.bakdata.conquery.models.auth.entities.Group)6 Dataset (com.bakdata.conquery.models.datasets.Dataset)6 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)6 Test (org.junit.jupiter.api.Test)4 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)3 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)3 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)2 RoleId (com.bakdata.conquery.models.identifiable.ids.specific.RoleId)2 DatasetRegistry (com.bakdata.conquery.models.worker.DatasetRegistry)2 ManagerNode (com.bakdata.conquery.commands.ManagerNode)1 ConqueryTestSpec (com.bakdata.conquery.integration.json.ConqueryTestSpec)1 NamespaceStorage (com.bakdata.conquery.io.storage.NamespaceStorage)1 ConqueryPermission (com.bakdata.conquery.models.auth.permissions.ConqueryPermission)1 DatasetPermission (com.bakdata.conquery.models.auth.permissions.DatasetPermission)1 UserId (com.bakdata.conquery.models.identifiable.ids.specific.UserId)1 EntityIdMap (com.bakdata.conquery.models.identifiable.mapping.EntityIdMap)1 AdminDatasetProcessor (com.bakdata.conquery.resources.admin.rest.AdminDatasetProcessor)1