Search in sources :

Example 31 with User

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

the class UserAuthenticationManagementProcessor method updateUser.

public boolean updateUser(ProtoUser pUser) {
    final User user = pUser.createOrOverwriteUser(storage);
    AuthorizationHelper.registerForAuthentication(realm, user, pUser.getCredentials(), false);
    return true;
}
Also used : ProtoUser(com.bakdata.conquery.apiv1.auth.ProtoUser) User(com.bakdata.conquery.models.auth.entities.User)

Example 32 with User

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

the class ApiTokenRealm method doGetAuthenticationInfo.

@Override
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if (!(token instanceof ApiToken)) {
        return null;
    }
    final ApiToken apiToken = ((ApiToken) token);
    ApiTokenHash tokenHash = apiToken.hashToken();
    // Clear the token
    apiToken.clear();
    ApiTokenData tokenData = tokenStorage.get(tokenHash);
    if (tokenData == null) {
        log.trace("Unknown token, cannot map token hash to token data. Aborting authentication");
        throw new IncorrectCredentialsException();
    }
    if (LocalDate.now().isAfter(tokenData.getExpirationDate())) {
        log.info("Supplied token expired on: {}", tokenData.getExpirationDate());
        throw new ExpiredCredentialsException("Supplied token is expired");
    }
    final ApiTokenData.MetaData metaData = new ApiTokenData.MetaData(LocalDate.now());
    tokenStorage.updateMetaData(tokenData.getId(), metaData);
    final UserId userId = tokenData.getUserId();
    final User user = storage.getUser(userId);
    if (user == null) {
        throw new UnknownAccountException("The UserId does not map to a user: " + userId);
    }
    return new ConqueryAuthenticationInfo(new TokenScopedUser(user, tokenData), token, this, false);
}
Also used : IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) User(com.bakdata.conquery.models.auth.entities.User) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) UnknownAccountException(org.apache.shiro.authc.UnknownAccountException) ConqueryAuthenticationInfo(com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo) ExpiredCredentialsException(org.apache.shiro.authc.ExpiredCredentialsException)

Example 33 with User

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

the class DefaultInitialUserRealm method doGetAuthenticationInfo.

@Override
public ConqueryAuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if (!(token instanceof DevelopmentToken)) {
        return null;
    }
    DevelopmentToken devToken = (DevelopmentToken) token;
    final User user = getUserOrThrowUnknownAccount(storage, devToken.getPrincipal());
    return new ConqueryAuthenticationInfo(user, devToken.getCredentials(), this, true);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) ConqueryAuthenticationInfo(com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo)

Example 34 with User

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

the class DevAuthConfig method createRealm.

@Override
public ConqueryAuthenticationRealm createRealm(ManagerNode managerNode) {
    User defaultUser = managerNode.getConfig().getAuthorizationRealms().getInitialUsers().get(0).createOrOverwriteUser(managerNode.getStorage());
    managerNode.getAuthController().getAuthenticationFilter().registerTokenExtractor(new UserIdTokenExtractor(defaultUser));
    return new DefaultInitialUserRealm(managerNode.getStorage());
}
Also used : User(com.bakdata.conquery.models.auth.entities.User)

Example 35 with User

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

the class SerializingStoreDumpTest method testCorruptValueDump.

/**
 * Tests if entries with corrupted values are dumped.
 */
@Test
public void testCorruptValueDump() throws IOException {
    // Set dump directory to this tests temp-dir
    config.setUnreadableDataDumpDirectory(tmpDir);
    {
        // Open a store and insert a valid key-value pair (UserId & User)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        store.add(user.getId(), user);
    }
    {
        // Open that store again, with a different config to insert a corrupt entry
        // (UserId & ManagedQuery)
        SerializingStore<UserId, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), UserId.class, QueryDescription.class));
        store.add(new UserId("testU2"), cQuery);
    }
    {
        // Reopen the store with the initial value and try to iterate over all entries
        // (this triggers the dump or removal of invalid entries)
        SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
        IterationStatistic expectedResult = new IterationStatistic();
        expectedResult.setTotalProcessed(2);
        expectedResult.setFailedKeys(0);
        expectedResult.setFailedValues(1);
        // Iterate (do nothing with the entries themselves)
        IterationStatistic result = store.forEach((k, v, s) -> {
        });
        assertThat(result).isEqualTo(expectedResult);
    }
    // Test if the correct number of dumpfiles was generated
    Condition<File> dumpFileCond = new Condition<>(f -> f.getName().endsWith(SerializingStore.DUMP_FILE_EXTENTION), "dump file");
    assertThat(tmpDir.listFiles()).areExactly(1, dumpFileCond);
    // Test if the dump is correct
    File dumpFile = getDumpFile(dumpFileCond);
    assertThat((QueryDescription) Jackson.MAPPER.readerFor(QueryDescription.class).readValue(dumpFile)).isEqualTo(cQuery);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Validators(io.dropwizard.jersey.validation.Validators) Environments(jetbrains.exodus.env.Environments) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) Environment(jetbrains.exodus.env.Environment) Files(com.google.common.io.Files) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) Validator(javax.validation.Validator) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) User(com.bakdata.conquery.models.auth.entities.User) File(java.io.File) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Slf4j(lombok.extern.slf4j.Slf4j) AfterEach(org.junit.jupiter.api.AfterEach) Condition(org.assertj.core.api.Condition) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) Jackson(com.bakdata.conquery.io.jackson.Jackson) XodusStoreFactory(com.bakdata.conquery.models.config.XodusStoreFactory) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Condition(org.assertj.core.api.Condition) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) File(java.io.File) 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