httpservices/src/main/java/ucar/httpservices/HTTPSession.java
synchronized
    protected void
    setAuthenticationAndProxy(HttpClientBuilder cb)
            throws HTTPException
    {
        // First, setup the ssl factory
        cb.setSSLSocketFactory((SSLConnectionSocketFactory) authcontrols.get(AuthProp.SSLFACTORY));

        // Second, Construct a CredentialsProvider that is
        // the union of the Proxy credentials plus
        // either the global or local credentials; local overrides global
        // Unfortunately, we cannot either clone or extract the contents
        // of the client supplied provider, so we are forced (for now)
        // to modify the client supplied provider.

        // Look in the local credentials first for for best scope match
        AuthScope bestMatch = HTTPAuthUtil.bestmatch(scope, localcreds.keySet());
        CredentialsProvider cp = null;
        if(bestMatch != null) {
            cp = localcreds.get(bestMatch);
        } else {
            bestMatch = HTTPAuthUtil.bestmatch(scope, globalcredfactories.keySet());
            if(bestMatch != null) {
                HTTPProviderFactory factory = globalcredfactories.get(bestMatch);
                cp = factory.getProvider(bestMatch);
            }
        }
        // Build the proxy credentials and AuthScope
        Credentials proxycreds = null;
        AuthScope proxyscope = null;
        String user = (String) authcontrols.get(AuthProp.PROXYUSER);
        String pwd = (String) authcontrols.get(AuthProp.PROXYPWD);
        HttpHost httpproxy = (HttpHost) authcontrols.get(AuthProp.HTTPPROXY);
        HttpHost httpsproxy = (HttpHost) authcontrols.get(AuthProp.HTTPSPROXY);
        if(user != null && (httpproxy != null || httpsproxy != null)) {
            if(httpproxy != null)
                proxyscope = HTTPAuthUtil.hostToAuthScope(httpproxy);
            else //httpsproxy != null
                proxyscope = HTTPAuthUtil.hostToAuthScope(httpsproxy);
            proxycreds = new UsernamePasswordCredentials(user, pwd);
        }
        if(cp == null && proxycreds != null && proxyscope != null) {
            // If client provider is null and proxycreds are not,
            // then use proxycreds alone
            cp = new BasicCredentialsProvider();
            cp.setCredentials(proxyscope, proxycreds);
        } else if(cp != null && proxycreds != null && proxyscope != null) {
            // If client provider is not null and proxycreds are not,
            // then add proxycreds to the client provider
            cp.setCredentials(proxyscope, proxycreds);
        }
        if(cp != null)
            this.sessioncontext.setCredentialsProvider(cp);
    }
synchronized
    protected void
    setAuthenticationAndProxy(HttpClientBuilder cb)
            throws HTTPException
    {
        // First, setup the ssl factory
        cb.setSSLSocketFactory((SSLConnectionSocketFactory) authcontrols.get(AuthProp.SSLFACTORY));

        // Second, Construct a CredentialsProvider that is
        // the union of the Proxy credentials plus
        // either the global or local credentials; local overrides global
        // Unfortunately, we cannot either clone or extract the contents
        // of the client supplied provider, so we are forced (for now)
        // to modify the client supplied provider.

        // Look in the local credentials first for for best scope match
        AuthScope bestMatch = HTTPAuthUtil.bestmatch(scope, localcreds.keySet());
        CredentialsProvider cp = null;
        if(bestMatch != null) {
            cp = localcreds.get(bestMatch);
        } else {
            bestMatch = HTTPAuthUtil.bestmatch(scope, globalcredfactories.keySet());
            if(bestMatch != null) {
                HTTPProviderFactory factory = globalcredfactories.get(bestMatch);
                cp = factory.getProvider(bestMatch);
            }
        }
        // Build the proxy credentials and AuthScope
        Credentials proxycreds = null;
        AuthScope proxyscope = null;
        String user = (String) authcontrols.get(AuthProp.PROXYUSER);
        String pwd = (String) authcontrols.get(AuthProp.PROXYPWD);
        HttpHost httpproxy = (HttpHost) authcontrols.get(AuthProp.HTTPPROXY);
        HttpHost httpsproxy = (HttpHost) authcontrols.get(AuthProp.HTTPSPROXY);
        if(user != null && (httpproxy != null || httpsproxy != null)) {
            if(httpproxy != null)
                proxyscope = HTTPAuthUtil.hostToAuthScope(httpproxy);
            else //httpsproxy != null
                proxyscope = HTTPAuthUtil.hostToAuthScope(httpsproxy);
            proxycreds = new UsernamePasswordCredentials(user, pwd);
        }
        if(cp == null && proxycreds != null && proxyscope != null) {
            // If client provider is null and proxycreds are not,
            // then use proxycreds alone
            cp = new BasicCredentialsProvider();
            cp.setCredentials(proxyscope, proxycreds);
        } else if(cp != null && proxycreds != null && proxyscope != null) {
            // If client provider is not null and proxycreds are not,
            // then add proxycreds to the client provider
            cp.setCredentials(proxyscope, proxycreds);
        }
        if(cp != null)
            this.sessioncontext.setCredentialsProvider(cp);
    }
