Credentials creds = new UsernamePasswordCredentials( username, password );
String host = getRepository().getHost();
int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT;
client.getCredentialsProvider().setCredentials( new AuthScope( host, port ), creds );
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 );
}
ProxyInfo proxyInfo = getProxyInfo( getRepository().getProtocol(), getRepository().getHost() );
if ( proxyInfo != null )
{
String proxyUsername = proxyInfo.getUserName();
String proxyPassword = proxyInfo.getPassword();
String proxyHost = proxyInfo.getHost();
int proxyPort = proxyInfo.getPort();
String proxyNtlmHost = proxyInfo.getNtlmHost();
String proxyNtlmDomain = proxyInfo.getNtlmDomain();
if ( proxyHost != null )
{
HttpHost proxy = new HttpHost( proxyHost, proxyPort );
if ( proxyUsername != null && proxyPassword != null )
{
Credentials creds;
if ( proxyNtlmHost != null || proxyNtlmDomain != null )
{
creds = new NTCredentials( proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain );
}
else
{
creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
}
int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT;
AuthScope authScope = new AuthScope( proxyHost, port );
client.getCredentialsProvider().setCredentials( authScope, creds );
}
client.getParams().setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy );
}