Package org.apache.http.impl.client

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


    client.getCredentialsProvider().setCredentials(
        new AuthScope( targetHost ),
        new UsernamePasswordCredentials( user, password ) );

    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put( targetHost, basicAuth );
    // Add AuthCache to the execution context
    BasicHttpContext localContext = new BasicHttpContext();
    localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );

    HttpGet request = new HttpGet( url.toURI() );
View Full Code Here


    try {
      client = createClient();
      client.getCredentialsProvider().setCredentials(
          new AuthScope( host.getHostName(), host.getPort() ),
          new UsernamePasswordCredentials( username, password ) );
      AuthCache authCache = new BasicAuthCache();
      BasicScheme authScheme = new BasicScheme();
      authCache.put( host, authScheme );
      context = new BasicHttpContext();
      context.setAttribute( ClientContext.AUTH_CACHE, authCache );
    } catch( GeneralSecurityException e ) {
      throw new HadoopException( "Failed to create HTTP client.", e );
    }
View Full Code Here

            throw new IllegalArgumentException("HTTP context may not be null");
        }

        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        if (authCache == null) {
            context.setAttribute(ClientContext.AUTH_CACHE, new BasicAuthCache());
        } else {

            CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
                    ClientContext.CREDS_PROVIDER);
View Full Code Here

    Executor(final HttpClient httpclient) {
        super();
        this.httpclient = httpclient;
        this.credentialsProvider = new BasicCredentialsProvider();
        this.authCache = new BasicAuthCache();
    }
View Full Code Here

        writeOutBoundHeaders(cr.getHeaders(), request);

        try {
            /**---BEGIN EMC modification - support for preemptive proxy authorization, which is otherwise impossible */
            AuthCache authCache = new BasicAuthCache();
            BasicHttpContext localContext = new BasicHttpContext();
            localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);

            // always preempt the proxy authorization
            HttpRoutePlanner routePlanner = ((AbstractHttpClient)client).getRoutePlanner();
            HttpHost proxyHost = routePlanner.determineRoute(getHost(request), request, localContext).getProxyHost();
            if (proxyHost != null) {
                BasicScheme proxyBasicScheme = new BasicScheme(ChallengeState.PROXY);
                authCache.put(proxyHost, proxyBasicScheme);
            }

            if(preemptiveBasicAuth) {
                BasicScheme basicScheme = new BasicScheme(ChallengeState.TARGET);
                authCache.put(getHost(request), basicScheme);
            }

            HttpResponse response = getHttpClient().execute(getHost(request), request, localContext);
            /**---END EMC modification */

 
View Full Code Here

  }

  @Override
  public void enablePreemptiveAuthentication(String hostname, int httpPort, int httpsPort)
  {
    AuthCache cache = new BasicAuthCache();
    // Generate Basic preemptive scheme object and stick it to the local execution context
    BasicScheme basicAuth = new BasicScheme();
    // Configure HttpClient to authenticate preemptively by prepopulating the authentication data cache.
    cache.put(new HttpHost(hostname, httpPort, "http"), basicAuth);
    cache.put(new HttpHost(hostname, httpsPort, "https"), basicAuth);
    // Add AuthCache to the execution context
    this.context.setAttribute(HttpClientContext.AUTH_CACHE, cache);
  }
View Full Code Here

            Credentials credentials = null;
            if (model.isBasicAuth()) {
                authScope = createAuthScope(model.getBasicAuthConfig().getHost(), model.getBasicAuthConfig().getPort(), model.getBasicAuthConfig().getRealm());
                credentials = new UsernamePasswordCredentials(model.getBasicAuthConfig().getUser(), model.getBasicAuthConfig().getPassword());
                // Create AuthCache instance
                AuthCache authCache = new BasicAuthCache();
                authCache.put(new HttpHost(authScope.getHost(), authScope.getPort()), new BasicScheme(ChallengeState.TARGET));
                BasicHttpContext context = new BasicHttpContext();
                context.setAttribute(ClientContext.AUTH_CACHE, authCache);
                ((ApacheHttpClient4Executor)_executor).setHttpContext(context);
            } else {
                authScope = createAuthScope(model.getNtlmAuthConfig().getHost(), model.getNtlmAuthConfig().getPort(), model.getNtlmAuthConfig().getRealm());
                credentials = new NTCredentials(model.getNtlmAuthConfig().getUser(),
                                    model.getNtlmAuthConfig().getPassword(),
                                    "",
                                    model.getNtlmAuthConfig().getDomain());
            }
            ((DefaultHttpClient)httpClient).getCredentialsProvider().setCredentials(authScope, credentials);
        } else {
            ProxyModel proxy = model.getProxyConfig();
            if (proxy != null) {
                HttpHost proxyHost = null;
                if (proxy.getPort() != null) {
                    proxyHost = new HttpHost(proxy.getHost(), Integer.valueOf(proxy.getPort()).intValue());
                } else {
                    proxyHost = new HttpHost(proxy.getHost(), -1);
                }
                if (proxy.getUser() != null) {
                    AuthScope authScope = new AuthScope(proxy.getHost(), Integer.valueOf(proxy.getPort()).intValue(), AuthScope.ANY_REALM);
                    Credentials credentials = new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword());
                    AuthCache authCache = new BasicAuthCache();
                    authCache.put(proxyHost, new BasicScheme(ChallengeState.PROXY));
                    ((DefaultHttpClient)httpClient).getCredentialsProvider().setCredentials(authScope, credentials);
                    BasicHttpContext context = new BasicHttpContext();
                    context.setAttribute(ClientContext.AUTH_CACHE, authCache);
                    ((ApacheHttpClient4Executor)_executor).setHttpContext(context);
                }
View Full Code Here

    httpClient.getCredentialsProvider().setCredentials(
        new AuthScope(httpHost.getHostName(), httpHost.getPort()),
        new UsernamePasswordCredentials(userName, password));

    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestScheme = new DigestScheme();

    digestScheme.overrideParamter("realm", "SPARQL"); // Virtuoso specific
    // digestScheme.overrideParamter("nonce", new Nonc);

    authCache.put(httpHost, digestScheme);

    BasicHttpContext localcontext = new BasicHttpContext();
    localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

    // Execute the request
View Full Code Here

    httpClient.getCredentialsProvider().setCredentials(
        new AuthScope(httpHost.getHostName(), httpHost.getPort()),
        new UsernamePasswordCredentials(userName, password));

    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestScheme = new DigestScheme();

    digestScheme.overrideParamter("realm", "SPARQL"); // Virtuoso specific
    // digestScheme.overrideParamter("nonce", new Nonc);

    authCache.put(httpHost, digestScheme);

    BasicHttpContext localcontext = new BasicHttpContext();
    localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

    // Execute the request
View Full Code Here

    try {

      // Preemptive authentication enabled - see
      // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html#d5e1032
      HttpHost targetHost = new HttpHost(builder.getHost(), builder.getPort(), builder.getScheme());
      AuthCache authCache = new BasicAuthCache();
      BasicScheme basicAuth = new BasicScheme();
      authCache.put(targetHost, basicAuth);
      HttpClientContext localContext = HttpClientContext.create();
      localContext.setAuthCache(authCache);

      response = httpclient.execute(targetHost, method, localContext);
      int statusCode = response.getStatusLine().getStatusCode();
View Full Code Here

TOP

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

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.