Search in sources :

Example 21 with User

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

the class JwtPkceVerifyingRealmTest method verifyTokenAlternativeId.

@Test
void verifyTokenAlternativeId() {
    // Setup the expected user id
    User expected = new User("Test", "Test", STORAGE);
    STORAGE.updateUser(expected);
    Date issueDate = new Date();
    Date expDate = DateUtils.addMinutes(issueDate, 1);
    final String primId = UUID.randomUUID().toString();
    String token = JWT.create().withIssuer(HTTP_REALM_URL).withAudience(AUDIENCE).withSubject(primId).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).withClaim(ALTERNATIVE_ID_CLAIM, expected.getName()).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
    BearerToken accessToken = new BearerToken(token);
    assertThat(REALM.doGetAuthenticationInfo(accessToken).getPrincipals().getPrimaryPrincipal()).isEqualTo(expected);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) BearerToken(org.apache.shiro.authc.BearerToken) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 22 with User

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

the class PermissionCleanupTaskTest method doDeletePermissionsOfOwnedReference.

@Test
void doDeletePermissionsOfOwnedReference() {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    // Created owned execution
    final ManagedQuery managedQueryOwned = createManagedQuery();
    // Setup user
    User user = new User("test", "test", STORAGE);
    User user2 = new User("test2", "test2", STORAGE);
    STORAGE.updateUser(user);
    user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managedQueryOwned.getId()));
    managedQueryOwned.setOwner(user);
    STORAGE.updateExecution(managedQueryOwned);
    // Created not owned execution
    final ManagedQuery managedQueryNotOwned = createManagedQuery();
    // Setup user
    user.addPermission(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
    // Set owner
    managedQueryNotOwned.setOwner(user2);
    STORAGE.updateExecution(managedQueryNotOwned);
    deletePermissionsOfOwnedInstances(STORAGE, ExecutionPermission.DOMAIN.toLowerCase(), ManagedExecutionId.Parser.INSTANCE, STORAGE::getExecution);
    assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Test(org.junit.jupiter.api.Test)

Example 23 with User

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

the class PermissionCleanupTaskTest method doDeletePartialPermissionWithInvalidReference.

@Test
void doDeletePartialPermissionWithInvalidReference() {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    final ManagedQuery managedQuery1 = createManagedQuery();
    final ManagedQuery managedQuery2 = createManagedQuery();
    // Removing the second execution
    STORAGE.removeExecution(managedQuery2.getId());
    User user = new User("test", "test", STORAGE);
    STORAGE.updateUser(user);
    user.addPermission(// Build a permission with multiple instances
    new WildcardPermission(List.of(Set.of(ExecutionPermission.DOMAIN), Set.of(Ability.READ.toString().toLowerCase()), Set.of(managedQuery1.getId().toString(), managedQuery2.getId().toString())), Instant.now()));
    deleteQueryPermissionsWithMissingRef(STORAGE, STORAGE.getAllUsers());
    assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQuery1.getId()));
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) WildcardPermission(com.bakdata.conquery.models.auth.permissions.WildcardPermission) Test(org.junit.jupiter.api.Test)

Example 24 with User

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

the class PermissionCleanupTaskTest method doDeletePermissionInvalidReference.

@Test
void doDeletePermissionInvalidReference() {
    assertThat(STORAGE.getAllExecutions()).isEmpty();
    final ManagedQuery managedQuery = createManagedQuery();
    // Removing the execution
    STORAGE.removeExecution(managedQuery.getId());
    User user = new User("test", "test", STORAGE);
    STORAGE.updateUser(user);
    user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managedQuery.getId()));
    deleteQueryPermissionsWithMissingRef(STORAGE, STORAGE.getAllUsers());
    assertThat(user.getPermissions()).isEmpty();
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Test(org.junit.jupiter.api.Test)

Example 25 with User

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

the class IdRefrenceTest method testListReferences.

@Test
public void testListReferences() throws IOException {
    CentralRegistry registry = new CentralRegistry();
    Dataset dataset = new Dataset();
    dataset.setName("dataset");
    Table table = new Table();
    table.setDataset(dataset);
    table.setName("table");
    registry.register(dataset);
    registry.register(table);
    final CentralRegistry metaRegistry = new CentralRegistry();
    User user = new User("usermail", "userlabel", mock(MetaStorage.class));
    metaRegistry.register(user);
    String json = Jackson.MAPPER.writeValueAsString(new ListHolder(Collections.singletonList(table), Collections.singletonList(user)));
    assertThat(json).contains("\"user.usermail\"").contains("\"dataset.table\"");
    ListHolder holder = new SingletonNamespaceCollection(registry, metaRegistry).injectIntoNew(Jackson.MAPPER.readerFor(ListHolder.class)).readValue(json);
    assertThat(holder.getUsers().get(0)).isSameAs(user);
    assertThat(holder.getTables().get(0)).isSameAs(table);
}
Also used : Table(com.bakdata.conquery.models.datasets.Table) User(com.bakdata.conquery.models.auth.entities.User) Dataset(com.bakdata.conquery.models.datasets.Dataset) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) SingletonNamespaceCollection(com.bakdata.conquery.models.worker.SingletonNamespaceCollection) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Test(org.junit.jupiter.api.Test)

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