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);
}
}
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());
}
}
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());
}
}
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);
}
}
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());
}
}
Aggregations