Search in sources :

Example 1 with KnoxSpnegoAuthSchemeFactory

use of org.apache.knox.gateway.dispatch.KnoxSpnegoAuthSchemeFactory in project knox by apache.

the class BaseZookeeperURLManager method buildHttpClient.

/**
 * Construct an Apache HttpClient with suitable timeout and authentication.
 *
 * @return Apache HttpClient
 */
private CloseableHttpClient buildHttpClient() {
    CloseableHttpClient client;
    // Construct a HttpClient with short term timeout
    RequestConfig.Builder requestBuilder = RequestConfig.custom().setConnectTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).setConnectionRequestTimeout(TIMEOUT);
    // If Kerberos is enabled, allow for challenge/response transparent to client
    if (Boolean.getBoolean(GatewayConfig.HADOOP_KERBEROS_SECURED)) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new NullCredentials());
        Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new KnoxSpnegoAuthSchemeFactory(true)).build();
        client = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build()).setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCredentialsProvider(credentialsProvider).build();
    } else {
        client = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build()).build();
    }
    return client;
}
Also used : KnoxSpnegoAuthSchemeFactory(org.apache.knox.gateway.dispatch.KnoxSpnegoAuthSchemeFactory) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider)

Aggregations

AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 KnoxSpnegoAuthSchemeFactory (org.apache.knox.gateway.dispatch.KnoxSpnegoAuthSchemeFactory)1