Search in sources :

Example 1 with EncryptedHttpRequestExecutor

use of com.iwave.ext.windows.winrm.encryption.EncryptedHttpRequestExecutor in project coprhd-controller by CoprHD.

the class WinRMTarget method createHttpClient.

/**
 * HttpClient builder
 * @return HttpClient
 * @throws HttpException
 */
protected CloseableHttpClient createHttpClient() throws HttpException {
    HttpClientBuilder httpClient = HttpClientBuilder.create();
    // Build the request config identifying the target preferred authentication schemes and other socket connection parameters.
    RequestConfig.Builder requestConfig = RequestConfig.custom().setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.SPNEGO, AuthSchemes.NTLM, AuthSchemes.DIGEST, AuthSchemes.BASIC));
    requestConfig.setConnectTimeout(DEFAULT_CONNECTION_TIMEOUT);
    requestConfig.setSocketTimeout(DEFAULT_CONNECTION_TIMEOUT);
    httpClient.setDefaultRequestConfig(requestConfig.build());
    // Set the request executor. The EncryptedHttpRequestExecutor is a custom request executor that is capable of encryption and works
    // using the Windows NTLM authentication scheme.
    httpClient.setRequestExecutor(new EncryptedHttpRequestExecutor());
    // Build a list of the authentication schemes
    Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.NTLM, new NTLMSchemeFactory()).register(AuthSchemes.BASIC, new BasicSchemeFactory()).register(AuthSchemes.DIGEST, new DigestSchemeFactory()).register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).register(AuthSchemes.SPNEGO, new CustomSPNegoSchemeFactory()).build();
    try {
        httpClient.setConnectionManager(createClientConnectionManager());
    } catch (Exception e) {
        throw new HttpException(e.getMessage());
    }
    httpClient.setDefaultAuthSchemeRegistry(authSchemeRegistry);
    return httpClient.build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) KerberosSchemeFactory(org.apache.http.impl.auth.KerberosSchemeFactory) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) HttpException(org.apache.http.HttpException) MalformedURLException(java.net.MalformedURLException) EncryptedHttpRequestExecutor(com.iwave.ext.windows.winrm.encryption.EncryptedHttpRequestExecutor) HttpException(org.apache.http.HttpException) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) NTLMSchemeFactory(org.apache.http.impl.auth.NTLMSchemeFactory) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Aggregations

EncryptedHttpRequestExecutor (com.iwave.ext.windows.winrm.encryption.EncryptedHttpRequestExecutor)1 MalformedURLException (java.net.MalformedURLException)1 HttpException (org.apache.http.HttpException)1 AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 BasicSchemeFactory (org.apache.http.impl.auth.BasicSchemeFactory)1 DigestSchemeFactory (org.apache.http.impl.auth.DigestSchemeFactory)1 KerberosSchemeFactory (org.apache.http.impl.auth.KerberosSchemeFactory)1 NTLMSchemeFactory (org.apache.http.impl.auth.NTLMSchemeFactory)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1