Search in sources :

Example 1 with ConnectionConfigImpl

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);
}
Also used : ConnectionConfigImpl(org.apache.calcite.avatica.ConnectionConfigImpl) Properties(java.util.Properties) URL(java.net.URL) ConnectionConfig(org.apache.calcite.avatica.ConnectionConfig) Test(org.junit.Test)

Example 2 with ConnectionConfigImpl

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));
}
Also used : GSSName(org.ietf.jgss.GSSName) KerberosTicket(javax.security.auth.kerberos.KerberosTicket) AvaticaCommonsHttpClientImpl(org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientImpl) Oid(org.ietf.jgss.Oid) Properties(java.util.Properties) Subject(javax.security.auth.Subject) KrbException(org.apache.kerby.kerberos.kerb.KrbException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) ConnectionConfigImpl(org.apache.calcite.avatica.ConnectionConfigImpl) GSSCredential(org.ietf.jgss.GSSCredential) GSSManager(org.ietf.jgss.GSSManager) Principal(java.security.Principal) ConnectionConfig(org.apache.calcite.avatica.ConnectionConfig) Test(org.junit.Test)

Example 3 with ConnectionConfigImpl

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);
}
Also used : ConnectionConfigImpl(org.apache.calcite.avatica.ConnectionConfigImpl) Properties(java.util.Properties) URL(java.net.URL) ConnectionConfig(org.apache.calcite.avatica.ConnectionConfig) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)3 ConnectionConfig (org.apache.calcite.avatica.ConnectionConfig)3 ConnectionConfigImpl (org.apache.calcite.avatica.ConnectionConfigImpl)3 Test (org.junit.Test)3 URL (java.net.URL)2 Principal (java.security.Principal)1 Subject (javax.security.auth.Subject)1 KerberosTicket (javax.security.auth.kerberos.KerberosTicket)1 AvaticaCommonsHttpClientImpl (org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientImpl)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1 KrbException (org.apache.kerby.kerberos.kerb.KrbException)1 GSSCredential (org.ietf.jgss.GSSCredential)1 GSSManager (org.ietf.jgss.GSSManager)1 GSSName (org.ietf.jgss.GSSName)1 Oid (org.ietf.jgss.Oid)1