Search in sources :

Example 1 with AuthSchemeProvider

use of org.apache.http.auth.AuthSchemeProvider in project wildfly by wildfly.

the class SAML2AttributeMappingTestCase method testPassUserPrincipalToAttributeManager.

/**
     * Tests IDP attribute mapping when passUserPrincipalToAttributeManager is set to "true". Automatic handling of redirections
     * is enabled for HTTP client used.
     *
     * @throws Exception
     */
@Test
public void testPassUserPrincipalToAttributeManager() throws Exception {
    Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new JBossNegotiateSchemeFactory(true)).build();
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(null, -1, null), new NullHCCredentials());
    try (final CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCredentialsProvider(credentialsProvider).setRedirectStrategy(Utils.REDIRECT_STRATEGY).build()) {
        String response = PicketLinkTestBase.makeCallWithKerberosAuthn(spUrl.toURI(), httpClient, "jduke", "theduke", 200);
        assertEquals("SP index page was not reached", SP_RESPONSE_BODY, response);
        response = PicketLinkTestBase.makeCall(new URL(spUrl.toString() + PrintAttributeServlet.SERVLET_PATH.substring(1)), httpClient, 200);
        assertEquals("cn attribute not stored", "Java Duke", response);
    }
}
Also used : JBossNegotiateSchemeFactory(org.jboss.as.test.integration.security.common.negotiation.JBossNegotiateSchemeFactory) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) NullHCCredentials(org.jboss.as.test.integration.security.common.NullHCCredentials) AuthScope(org.apache.http.auth.AuthScope) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) URL(java.net.URL) Test(org.junit.Test)

Example 2 with AuthSchemeProvider

use of org.apache.http.auth.AuthSchemeProvider in project stdlib by petergeneric.

the class ResteasyClientFactoryImpl method createHttpClientCustomiser.

/**
 * N.B. This method signature may change in the future to add new parameters
 *
 * @param fastFail
 * @param authScope
 * @param credentials
 * @param preemptiveAuth
 * @param storeCookies
 * @param customiser
 *
 * @return
 */
public Consumer<HttpClientBuilder> createHttpClientCustomiser(final boolean fastFail, final AuthScope authScope, final Credentials credentials, final boolean preemptiveAuth, final boolean storeCookies, Consumer<HttpClientBuilder> customiser) {
    // Customise timeouts if fast fail mode is enabled
    if (fastFail) {
        customiser = concat(customiser, b -> {
            RequestConfig.Builder requestBuilder = RequestConfig.custom();
            requestBuilder.setConnectTimeout((int) fastFailConnectionTimeout.getMilliseconds()).setSocketTimeout((int) fastFailSocketTimeout.getMilliseconds());
            b.setDefaultRequestConfig(requestBuilder.build());
        });
    }
    // If credentials were supplied then we should set them up
    if (credentials != null) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        if (authScope != null)
            credentialsProvider.setCredentials(authScope, credentials);
        else
            credentialsProvider.setCredentials(AuthScope.ANY, credentials);
        // Set up bearer auth scheme provider if we're using bearer credentials
        if (credentials instanceof BearerCredentials) {
            customiser = concat(customiser, b -> {
                Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register("Bearer", new BearerAuthSchemeProvider()).build();
                b.setDefaultAuthSchemeRegistry(authSchemeRegistry);
            });
        }
        // Set up the credentials customisation
        customiser = concat(customiser, b -> b.setDefaultCredentialsProvider(credentialsProvider));
        if (preemptiveAuth && credentials instanceof BearerCredentials)
            customiser = concat(customiser, b -> b.addInterceptorFirst(new PreemptiveBearerAuthInterceptor()));
        else
            customiser = concat(customiser, b -> b.addInterceptorLast(new PreemptiveBasicAuthInterceptor()));
    }
    // If cookies are enabled then set up a cookie store
    if (storeCookies)
        customiser = concat(customiser, b -> b.setDefaultCookieStore(new BasicCookieStore()));
    return customiser;
}
Also used : AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) RegistryBuilder(org.apache.http.config.RegistryBuilder) Inject(com.google.inject.Inject) Timeout(com.peterphi.std.threading.Timeout) LogReportMessageBodyWriter(com.peterphi.std.guice.common.logging.logreport.jaxrs.LogReportMessageBodyWriter) RequestConfig(org.apache.http.client.config.RequestConfig) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) CommonTypesParamConverterProvider(com.peterphi.std.guice.restclient.converter.CommonTypesParamConverterProvider) ProxySelector(java.net.ProxySelector) NoConnectionReuseStrategy(org.apache.http.impl.NoConnectionReuseStrategy) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) ShutdownManager(com.peterphi.std.guice.common.shutdown.iface.ShutdownManager) Registry(org.apache.http.config.Registry) Credentials(org.apache.http.auth.Credentials) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) SystemDefaultRoutePlanner(org.apache.http.impl.conn.SystemDefaultRoutePlanner) Doc(com.peterphi.std.annotation.Doc) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) StoppableService(com.peterphi.std.guice.common.shutdown.iface.StoppableService) AuthScope(org.apache.http.auth.AuthScope) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) Named(com.google.inject.name.Named) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) CredentialsProvider(org.apache.http.client.CredentialsProvider) Singleton(com.google.inject.Singleton) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) RegistryBuilder(org.apache.http.config.RegistryBuilder) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) Registry(org.apache.http.config.Registry)

