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