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