Package org.apache.http.client

Examples of org.apache.http.client.AuthCache


            throw new IllegalArgumentException("HTTP request may not be null");
        }
        if (context == null) {
            throw new IllegalArgumentException("HTTP context may not be null");
        }
        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        if (authCache != null) {
            cache(authCache,
                    (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST),
                    (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE));
            cache(authCache,
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

        public PreemptiveProxyAuth(HttpHost proxyHost) {
            this.proxyHost = proxyHost;
        }

        public void process(HttpRequest request, HttpContext context) {
            AuthCache authCache;
            // Set up the a Basic Auth scheme scoped for the proxy - we don't
            // want to do this for non-proxy authentication.
            BasicScheme basicScheme = new BasicScheme(ChallengeState.PROXY);

            if (context.getAttribute(ClientContext.AUTH_CACHE) == null) {
                authCache = new BasicAuthCache();
                authCache.put(this.proxyHost, basicScheme);
                context.setAttribute(ClientContext.AUTH_CACHE, authCache);
            } else {
                authCache =
                    (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
                authCache.put(this.proxyHost, basicScheme);
            }
        }
View Full Code Here

        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", AuthScope.ANY_PORT), new UsernamePasswordCredentials("Aladdin", "open sesame"));
       
        HttpHost host = new HttpHost("localhost", 12345);
       
        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(host, basicAuth);
       
        BasicHttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.AUTH_CACHE, authCache);
       
        List<String> authPrefs = new ArrayList<String>();
View Full Code Here

                    credentialsProvider.setCredentials(new AuthScope(hh), credentials);

                    // Preemptive authentication
                    if (isPreemptiveBasicAuth()) {
                        // 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(hh, basicAuth);

                        // Add AuthCache to the execution context
                        httpClientContext = HttpClientContext.create();
                        httpClientContext.setCredentialsProvider(credentialsProvider);
                        httpClientContext.setAuthCache(authCache);
View Full Code Here

TOP

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

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.