protected static HttpClientBuilder addAuthentication ( final HttpClientBuilder builder , final URI uri , final String username , String password ) { if ( isNotBlank ( username ) ) { CredentialsProvider provider = new BasicCredentialsProvider ( ) ; AuthScope scope = new AuthScope ( uri . getHost ( ) , uri . getPort ( ) , "realm" ) ; UsernamePasswordCredentials credentials = new UsernamePasswordCredentials ( username , password ) ; provider . setCredentials ( scope , credentials ) ; builder . setDefaultCredentialsProvider ( provider ) ; builder . addInterceptorFirst ( new PreemptiveAuth ( ) ) ; } return builder ; }
Add authentication to supplied builder .