Package org.apache.http.client

Examples of org.apache.http.client.CredentialsProvider


            if (followup != null) {
                return followup;
            }
        }
        if (HttpClientParams.isAuthenticating(this.params)) {
            CredentialsProvider credsProvider = (CredentialsProvider) this.localContext.getAttribute(
                    ClientContext.CREDS_PROVIDER);
            if (credsProvider != null) {
                followup = handleTargetChallenge(credsProvider);
                if (followup != null) {
                    return followup;
View Full Code Here


    }

    private RoutedRequest handleConnectResponse() throws HttpException {
        RoutedRequest followup = null;
        if (HttpClientParams.isAuthenticating(this.params)) {
            CredentialsProvider credsProvider = (CredentialsProvider) this.localContext.getAttribute(
                    ClientContext.CREDS_PROVIDER);
            if (credsProvider != null) {
                followup = handleProxyChallenge(credsProvider);
                if (followup != null) {
                    return followup;
View Full Code Here

           
            // If no auth scheme avaialble yet, try to initialize it preemptively
            if (authState.getAuthScheme() == null) {
                AuthScheme authScheme = (AuthScheme) context.getAttribute(
                        "preemptive-auth");
                CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
                        ClientContext.CREDS_PROVIDER);
                HttpHost targetHost = (HttpHost) context.getAttribute(
                        ExecutionContext.HTTP_TARGET_HOST);
                if (authScheme != null) {
                    Credentials creds = credsProvider.getCredentials(
                            new AuthScope(
                                    targetHost.getHostName(),
                                    targetHost.getPort()));
                    if (creds == null) {
                        throw new HttpException("No credentials for preemptive authentication");
View Full Code Here

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

        CredentialsProvider defaultCredentialsProvider = this.credentialsProvider;
        if (defaultCredentialsProvider == null) {
            if (systemProperties) {
                defaultCredentialsProvider = new SystemDefaultCredentialsProvider();
            } else {
                defaultCredentialsProvider = new BasicCredentialsProvider();
View Full Code Here

                new HttpGet("http://somefella:secret@bar/test"));
        final HttpClientContext context = HttpClientContext.create();
        protocolExec.execute(route, request, context, execAware);
        Assert.assertEquals(new URI("/test"), request.getURI());
        Assert.assertEquals(new HttpHost("bar", -1), context.getTargetHost());
        final CredentialsProvider credentialsProvider = context.getCredentialsProvider();
        Assert.assertNotNull(credentialsProvider);
        final Credentials creds = credentialsProvider.getCredentials(new AuthScope("bar", -1, null));
        Assert.assertNotNull(creds);
        Assert.assertEquals("somefella", creds.getUserPrincipal().getName());
    }
View Full Code Here

                final UsernamePasswordCredentials defaultcreds = new UsernamePasswordCredentials(
                        username, password);
                final HttpHost newProxy = new HttpHost(host, port);
                client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
                        newProxy);
                final CredentialsProvider credsProvider = new BasicCredentialsProvider();
                credsProvider.setCredentials(new AuthScope(host, port,
                        AuthScope.ANY_REALM), defaultcreds);

            }
        }
    }
View Full Code Here

    public HttpContext configureWith(XMLConfiguration config) {
        final BasicHttpContext context = new BasicHttpContext();
        if (config.containsKey("hosts.host")) {
            final List<HierarchicalConfiguration> hosts = config
                    .configurationsAt("hosts.host");
            final CredentialsProvider credsProvider = new BasicCredentialsProvider();
            if (null != hosts) {
                LOGGER.debug("hosts:" + hosts.size());
                for (final HierarchicalConfiguration host : hosts) {

                    final AuthScope authScope = new AuthScope(
                            host.getString("server"), host.getInt("port"));
                    credsProvider.setCredentials(
                            authScope,
                            new UsernamePasswordCredentials(host.getString(
                                    "username", "admin"), host.getString(
                                    "password", "admin1")));
                }
View Full Code Here

            if (status < 200) {
                throw new HttpException("Unexpected response to CONNECT request: " +
                        response.getStatusLine());
            }
           
            CredentialsProvider credsProvider = (CredentialsProvider)
                context.getAttribute(ClientContext.CREDS_PROVIDER);
           
            if (credsProvider != null && HttpClientParams.isAuthenticating(params)) {
                if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) {
View Full Code Here

            }
           
            return new RoutedRequest.Impl(redirect, newRoute);
        }

        CredentialsProvider credsProvider = (CredentialsProvider)
            context.getAttribute(ClientContext.CREDS_PROVIDER);
   
        if (credsProvider != null && HttpClientParams.isAuthenticating(params)) {

            if (this.targetAuthHandler.isAuthenticationRequested(response, context)) {
View Full Code Here

   * via NTLM.
   */
    @Bean
    public RestTemplate getRestTemplate(List<HttpMessageConverter<?>> messageConverters) {
      messageConverters.add(new ByteArrayHttpMessageConverter());
      final CredentialsProvider credsProv = new BasicCredentialsProvider();
      credsProv.setCredentials(
          AuthScope.ANY,
          new NTCredentials(username, password, null, null)
      );
      final HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
      final RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
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.