public CredentialsProvider setProxyAuthentication ( ProxyConfig proxyConfig ) { if ( proxyConfig == null ) { return null ; } String username = proxyConfig . getUsername ( ) ; String password = proxyConfig . getPassword ( ) ; if ( ! username . isEmpty ( ) && ! password . isEmpty ( ) ) { String host = proxyConfig . getHost ( ) ; String port = proxyConfig . getPort ( ) ; if ( ! host . isEmpty ( ) && ! port . isEmpty ( ) ) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider ( ) ; String domain = proxyConfig . getDomain ( ) ; if ( ! domain . isEmpty ( ) ) { credentialsProvider . setCredentials ( new AuthScope ( host , Integer . parseInt ( port ) ) , new NTCredentials ( username , password , host , domain ) ) ; } else { credentialsProvider . setCredentials ( new AuthScope ( host , Integer . parseInt ( port ) ) , new UsernamePasswordCredentials ( username , password ) ) ; } return credentialsProvider ; } } return null ; }
Method to set proxy authentication