Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.BasicCredentialsProvider


            return;

        // Be careful to scope credentials to the specific URI so that
        // HttpClient won't try and send them to other servers
        HttpHost host = new HttpHost(target.getHost(), target.getPort());
        CredentialsProvider provider = new BasicCredentialsProvider();

        provider.setCredentials(new AuthScope(host), this.createCredentials(target));

        client.setCredentialsProvider(provider);
    }
View Full Code Here


  }

  @Override
  protected CredentialsProvider createCredentialsProvider()
  {
    return new BasicCredentialsProvider();
  }
View Full Code Here

        if (!this.hasUserName(target) || !this.hasPassword(target)) return;
       
        // Be careful to scope credentials to the specific URI so that HttpClient won't try
        // and send them to other servers
        HttpHost host = new HttpHost(target.getHost(), target.getPort());
        CredentialsProvider provider = new BasicCredentialsProvider();
       
        String user = this.getUserName(target);
        provider.setCredentials(new AuthScope(host), new UsernamePasswordCredentials(user, new String(this.getPassword(target))));
       
        client.setCredentialsProvider(provider);
    }
View Full Code Here

    @Test
    public void testBasicAuthenticationCredentialsCaching() throws Exception {
        this.localServer.register("*", new AuthHandler());

        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("test", "test"));
        final TestTargetAuthenticationStrategy authStrategy = new TestTargetAuthenticationStrategy();

        this.httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
View Full Code Here

    @Test
    public void testPreemptiveAuthentication() throws Exception {
        final CountingAuthHandler requestHandler = new CountingAuthHandler();
        this.localServer.register("*", requestHandler);

        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("test", "test"));

        this.httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build();
View Full Code Here

    @Test
    public void testPreemptiveAuthenticationFailure() throws Exception {
        final CountingAuthHandler requestHandler = new CountingAuthHandler();
        this.localServer.register("*", requestHandler);

        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("test", "stuff"));

        this.httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build();
View Full Code Here

    @Before
    public void setUp() {
        this.target = new HttpHost("localhost", 80);
        this.proxy = new HttpHost("localhost", 8080);

        this.credProvider = new BasicCredentialsProvider();
        this.creds1 = new UsernamePasswordCredentials("user1", "secret1");
        this.creds2 = new UsernamePasswordCredentials("user2", "secret2");
        this.authscope1 = new AuthScope(this.target);
        this.authscope2 = new AuthScope(this.proxy);
        this.authscheme1 = new BasicScheme();
View Full Code Here

        Mockito.when(this.authScheme.isComplete()).thenReturn(Boolean.TRUE);
        this.context = new BasicHttpContext();
        this.host = new HttpHost("localhost", 80);
        this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.host);
        this.credentials = Mockito.mock(Credentials.class);
        this.credentialsProvider = new BasicCredentialsProvider();
        this.credentialsProvider.setCredentials(AuthScope.ANY, this.credentials);
        this.context.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
        this.authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
            .register("basic", new BasicSchemeFactory())
            .register("digest", new DigestSchemeFactory())
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

TOP

Related Classes of org.apache.http.impl.client.BasicCredentialsProvider

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.