* @param authManager
* the <code>AuthManager</code> containing all the authorisations for
* this <code>UrlConfig</code>
*/
private void setConnectionAuthorization(HttpClient client, URL u, AuthManager authManager) {
HttpParams params = client.getParams();
if (authManager != null) {
Authorization auth = authManager.getAuthForURL(u);
if (auth != null) {
String username = auth.getUser();
String realm = auth.getRealm();
String domain = auth.getDomain();
if (log.isDebugEnabled()){
log.debug(username + " > D="+ username + " D="+domain+" R="+realm);
}
client.getState().setCredentials(
new AuthScope(u.getHost(),u.getPort(),
realm.length()==0 ? null : realm //"" is not the same as no realm
,AuthScope.ANY_SCHEME),
// NT Includes other types of Credentials
new NTCredentials(
username,
auth.getPass(),
localHost,
domain
));
// We have credentials - should we set pre-emptive authentication?
if (canSetPreEmptive){
log.debug("Setting Pre-emptive authentication");
params.setBooleanParameter(HTTP_AUTHENTICATION_PREEMPTIVE, true);
}
}
else
{
client.getState().clearCredentials();
if (canSetPreEmptive){
params.setBooleanParameter(HTTP_AUTHENTICATION_PREEMPTIVE, false);
}
}
}
else
{