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