Example 3 with AuthSchemeProvider

use of org.apache.http.auth.AuthSchemeProvider in project epp.mpc by eclipse.

the class WinClientBuilderCustomizer method customizeBuilder.

public HttpClientBuilder customizeBuilder(HttpClientBuilder builder) {
    if (!isWinAuthAvailable()) {
        return builder;
    }
    HttpClientBuilder winBuilder = builder == null ? HttpClientBuilder.create() : builder;
    Registry<AuthSchemeProvider> authSchemeRegistry = createAuthSchemeRegistry();
    return winBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
}
Also used : HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider)

Example 4 with AuthSchemeProvider

use of org.apache.http.auth.AuthSchemeProvider in project hbase by apache.

the class TestSecureRESTServer method getClient.

private Pair<CloseableHttpClient, HttpClientContext> getClient() {
    HttpClientConnectionManager pool = new PoolingHttpClientConnectionManager();
    HttpHost host = new HttpHost("localhost", REST_TEST.getServletPort());
    Registry<AuthSchemeProvider> authRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)).build();
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, EmptyCredentials.INSTANCE);
    AuthCache authCache = new BasicAuthCache();
    CloseableHttpClient client = HttpClients.custom().setDefaultAuthSchemeRegistry(authRegistry).setConnectionManager(pool).build();
    HttpClientContext context = HttpClientContext.create();
    context.setTargetHost(host);
    context.setCredentialsProvider(credentialsProvider);
    context.setAuthSchemeRegistry(authRegistry);
    context.setAuthCache(authCache);
    return new Pair<>(client, context);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) SPNegoSchemeFactory(org.apache.http.impl.auth.SPNegoSchemeFactory) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpHost(org.apache.http.HttpHost) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) Pair(org.apache.hadoop.hbase.util.Pair)

Example 5 with AuthSchemeProvider

use of org.apache.http.auth.AuthSchemeProvider in project zm-mailbox by Zimbra.

the class ExchangeFreeBusyProvider method basicAuth.

private boolean basicAuth(HttpClientBuilder clientBuilder, ServerInfo info) {
    Credentials cred = new UsernamePasswordCredentials(info.authUsername, info.authPassword);
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, cred);
    clientBuilder.setDefaultCredentialsProvider(credsProvider);
    Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.BASIC, new BasicSchemeFactory(Consts.UTF_8)).build();
    clientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
    return true;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)26 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)18 CredentialsProvider (org.apache.http.client.CredentialsProvider)17 AuthScope (org.apache.http.auth.AuthScope)11 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)11 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)10 HttpHost (org.apache.http.HttpHost)9 SPNegoSchemeFactory (org.apache.http.impl.auth.SPNegoSchemeFactory)9 Credentials (org.apache.http.auth.Credentials)8 RequestConfig (org.apache.http.client.config.RequestConfig)8 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 BasicSchemeFactory (org.apache.http.impl.auth.BasicSchemeFactory)7 HttpResponse (org.apache.http.HttpResponse)6 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)4 PrivilegedActionException (java.security.PrivilegedActionException)4 HttpClient (org.apache.http.client.HttpClient)4 DigestSchemeFactory (org.apache.http.impl.auth.DigestSchemeFactory)4 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)4 File (java.io.File)3