Search in sources :

Example 1 with SPNegoSchemeFactory

use of com.axway.ats.core.gss.spnego.SPNegoSchemeFactory in project ats-framework by Axway.

the class HttpClient method setupAuthentication.

/**
 * Set up authentication for HTTP Basic/HTTP Digest/SPNEGO.
 *
 * @param httpClientBuilder The client builder
 * @return The context
 * @throws HttpException
 */
private void setupAuthentication(HttpClientBuilder httpClientBuilder) throws HttpException {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password));
    httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
    if (authType == AuthType.always) {
        AuthCache authCache = new BasicAuthCache();
        // Generate BASIC scheme object and add it to the local auth cache
        BasicScheme basicAuth = new BasicScheme();
        HttpHost target = new HttpHost(host, port, isOverSsl ? "https" : "http");
        authCache.put(target, basicAuth);
        // Add AuthCache to the execution context
        httpContext.setAuthCache(authCache);
    } else {
        if (!StringUtils.isNullOrEmpty(kerberosServicePrincipalName)) {
            GssClient gssClient = new GssClient(username, password, kerberosClientKeytab, krb5ConfFile);
            AuthSchemeProvider nsf = new SPNegoSchemeFactory(gssClient, kerberosServicePrincipalName, kerberosServicePrincipalType);
            final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, nsf).build();
            httpClientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
        }
    }
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) GssClient(com.axway.ats.core.gss.GssClient) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) SPNegoSchemeFactory(com.axway.ats.core.gss.spnego.SPNegoSchemeFactory) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

GssClient (com.axway.ats.core.gss.GssClient)1 SPNegoSchemeFactory (com.axway.ats.core.gss.spnego.SPNegoSchemeFactory)1 HttpHost (org.apache.http.HttpHost)1 AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)1 AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 AuthCache (org.apache.http.client.AuthCache)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 BasicScheme (org.apache.http.impl.auth.BasicScheme)1 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1