Search in sources :

Example 1 with Credential

use of org.finos.legend.engine.shared.core.identity.Credential in project legend-engine by finos.

the class TestConnectionStateManager method testPoolIdentityIsValid.

@Test
public void testPoolIdentityIsValid() {
    Credential mockCredential = mock(Credential.class);
    Identity identityOne = new Identity("mock", mockCredential);
    when(mockCredential.isValid()).thenReturn(true);
    DataSourceSpecification ds1 = buildLocalDataSourceSpecification(Collections.emptyList());
    String poolName = connectionStateManager.poolNameFor(identityOne, ds1.getConnectionKey());
    Assert.assertNotNull(poolName);
    requestConnection(identityOne, ds1);
    Assert.assertEquals(1, connectionStateManager.size());
    DataSourceWithStatistics dataSourceWithStatistics = connectionStateManager.get(poolName);
    requestConnection(identityOne, ds1);
    Assert.assertEquals(1, connectionStateManager.size());
    DataSourceWithStatistics dataSourceWithStatistics1 = connectionStateManager.get(poolName);
    Assert.assertEquals(dataSourceWithStatistics.getStatistics().getFirstConnectionRequest(), dataSourceWithStatistics1.getStatistics().getFirstConnectionRequest());
    // mock expiring of credentials
    when(mockCredential.isValid()).thenReturn(false);
    requestConnection(identityOne, ds1);
    Assert.assertEquals(1, connectionStateManager.size());
    DataSourceWithStatistics dataSourceWithStatisticsAfter = connectionStateManager.get(poolName);
    Assert.assertNotEquals(dataSourceWithStatistics.getStatistics().getFirstConnectionRequest(), dataSourceWithStatisticsAfter.getStatistics().getFirstConnectionRequest());
}
Also used : Credential(org.finos.legend.engine.shared.core.identity.Credential) DataSourceWithStatistics(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceWithStatistics) Identity(org.finos.legend.engine.shared.core.identity.Identity) DataSourceSpecification(org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceSpecification) Test(org.junit.Test)

Example 2 with Credential

use of org.finos.legend.engine.shared.core.identity.Credential in project legend-engine by finos.

the class TestBigQueryWithGCPApplicationDefaultCredentialsFlow method testFlow.

@Test
public void testFlow() throws Exception {
    BigQueryWithGCPApplicationDefaultCredentialsFlow flow = new BigQueryWithGCPApplicationDefaultCredentialsFlow();
    Credential credential = flow.makeCredential(identity1, new BigQueryDatasourceSpecification(), new GCPApplicationDefaultCredentialsAuthenticationStrategy());
    assertTrue(credential instanceof GCPApplicationDefaultCredential);
}
Also used : BigQueryDatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.BigQueryDatasourceSpecification) Credential(org.finos.legend.engine.shared.core.identity.Credential) GCPApplicationDefaultCredential(org.finos.legend.engine.shared.core.identity.credential.GCPApplicationDefaultCredential) GCPApplicationDefaultCredential(org.finos.legend.engine.shared.core.identity.credential.GCPApplicationDefaultCredential) GCPApplicationDefaultCredentialsAuthenticationStrategy(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.GCPApplicationDefaultCredentialsAuthenticationStrategy) Test(org.junit.Test)

Example 3 with Credential

use of org.finos.legend.engine.shared.core.identity.Credential in project legend-engine by finos.

the class DefaultIdentityFactory method adapt.

@Override
public List<CommonProfile> adapt(Identity identity) {
    MutableList<CommonProfile> profiles = Lists.mutable.empty();
    ImmutableList<Credential> credentials = identity.getCredentials();
    for (Credential credential : credentials) {
        if (credential instanceof LegendKerberosCredential) {
            LegendKerberosCredential kerberosCredential = (LegendKerberosCredential) credential;
            profiles.add(new KerberosProfile(kerberosCredential.getSubject(), null));
        }
    }
    return profiles;
}
Also used : LegendKerberosCredential(org.finos.legend.engine.shared.core.identity.credential.LegendKerberosCredential) Credential(org.finos.legend.engine.shared.core.identity.Credential) LegendKerberosCredential(org.finos.legend.engine.shared.core.identity.credential.LegendKerberosCredential) KerberosProfile(org.finos.legend.server.pac4j.kerberos.KerberosProfile) CommonProfile(org.pac4j.core.profile.CommonProfile)

Aggregations

Credential (org.finos.legend.engine.shared.core.identity.Credential)3 Test (org.junit.Test)2 DataSourceSpecification (org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceSpecification)1 DataSourceWithStatistics (org.finos.legend.engine.plan.execution.stores.relational.connection.ds.DataSourceWithStatistics)1 GCPApplicationDefaultCredentialsAuthenticationStrategy (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.GCPApplicationDefaultCredentialsAuthenticationStrategy)1 BigQueryDatasourceSpecification (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.BigQueryDatasourceSpecification)1 Identity (org.finos.legend.engine.shared.core.identity.Identity)1 GCPApplicationDefaultCredential (org.finos.legend.engine.shared.core.identity.credential.GCPApplicationDefaultCredential)1 LegendKerberosCredential (org.finos.legend.engine.shared.core.identity.credential.LegendKerberosCredential)1 KerberosProfile (org.finos.legend.server.pac4j.kerberos.KerberosProfile)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1