synchronized protected void setAuthenticationAndProxy ( HttpClientBuilder cb ) throws HTTPException { // First, setup the ssl factory cb . setSSLSocketFactory ( ( SSLConnectionSocketFactory ) authcontrols . get ( AuthProp . SSLFACTORY ) ) ; // Second, Construct a CredentialsProvider that is // the union of the Proxy credentials plus // either the global or local credentials; local overrides global // Unfortunately, we cannot either clone or extract the contents // of the client supplied provider, so we are forced (for now) // to modify the client supplied provider. // Look in the local credentials first for for best scope match AuthScope bestMatch = HTTPAuthUtil . bestmatch ( scope , localcreds . keySet ( ) ) ; CredentialsProvider cp = null ; if ( bestMatch != null ) { cp = localcreds . get ( bestMatch ) ; } else { bestMatch = HTTPAuthUtil . bestmatch ( scope , globalcredfactories . keySet ( ) ) ; if ( bestMatch != null ) { HTTPProviderFactory factory = globalcredfactories . get ( bestMatch ) ; cp = factory . getProvider ( bestMatch ) ; } } // Build the proxy credentials and AuthScope Credentials proxycreds = null ; AuthScope proxyscope = null ; String user = ( String ) authcontrols . get ( AuthProp . PROXYUSER ) ; String pwd = ( String ) authcontrols . get ( AuthProp . PROXYPWD ) ; HttpHost httpproxy = ( HttpHost ) authcontrols . get ( AuthProp . HTTPPROXY ) ; HttpHost httpsproxy = ( HttpHost ) authcontrols . get ( AuthProp . HTTPSPROXY ) ; if ( user != null && ( httpproxy != null || httpsproxy != null ) ) { if ( httpproxy != null ) proxyscope = HTTPAuthUtil . hostToAuthScope ( httpproxy ) ; else //httpsproxy != null proxyscope = HTTPAuthUtil . hostToAuthScope ( httpsproxy ) ; proxycreds = new UsernamePasswordCredentials ( user , pwd ) ; } if ( cp == null && proxycreds != null && proxyscope != null ) { // If client provider is null and proxycreds are not, // then use proxycreds alone cp = new BasicCredentialsProvider ( ) ; cp . setCredentials ( proxyscope , proxycreds ) ; } else if ( cp != null && proxycreds != null && proxyscope != null ) { // If client provider is not null and proxycreds are not, // then add proxycreds to the client provider cp . setCredentials ( proxyscope , proxycreds ) ; } if ( cp != null ) this . sessioncontext . setCredentialsProvider ( cp ) ; }
Handle authentication and Proxy'ing

@param cb
@throws HTTPException
Handle authentication and Proxy ing