use of org.apache.calcite.avatica.ConnectionConfigImpl in project calcite-avatica by apache.
the class AvaticaHttpClientFactoryTest method testDefaultHttpClient.
@Test
public void testDefaultHttpClient() throws Exception {
Properties props = new Properties();
URL url = new URL("http://localhost:8765");
ConnectionConfig config = new ConnectionConfigImpl(props);
AvaticaHttpClientFactory httpClientFactory = new AvaticaHttpClientFactoryImpl();
AvaticaHttpClient client = httpClientFactory.getClient(url, config, null);
assertTrue("Client was an instance of " + client.getClass(), client instanceof AvaticaCommonsHttpClientImpl);
}
use of org.apache.calcite.avatica.ConnectionConfigImpl in project calcite-avatica by apache.
the class HttpServerSpnegoWithoutJaasTest method testAuthenticatedClientsAllowed.
@Test
public void testAuthenticatedClientsAllowed() throws Exception {
// Create the subject for the client
final Subject clientSubject = AvaticaJaasKrbUtil.loginUsingKeytab(SpnegoTestUtil.CLIENT_PRINCIPAL, clientKeytab);
final Set<Principal> clientPrincipals = clientSubject.getPrincipals();
// Make sure the subject has a principal
assertFalse(clientPrincipals.isEmpty());
// Get a TGT for the subject (might have many, different encryption types). The first should
// be the default encryption type.
Set<KerberosTicket> privateCredentials = clientSubject.getPrivateCredentials(KerberosTicket.class);
assertFalse(privateCredentials.isEmpty());
KerberosTicket tgt = privateCredentials.iterator().next();
assertNotNull(tgt);
LOG.info("Using TGT with etype: {}", tgt.getSessionKey().getAlgorithm());
// The name of the principal
final String principalName = clientPrincipals.iterator().next().getName();
// Run this code, logged in as the subject (the client)
byte[] response = Subject.doAs(clientSubject, new PrivilegedExceptionAction<byte[]>() {
@Override
public byte[] run() throws Exception {
// Logs in with Kerberos via GSS
GSSManager gssManager = GSSManager.getInstance();
Oid oid = new Oid(SpnegoTestUtil.JGSS_KERBEROS_TICKET_OID);
GSSName gssClient = gssManager.createName(principalName, GSSName.NT_USER_NAME);
GSSCredential credential = gssManager.createCredential(gssClient, GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY);
Properties props = new Properties();
ConnectionConfig config = new ConnectionConfigImpl(props);
PoolingHttpClientConnectionManager pool = CommonsHttpClientPoolCache.getPool(config);
// Passes the GSSCredential into the HTTP client implementation
final AvaticaCommonsHttpClientImpl httpClient = new AvaticaCommonsHttpClientImpl(httpServerUrl);
httpClient.setGSSCredential(credential);
httpClient.setHttpClientPool(pool);
return httpClient.send(new byte[0]);
}
});
// We should get a response which is "OK" with our client's name
assertNotNull(response);
assertEquals("OK " + SpnegoTestUtil.CLIENT_NAME, new String(response, StandardCharsets.UTF_8));
}
use of org.apache.calcite.avatica.ConnectionConfigImpl in project calcite-avatica by apache.
the class AvaticaHttpClientFactoryTest method testOverridenHttpClient.
@Test
public void testOverridenHttpClient() throws Exception {
Properties props = new Properties();
props.setProperty(BuiltInConnectionProperty.HTTP_CLIENT_IMPL.name(), AvaticaHttpClientImpl.class.getName());
URL url = new URL("http://localhost:8765");
ConnectionConfig config = new ConnectionConfigImpl(props);
AvaticaHttpClientFactory httpClientFactory = new AvaticaHttpClientFactoryImpl();
AvaticaHttpClient client = httpClientFactory.getClient(url, config, null);
assertTrue("Client was an instance of " + client.getClass(), client instanceof AvaticaHttpClientImpl);
}
Aggregations