Examples of AuthCache


Examples of org.apache.http.client.AuthCache

    public void apply(AbstractHttpClient client, HttpContext httpContext, URI target) {
        this.authenticator.apply(client, httpContext, target);

        // Enable preemptive basic authentication
        // For nice layering we need to respect existing auth cache if present
        AuthCache authCache = (AuthCache) httpContext.getAttribute(ClientContext.AUTH_CACHE);
        if (authCache == null)
            authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme(this.isProxy ? ChallengeState.PROXY : ChallengeState.TARGET);
        // TODO It is possible that this overwrites existing cached credentials
        // so potentially not ideal.
        authCache.put(new HttpHost(target.getHost(), target.getPort()), basicAuth);
        httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }
View Full Code Here

Examples of org.apache.http.client.AuthCache

        }
        if (context == null) {
            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);
           
            HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (target != null) {
                AuthScheme authScheme = authCache.get(target);
                if (authScheme != null) {
                    doPreemptiveAuth(
                            target,
                            authScheme,                    
                            (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE),
                            credsProvider);
                }
            }

            HttpHost proxy = (HttpHost) context.getAttribute(ExecutionContext.HTTP_PROXY_HOST);
            if (proxy != null) {
                AuthScheme authScheme = authCache.get(proxy);
                if (authScheme != null) {
                    doPreemptiveAuth(
                            proxy,
                            authScheme,                    
                            (AuthState) context.getAttribute(ClientContext.PROXY_AUTH_STATE),
View Full Code Here

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

Examples of org.apache.http.client.AuthCache

    public void apply(AbstractHttpClient client, HttpContext httpContext, URI target) {
        this.authenticator.apply(client, httpContext, target);

        // Enable preemptive basic authentication
        // For nice layering we need to respect existing auth cache if present
        AuthCache authCache = (AuthCache) httpContext.getAttribute(ClientContext.AUTH_CACHE);
        if (authCache == null)
            authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme(this.isProxy ? ChallengeState.PROXY : ChallengeState.TARGET);
        // TODO It is possible that this overwrites existing cached credentials so potentially not ideal.
        authCache.put(new HttpHost(target.getHost(), target.getPort()), basicAuth);
        httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }
View Full Code Here

Examples of org.apache.http.client.AuthCache

                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

Examples of org.apache.http.client.AuthCache

        Args.notNull(request, "HTTP request");
        Args.notNull(context, "HTTP context");

        final HttpClientContext clientContext = HttpClientContext.adapt(context);

        final AuthCache authCache = clientContext.getAuthCache();
        if (authCache == null) {
            this.log.debug("Auth cache not set in the context");
            return;
        }

        final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
        if (credsProvider == null) {
            this.log.debug("Credentials provider not set in the context");
            return;
        }

        final RouteInfo route = clientContext.getHttpRoute();
        HttpHost target = clientContext.getTargetHost();
        if (target.getPort() < 0) {
            target = new HttpHost(
                    target.getHostName(),
                    route.getTargetHost().getPort(),
                    target.getSchemeName());
        }

        final AuthState targetState = clientContext.getTargetAuthState();
        if (target != null && targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) {
            final AuthScheme authScheme = authCache.get(target);
            if (authScheme != null) {
                doPreemptiveAuth(target, authScheme, targetState, credsProvider);
            }
        }

        final HttpHost proxy = route.getProxyHost();
        final AuthState proxyState = clientContext.getProxyAuthState();
        if (proxy != null && proxyState != null && proxyState.getState() == AuthProtocolState.UNCHALLENGED) {
            final AuthScheme authScheme = authCache.get(proxy);
            if (authScheme != null) {
                doPreemptiveAuth(proxy, authScheme, proxyState, credsProvider);
            }
        }
    }
View Full Code Here

Examples of org.apache.http.client.AuthCache

            .build();

        final HttpHost targethost = getServerHttp();

        final HttpContext context = new BasicHttpContext();
        final AuthCache authCache = new BasicAuthCache();
        authCache.put(targethost, new BasicScheme());
        context.setAttribute(ClientContext.AUTH_CACHE, authCache);

        final HttpGet httpget = new HttpGet("/");

        final HttpResponse response1 = this.httpclient.execute(targethost, httpget, context);
View Full Code Here

Examples of org.apache.http.client.AuthCache

            .build();

        final HttpHost targethost = getServerHttp();

        final HttpContext context = new BasicHttpContext();
        final AuthCache authCache = new BasicAuthCache();
        authCache.put(targethost, new BasicScheme());
        context.setAttribute(ClientContext.AUTH_CACHE, authCache);

        final HttpGet httpget = new HttpGet("/");

        final HttpResponse response1 = this.httpclient.execute(targethost, httpget, context);
View Full Code Here

Examples of org.apache.http.client.AuthCache

        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ClientContext.ROUTE, new HttpRoute(this.target, null, this.proxy, false));
        context.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetState);
        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);

        final AuthCache authCache = new BasicAuthCache();
        authCache.put(this.target, this.authscheme1);
        authCache.put(this.proxy, this.authscheme2);

        context.setAttribute(ClientContext.AUTH_CACHE, authCache);

        final HttpRequestInterceptor interceptor = new RequestAuthCache();
        interceptor.process(request, context);
View Full Code Here

Examples of org.apache.http.client.AuthCache

        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
        context.setAttribute(ClientContext.ROUTE, new HttpRoute(this.target, null, this.proxy, false));
        context.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetState);
        context.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyState);

        final AuthCache authCache = new BasicAuthCache();
        authCache.put(this.target, this.authscheme1);
        authCache.put(this.proxy, this.authscheme2);

        context.setAttribute(ClientContext.AUTH_CACHE, authCache);

        final HttpRequestInterceptor interceptor = new RequestAuthCache();
        interceptor.process(request, context);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.