Search in sources :

Example 1 with User

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

the class FormConfigProcessor method deleteConfig.

/**
 * Deletes a configuration from the storage and all permissions, that have this configuration as target.
 */
public void deleteConfig(Subject subject, FormConfig config) {
    User user = storage.getUser(subject.getId());
    user.authorize(config, Ability.DELETE);
    storage.removeFormConfig(config.getId());
    // Delete corresponding permissions (Maybe better to put it into a slow job)
    for (ConqueryPermission permission : user.getPermissions()) {
        WildcardPermission wpermission = (WildcardPermission) permission;
        if (!wpermission.getDomains().contains(FormConfigPermission.DOMAIN.toLowerCase())) {
            continue;
        }
        if (!wpermission.getInstances().contains(config.getId().toString().toLowerCase())) {
            continue;
        }
        if (!wpermission.getInstances().isEmpty()) {
            // Create new permission if it was a composite permission
            Set<String> instancesCleared = new HashSet<>(wpermission.getInstances());
            instancesCleared.remove(config.getId().toString());
            WildcardPermission clearedPermission = new WildcardPermission(List.of(wpermission.getDomains(), wpermission.getAbilities(), instancesCleared), Instant.now());
            user.addPermission(clearedPermission);
        }
        user.removePermission(wpermission);
    }
}
Also used : ConqueryPermission(com.bakdata.conquery.models.auth.permissions.ConqueryPermission) User(com.bakdata.conquery.models.auth.entities.User) WildcardPermission(com.bakdata.conquery.models.auth.permissions.WildcardPermission) HashSet(java.util.HashSet)

Example 2 with User

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

the class GroupHandlingTest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    MetaStorage storage = conquery.getMetaStorage();
    Group group1 = new Group("company", "company", storage);
    User user1 = new User("user", "user", storage);
    User user1copy = new User("user", "user", storage);
    User user2 = new User("user2", "user2", storage);
    try {
        storage.addGroup(group1);
        storage.addUser(user1);
        group1.addMember(user1);
        group1.addMember(user1copy);
        assertThat(group1.getMembers()).containsExactlyInAnyOrder(user1.getId());
        group1.addMember(user2);
        assertThat(group1.getMembers()).containsExactlyInAnyOrder(user1.getId(), user2.getId());
        group1.removeMember(user2);
        assertThat(group1.getMembers()).containsExactlyInAnyOrder(user1.getId());
    } finally {
        storage.removeUser(user1.getId());
        storage.removeUser(user2.getId());
        storage.removeGroup(group1.getId());
    }
}
Also used : Group(com.bakdata.conquery.models.auth.entities.Group) User(com.bakdata.conquery.models.auth.entities.User) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage)

Example 3 with User

use of com.bakdata.conquery.models.auth.entities.User 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 4 with User

use of com.bakdata.conquery.models.auth.entities.User 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 5 with User

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

the class ConceptPermissionTest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    final MetaStorage storage = conquery.getMetaStorage();
    final Dataset dataset = conquery.getDataset();
    final String testJson = In.resource("/tests/query/SIMPLE_TREECONCEPT_QUERY/SIMPLE_TREECONCEPT_Query.test.json").withUTF8().readAll();
    final QueryTest test = (QueryTest) JsonIntegrationTest.readJson(dataset.getId(), testJson);
    final QueryProcessor processor = new QueryProcessor(conquery.getDatasetRegistry(), storage, conquery.getConfig());
    final User user = new User("testUser", "testUserLabel", storage);
    // Manually import data, so we can do our own work.
    {
        ValidatorHelper.failOnError(log, conquery.getValidator().validate(test));
        importSecondaryIds(conquery, test.getContent().getSecondaryIds());
        conquery.waitUntilWorkDone();
        LoadingUtil.importTables(conquery, test.getContent().getTables());
        conquery.waitUntilWorkDone();
        LoadingUtil.importConcepts(conquery, test.getRawConcepts());
        conquery.waitUntilWorkDone();
        LoadingUtil.importTableContents(conquery, test.getContent().getTables());
        conquery.waitUntilWorkDone();
        storage.addUser(user);
        user.addPermission(DatasetPermission.onInstance(Ability.READ, dataset.getId()));
    }
    // Query cannot be deserialized without Namespace set up
    final Query query = IntegrationUtils.parseQuery(conquery, test.getRawQuery());
    // Id of the lone concept that is used in the test.
    Concept<?> conceptId = conquery.getNamespace().getStorage().getAllConcepts().iterator().next();
    IntegrationUtils.assertQueryResult(conquery, query, -1, ExecutionState.FAILED, user, 403);
    // Add the necessary Permission
    {
        final ConqueryPermission permission = conceptId.createPermission(Ability.READ.asSet());
        log.info("Adding the Permission[{}] to User[{}]", permission, user);
        user.addPermission(permission);
    }
    // Only assert permissions
    IntegrationUtils.assertQueryResult(conquery, query, -1, ExecutionState.DONE, user, 201);
    conquery.waitUntilWorkDone();
    // Clean up
    {
        storage.removeUser(user.getId());
    }
}
Also used : ConqueryPermission(com.bakdata.conquery.models.auth.permissions.ConqueryPermission) User(com.bakdata.conquery.models.auth.entities.User) Query(com.bakdata.conquery.apiv1.query.Query) QueryTest(com.bakdata.conquery.integration.json.QueryTest) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) Dataset(com.bakdata.conquery.models.datasets.Dataset) QueryProcessor(com.bakdata.conquery.apiv1.QueryProcessor)

Aggregations

User (com.bakdata.conquery.models.auth.entities.User)49 Test (org.junit.jupiter.api.Test)17 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)14 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)14 Dataset (com.bakdata.conquery.models.datasets.Dataset)11 UserId (com.bakdata.conquery.models.identifiable.ids.specific.UserId)10 Group (com.bakdata.conquery.models.auth.entities.Group)8 Role (com.bakdata.conquery.models.auth.entities.Role)8 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)8 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)7 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)5 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)5 ConqueryAuthenticationInfo (com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo)5 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ConqueryPermission (com.bakdata.conquery.models.auth.permissions.ConqueryPermission)4 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)4 Slf4j (lombok.extern.slf4j.Slf4j)4 Query (com.bakdata.conquery.apiv1.query.Query)3 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)3