Package org.apache.http.client

Examples of org.apache.http.client.CredentialsProvider


        CookieStore defaultCookieStore = this.cookieStore;
        if (defaultCookieStore == null) {
            defaultCookieStore = new BasicCookieStore();
        }

        CredentialsProvider defaultCredentialsProvider = this.credentialsProvider;
        if (defaultCredentialsProvider == null) {
            defaultCredentialsProvider = new BasicCredentialsProvider();
        }

        return new InternalHttpClient(
View Full Code Here


        final HttpClientContext context = HttpClientContext.create();

        final Lookup<CookieSpecProvider> localCookieSpecRegistry = Mockito.mock(Lookup.class);
        final Lookup<AuthSchemeProvider> localAuthSchemeRegistry = Mockito.mock(Lookup.class);
        final CookieStore localCookieStore = Mockito.mock(CookieStore.class);
        final CredentialsProvider localCredentialsProvider = Mockito.mock(CredentialsProvider.class);
        final RequestConfig localConfig = RequestConfig.custom().build();

        context.setCookieSpecRegistry(localCookieSpecRegistry);
        context.setAuthSchemeRegistry(localAuthSchemeRegistry);
        context.setCookieStore(localCookieStore);
View Full Code Here

        final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
            .register("basic", new BasicSchemeFactory())
            .register("digest", new DigestSchemeFactory()).build();
        context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, authSchemeRegistry);

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        context.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider);

        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
        Assert.assertNotNull(options);
        Assert.assertEquals(0, options.size());
View Full Code Here

        final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
            .register("basic", new BasicSchemeFactory())
            .register("digest", new DigestSchemeFactory()).build();
        context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, authSchemeRegistry);

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope("somehost", 80, "realm2"),
                new UsernamePasswordCredentials("user", "pwd"));
        context.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider);

        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
        Assert.assertNotNull(options);
View Full Code Here

        final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
            .register("basic", new BasicSchemeFactory())
            .register("digest", new DigestSchemeFactory()).build();
        context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, authSchemeRegistry);

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope("somehost", 80),
                new UsernamePasswordCredentials("user", "pwd"));
        context.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider);

        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
        Assert.assertNotNull(options);
View Full Code Here

            .register("basic", new BasicSchemeFactory())
            .register("digest", new DigestSchemeFactory()).build();
        context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, authSchemeRegistry);
        context.setAttribute(ClientContext.REQUEST_CONFIG, config);

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope("somehost", 80),
                new UsernamePasswordCredentials("user", "pwd"));
        context.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider);

        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
        Assert.assertNotNull(options);
View Full Code Here

* a target site that requires user authentication.
*/
public class ClientAuthentication {

    public static void main(String[] args) throws Exception {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope("localhost", 443),
                new UsernamePasswordCredentials("username", "password"));
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider)
                .build();
View Full Code Here

        connManager.setMaxPerRoute(new HttpRoute(new HttpHost("somehost", 80)), 20);

        // Use custom cookie store if necessary.
        CookieStore cookieStore = new BasicCookieStore();
        // Use custom credentials provider if necessary.
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        // Create global request configuration
        RequestConfig defaultRequestConfig = RequestConfig.custom()
            .setCookieSpec(CookieSpecs.BEST_MATCH)
            .setExpectContinueEnabled(true)
            .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
View Full Code Here

*/
public class ClientPreemptiveDigestAuthentication {

    public static void main(String[] args) throws Exception {
        HttpHost target = new HttpHost("localhost", 80, "http");
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope(target.getHostName(), target.getPort()),
                new UsernamePasswordCredentials("username", "password"));
        CloseableHttpClient httpclient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider)
                .build();
View Full Code Here

        return hdrs.toString();
    }

    private void setConnectionAuthorization(HttpClient client, URL url, AuthManager authManager) {
        CredentialsProvider credentialsProvider =
            ((AbstractHttpClient) client).getCredentialsProvider();
        if (authManager != null) {
            Authorization auth = authManager.getAuthForURL(url);
            if (auth != null) {
                    String username = auth.getUser();
                    String realm = auth.getRealm();
                    String domain = auth.getDomain();
                    if (log.isDebugEnabled()){
                        log.debug(username + " > D="+domain+" R="+realm);
                    }
                    credentialsProvider.setCredentials(
                            new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
                            new NTCredentials(username, auth.getPass(), localHost, domain));
            } else {
                credentialsProvider.clear();
            }
        } else {
            credentialsProvider.clear();           
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.client.CredentialsProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.