Package org.apache.http.impl.client

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


                    Scheme scheme = schemeRegistry.getScheme(target);
                    target = new HttpHost(target.getHostName(),
                            scheme.resolvePort(target.getPort()), target.getSchemeName());
                }
                if (authCache == null) {
                    authCache = new BasicAuthCache();
                    context.setAttribute(ClientContext.AUTH_CACHE, authCache);
                }
                switch (targetState.getState()) {
                case CHALLENGED:
                    cache(authCache, target, targetState.getAuthScheme());
                    break;
                case FAILURE:
                    uncache(authCache, target, targetState.getAuthScheme());
                }
            }
        }

        HttpHost proxy = (HttpHost) context.getAttribute(ExecutionContext.HTTP_PROXY_HOST);
        AuthState proxyState = (AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE);
        if (proxy != null && proxyState != null) {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Proxy auth state: " + proxyState.getState());
            }
            if (isCachable(proxyState)) {
                if (authCache == null) {
                    authCache = new BasicAuthCache();
                    context.setAttribute(ClientContext.AUTH_CACHE, authCache);
                }
                switch (proxyState.getState()) {
                case CHALLENGED:
                    cache(authCache, proxy, proxyState.getAuthScheme());
View Full Code Here


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

                log.debug( "Initial attempt did not return a 200 status code. Trying pre-emptive authentication.." );

                HttpHost targetHost = new HttpHost( uri.getHost(), uri.getPort(), uri.getScheme() );

                // 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 );
View Full Code Here

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

    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 );

    HttpPost post = new HttpPost( url.toURI() );
View Full Code Here

    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

            String username = authenticationInfo.getUserName();
            String password = authenticationInfo.getPassword();
            // preemptive for put
            if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
            {
                AuthCache authCache = new BasicAuthCache();
                BasicScheme basicAuth = new BasicScheme();
                HttpHost targetHost =
                    new HttpHost( repository.getHost(), repository.getPort(), repository.getProtocol() );
                authCache.put( targetHost, basicAuth );

                localContext = new BasicHttpContext();
                localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );
            }
        }
View Full Code Here

                String password = authenticationInfo.getPassword();

                if ( StringUtils.isNotEmpty( username ) && StringUtils.isNotEmpty( password ) )
                {

                    AuthCache authCache = new BasicAuthCache();
                    BasicScheme basicAuth = new BasicScheme();
                    HttpHost targetHost =
                        new HttpHost( repository.getHost(), repository.getPort(), repository.getProtocol() );
                    authCache.put( targetHost, basicAuth );

                    localContext = new BasicHttpContext();
                    localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );
                }
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);
        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

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

    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 );

    HttpPost post = new HttpPost( url.toURI() );
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.