* @param response the proxy response
*/
private void autoSelectAuthHandler(final HttpProxyResponse response) throws ProxyAuthException {
// Get the Proxy-Authenticate header
List<String> values = response.getHeaders().get("Proxy-Authenticate");
ProxyIoSession proxyIoSession = getProxyIoSession();
if (values == null || values.size() == 0) {
authHandler = HttpAuthenticationMethods.NO_AUTH.getNewHandler(proxyIoSession);
} else if (getProxyIoSession().getPreferedOrder() == null) {
// No preference order set for auth mechanisms
int method = -1;
// Test which auth mechanism to use. First found is the first used
// that's why we test in a decreasing security quality order.
for (String proxyAuthHeader : values) {
proxyAuthHeader = proxyAuthHeader.toLowerCase();
if (proxyAuthHeader.contains("ntlm")) {
method = HttpAuthenticationMethods.NTLM.getId();
break;
} else if (proxyAuthHeader.contains("digest") && method != HttpAuthenticationMethods.NTLM.getId()) {
method = HttpAuthenticationMethods.DIGEST.getId();
} else if (proxyAuthHeader.contains("basic") && method == -1) {
method = HttpAuthenticationMethods.BASIC.getId();
}
}
if (method != -1) {
try {
authHandler = HttpAuthenticationMethods.getNewHandler(method, proxyIoSession);
} catch (Exception ex) {
logger.debug("Following exception occured:", ex);
}
}
if (authHandler == null) {
authHandler = HttpAuthenticationMethods.NO_AUTH.getNewHandler(proxyIoSession);
}
} else {
for (HttpAuthenticationMethods method : proxyIoSession.getPreferedOrder()) {
if (authHandler != null) {
break;
}
if (method == HttpAuthenticationMethods.NO_AUTH) {