Search in sources :

Example 1 with CredentialSupplier

use of org.finos.legend.engine.authentication.credential.CredentialSupplier in project legend-engine by finos.

the class AuthenticationStrategy method getDatabaseCredential.

protected Credential getDatabaseCredential(IdentityState identityState) {
    try {
        Identity identity = identityState.getIdentity();
        CredentialSupplier credentialSupplier = identityState.getCredentialSupplier().get();
        return credentialSupplier.getCredential(identity);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CredentialSupplier(org.finos.legend.engine.authentication.credential.CredentialSupplier) Identity(org.finos.legend.engine.shared.core.identity.Identity) PrivilegedActionException(java.security.PrivilegedActionException) ConnectionException(org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionException)

Example 2 with CredentialSupplier

use of org.finos.legend.engine.authentication.credential.CredentialSupplier in project legend-engine by finos.

the class RelationalConnectionManager method getTestDatabaseConnection.

public Connection getTestDatabaseConnection() {
    // TODO : pass identity into this method
    RelationalDatabaseConnection testConnection = buildTestDatabaseDatasourceSpecification();
    Identity identity = IdentityFactoryProvider.getInstance().makeIdentity((Subject) null);
    Optional<CredentialSupplier> credentialHolder = RelationalConnectionManager.getCredential(flowProviderHolder, testConnection, identity);
    return this.getDataSourceSpecification(testConnection).getConnectionUsingIdentity(identity, credentialHolder);
}
Also used : CredentialSupplier(org.finos.legend.engine.authentication.credential.CredentialSupplier) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) Identity(org.finos.legend.engine.shared.core.identity.Identity)

Example 3 with CredentialSupplier

use of org.finos.legend.engine.authentication.credential.CredentialSupplier in project legend-engine by finos.

the class RelationalConnectionManager method getCredential.

public static Optional<CredentialSupplier> getCredential(DatabaseAuthenticationFlowProvider flowProvider, RelationalDatabaseConnection connection, Identity identity) {
    Optional<DatabaseAuthenticationFlow> flowHolder = flowProvider.lookupFlow(connection);
    if (!flowHolder.isPresent()) {
        /*
              When the flow feature is fully enabled, a missing flow is a bug and should be failed at runtime.
              Fow now, we are lenient and fallback to the existing implementation which uses identity directly.
            */
        String message = String.format("Database authentication flow feature has been enabled. But flow for DbType=%s, AuthType=%s has not been configured", connection.datasourceSpecification.getClass().getSimpleName(), connection.authenticationStrategy.getClass().getSimpleName());
        LOGGER.warn(message);
        return Optional.empty();
    }
    CredentialSupplier credentialSupplier = new CredentialSupplier(flowHolder.get(), connection.datasourceSpecification, connection.authenticationStrategy);
    return Optional.of(credentialSupplier);
}
Also used : DatabaseAuthenticationFlow(org.finos.legend.engine.authentication.DatabaseAuthenticationFlow) CredentialSupplier(org.finos.legend.engine.authentication.credential.CredentialSupplier)

Example 4 with CredentialSupplier

use of org.finos.legend.engine.authentication.credential.CredentialSupplier 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)

Example 5 with CredentialSupplier

use of org.finos.legend.engine.authentication.credential.CredentialSupplier in project legend-engine by finos.

the class ConnectionManagerSelector method getDatabaseConnectionImpl.

public Connection getDatabaseConnectionImpl(Identity identity, DatabaseConnection databaseConnection, DataSourceSpecification datasource) {
    if (databaseConnection instanceof RelationalDatabaseConnection) {
        RelationalDatabaseConnection relationalDatabaseConnection = (RelationalDatabaseConnection) databaseConnection;
        Optional<CredentialSupplier> databaseCredentialHolder = RelationalConnectionManager.getCredential(flowProviderHolder, relationalDatabaseConnection, identity);
        return datasource.getConnectionUsingIdentity(identity, databaseCredentialHolder);
    }
    /*
            In some cases, connection managers can return DatabaseConnections that are not RelationalDatabaseConnection.
            Without the metadata associated with a RelationalDatabaseConnection we cannot compute a credential.
        */
    return datasource.getConnectionUsingIdentity(identity, Optional.empty());
}
Also used : CredentialSupplier(org.finos.legend.engine.authentication.credential.CredentialSupplier) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection)

Aggregations

CredentialSupplier (org.finos.legend.engine.authentication.credential.CredentialSupplier)5 RelationalDatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection)3 Identity (org.finos.legend.engine.shared.core.identity.Identity)3 PrivilegedActionException (java.security.PrivilegedActionException)1 DatabaseAuthenticationFlow (org.finos.legend.engine.authentication.DatabaseAuthenticationFlow)1 DatabaseAuthenticationFlowProvider (org.finos.legend.engine.authentication.provider.DatabaseAuthenticationFlowProvider)1 ConnectionException (org.finos.legend.engine.plan.execution.stores.relational.connection.ConnectionException)1 Test (org.junit.Test)1