Search in sources :

Example 1 with DatabaseAuthenticationFlowProvider

use of org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider in project legend-engine by finos.

the class RelationalStoreExecutorBuilder method build.

@Override
public StoreExecutor build(StoreExecutorConfiguration storeExecutorConfiguration) {
    if (!(storeExecutorConfiguration instanceof RelationalExecutionConfiguration)) {
        String message = String.format("Invalid argument. Expected %s but found %s", RelationalExecutionConfiguration.class.getCanonicalName(), storeExecutorConfiguration.getClass().getCanonicalName());
        throw new RuntimeException(message);
    }
    RelationalExecutionConfiguration relationalExecutionConfiguration = (RelationalExecutionConfiguration) storeExecutorConfiguration;
    if (relationalExecutionConfiguration.tempPath == null) {
        relationalExecutionConfiguration.tempPath = DEFAULT_TEMP_PATH;
    }
    if (relationalExecutionConfiguration.temporarytestdb == null) {
        relationalExecutionConfiguration.temporarytestdb = new TemporaryTestDbConfiguration(DEFAULT_PORT);
    }
    Optional<DatabaseAuthenticationFlowProvider> flowProviderHolder = this.configureDatabaseAuthenticationFlowProvider(relationalExecutionConfiguration);
    RelationalStoreState state = new RelationalStoreState(relationalExecutionConfiguration.temporarytestdb, relationalExecutionConfiguration, flowProviderHolder);
    return new RelationalStoreExecutor(state);
}
Also used : RelationalExecutionConfiguration(org.finos.legend.engine.plan.execution.stores.relational.config.RelationalExecutionConfiguration) TemporaryTestDbConfiguration(org.finos.legend.engine.plan.execution.stores.relational.config.TemporaryTestDbConfiguration) DatabaseAuthenticationFlowProvider(org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider)

Example 2 with DatabaseAuthenticationFlowProvider

use of org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider in project legend-engine by finos.

the class RelationalStoreExecutorBuilder method configureDatabaseAuthenticationFlowProvider.

private Optional<DatabaseAuthenticationFlowProvider> configureDatabaseAuthenticationFlowProvider(RelationalExecutionConfiguration relationalExecutionConfig) {
    if (relationalExecutionConfig == null) {
        return Optional.empty();
    }
    Class<? extends DatabaseAuthenticationFlowProvider> flowProviderClass = relationalExecutionConfig.getFlowProviderClass();
    DatabaseAuthenticationFlowProviderConfiguration flowProviderConfiguration = relationalExecutionConfig.getFlowProviderConfiguration();
    if (flowProviderClass == null) {
        // TODO : Implement more strict validation when the flow provider feature is fully rolled out
        return Optional.empty();
    }
    Optional<DatabaseAuthenticationFlowProvider> flowProviderHolder = DatabaseAuthenticationFlowProviderSelector.getProvider(flowProviderClass.getCanonicalName());
    DatabaseAuthenticationFlowProvider flowProvider = flowProviderHolder.orElseThrow(() -> new RuntimeException(String.format("Database authentication provider not found in the classpath. Provider class-%s", flowProviderClass.getCanonicalName())));
    if (flowProviderConfiguration != null) {
        flowProvider.configure(flowProviderConfiguration);
    }
    return Optional.of(flowProvider);
}
Also used : DatabaseAuthenticationFlowProviderConfiguration(org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProviderConfiguration) DatabaseAuthenticationFlowProvider(org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider)

Example 3 with DatabaseAuthenticationFlowProvider

use of org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider in project legend-engine by finos.

the class RelationalStoreExecutorBuilder method build.

@Override
public RelationalStoreExecutor build() {
    TemporaryTestDbConfiguration temporaryTestDbConfiguration = new TemporaryTestDbConfiguration(DEFAULT_PORT);
    RelationalExecutionConfiguration relationalExecutionConfiguration = new RelationalExecutionConfiguration(DEFAULT_TEMP_PATH);
    Optional<DatabaseAuthenticationFlowProvider> flowProviderHolder = this.configureDatabaseAuthenticationFlowProvider(relationalExecutionConfiguration);
    RelationalStoreState state = new RelationalStoreState(temporaryTestDbConfiguration, relationalExecutionConfiguration, flowProviderHolder);
    return new RelationalStoreExecutor(state);
}
Also used : RelationalExecutionConfiguration(org.finos.legend.engine.plan.execution.stores.relational.config.RelationalExecutionConfiguration) TemporaryTestDbConfiguration(org.finos.legend.engine.plan.execution.stores.relational.config.TemporaryTestDbConfiguration) DatabaseAuthenticationFlowProvider(org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider)

Example 4 with DatabaseAuthenticationFlowProvider

use of org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider in project legend-engine by finos.

the class TestRelationalConnectionManager method testResolveEmptyCredentialForUnsupportedFlow.

@Test
public void testResolveEmptyCredentialForUnsupportedFlow() throws JsonProcessingException {
    String connectionStr = "{\n" + "  \"_type\": \"RelationalDatabaseConnection\",\n" + "  \"type\": \"H2\",\n" + "  \"authenticationStrategy\" : {\n" + "    \"_type\" : \"test\"\n" + "  },\n" + "  \"datasourceSpecification\" : {\n" + "    \"_type\" : \"static\",\n" + "    \"host\" : \"127.0.0.1\",\n" + "    \"port\" : \"111\"\n" + "  }\n" + "}";
    RelationalDatabaseConnection connectionSpec = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports().readValue(connectionStr, RelationalDatabaseConnection.class);
    DatabaseAuthenticationFlowProvider flowProvider = new NoOpFlowProvider();
    Identity identity = DefaultIdentityFactory.INSTANCE.makeUnknownIdentity();
    Optional<CredentialSupplier> credential = RelationalConnectionManager.getCredential(flowProvider, connectionSpec, identity);
    assertFalse(credential.isPresent());
}
Also used : CredentialSupplier(org.finos.legend.engine.authentication.credential.CredentialSupplier) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DatabaseAuthenticationFlowProvider(org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider) Identity(org.finos.legend.engine.shared.core.identity.Identity) Test(org.junit.Test)

Aggregations

DatabaseAuthenticationFlowProvider (org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider)4 RelationalExecutionConfiguration (org.finos.legend.engine.plan.execution.stores.relational.config.RelationalExecutionConfiguration)2 TemporaryTestDbConfiguration (org.finos.legend.engine.plan.execution.stores.relational.config.TemporaryTestDbConfiguration)2 CredentialSupplier (org.finos.legend.engine.authentication.credential.CredentialSupplier)1 DatabaseAuthenticationFlowProviderConfiguration (org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProviderConfiguration)1 RelationalDatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection)1 Identity (org.finos.legend.engine.shared.core.identity.Identity)1 Test (org.junit.Test)1