use of org.finos.legend.engine.plan.execution.stores.relational.connection.ds.state.IdentityState in project legend-engine by finos.
the class DataSourceSpecification method getConnectionUsingIdentity.
public Connection getConnectionUsingIdentity(Identity identity, Optional<CredentialSupplier> databaseCredentialSupplierHolder) {
Optional<LegendKerberosCredential> kerberosCredentialHolder = identity.getCredential(LegendKerberosCredential.class);
Supplier<DataSource> dataSourceBuilder;
if (kerberosCredentialHolder.isPresent()) {
dataSourceBuilder = () -> KerberosUtils.doAs(identity, (PrivilegedAction<DataSource>) () -> this.buildDataSource(identity));
} else {
dataSourceBuilder = () -> this.buildDataSource(identity);
}
return getConnection(new IdentityState(identity, databaseCredentialSupplierHolder), dataSourceBuilder);
}
use of org.finos.legend.engine.plan.execution.stores.relational.connection.ds.state.IdentityState in project legend-engine by finos.
the class UserNamePasswordAuthenticationStrategy method handleConnection.
@Override
public Pair<String, Properties> handleConnection(String url, Properties properties, DatabaseManager databaseManager) {
Properties connectionProperties = new Properties();
connectionProperties.putAll(properties);
IdentityState identityState = ConnectionStateManager.getInstance().getIdentityStateUsing(properties);
PlaintextUserPasswordCredential credential = (PlaintextUserPasswordCredential) getDatabaseCredential(identityState);
connectionProperties.put("user", credential.getUser());
connectionProperties.put("password", credential.getPassword());
return Tuples.pair(url, connectionProperties);
}
use of org.finos.legend.engine.plan.execution.stores.relational.connection.ds.state.IdentityState in project legend-engine by finos.
the class TestConnectionState method connectionStateCreation.
@Test
public void connectionStateCreation() throws Exception {
Identity identity = IdentityFactoryProvider.getInstance().makeIdentityForTesting("testuser1");
// User gets connection to db1
RelationalDatabaseConnection database1 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db1");
this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// verify connection state for user1 exists
String poolName = String.format("DBPool_Static_host:127.0.0.1_port:%d_db:db1_type:TestDB_testuser1_org.finos.legend.engine.shared.core.identity.credential.AnonymousCredential", server.getPort());
IdentityState identityState = ConnectionStateManager.getInstance().getConnectionStateManagerPOJO(poolName);
assertEquals("testuser1", identityState.getIdentity().getName());
assertNotNull(identityState.getCredentialSupplier());
}
use of org.finos.legend.engine.plan.execution.stores.relational.connection.ds.state.IdentityState in project legend-engine by finos.
the class TestConnectionState method connectionStateUpdate.
@Test
public void connectionStateUpdate() throws Exception {
Identity identity = IdentityFactoryProvider.getInstance().makeIdentityForTesting("testuser1");
// User gets connection to db1
RelationalDatabaseConnection database1 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db1");
this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// verify connection state for user1 exists
String poolName = String.format("DBPool_Static_host:127.0.0.1_port:%d_db:db1_type:TestDB_testuser1_org.finos.legend.engine.shared.core.identity.credential.AnonymousCredential", server.getPort());
DataSourceWithStatistics identityState1 = ConnectionStateManager.getInstance().getDataSourceByPoolName(poolName);
assertEquals("testuser1", identityState1.getIdentity().getName());
assertNotNull(identityState1.getCredentialSupplier());
// User gets another connection to db1
this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// verify connection state for user1 exists
IdentityState identityState2 = ConnectionStateManager.getInstance().getConnectionStateManagerPOJO(poolName);
assertEquals("testuser1", identityState2.getIdentity().getName());
assertNotNull(identityState2.getCredentialSupplier());
// Verify connection state has been reset
assertNotSame("expected distinct state objects but got the same one", identityState1, identityState2);
}
use of org.finos.legend.engine.plan.execution.stores.relational.connection.ds.state.IdentityState in project legend-engine by finos.
the class TestConnectionState method connectionStateReset.
@Test
public void connectionStateReset() throws Exception {
Identity identity = IdentityFactoryProvider.getInstance().makeIdentityForTesting("testuser1");
// User gets connection to db1
RelationalDatabaseConnection database1 = buildStaticDatabaseSpec("127.0.0.1", server.getPort(), "db1");
Connection connection = this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// verify connection state for user1 exists
String poolName = String.format("DBPool_Static_host:127.0.0.1_port:%d_db:db1_type:TestDB_testuser1_org.finos.legend.engine.shared.core.identity.credential.AnonymousCredential", server.getPort());
IdentityState identityState1 = ConnectionStateManager.getInstance().getConnectionStateManagerPOJO(poolName);
assertEquals("testuser1", identityState1.getIdentity().getName());
assertNotNull(identityState1.getCredentialSupplier());
connection.close();
// Reset connection state - This simulates a case where the state manager evicts state objects
ConnectionStateManager.getInstance().evictUnusedPoolsOlderThan(Duration.ofMillis(1));
IdentityState identityState = ConnectionStateManager.getInstance().getConnectionStateManagerPOJO(poolName);
assertNull(identityState);
// User gets another connection to db1
this.connectionManagerSelector.getDatabaseConnection(identity, database1);
// Verify new connection state has been created for user
IdentityState identityState2 = ConnectionStateManager.getInstance().getConnectionStateManagerPOJO(poolName);
assertEquals("testuser1", identityState2.getIdentity().getName());
assertNotNull(identityState2.getCredentialSupplier());
assertNotSame("expected distinct state objects but got the same one", identityState1, identityState2);
}
Aggregations