}
}
protected void refreshCredentials(int statusCode, HttpMethod method, IProgressMonitor monitor) throws RedmineApiErrorException {
if (Policy.isBackgroundMonitor(monitor)) {
throw new RedmineApiAuthenticationException(Messages.ERRMSG_MISSING_CREDENTIALS_SYNCHRONIZATION_FAILED);
}
try {
String message = Messages.AUTHENTICATION_REQUIRED;
switch (statusCode) {
case HttpStatus.SC_UNAUTHORIZED:
Header authHeader = method.getResponseHeader(HEADER_WWW_AUTHENTICATE);
if(authHeader!=null) {
for (HeaderElement headerElem : authHeader.getElements()) {
if (headerElem.getName().contains(HEADER_WWW_AUTHENTICATE_REALM)) {
if(headerElem.getValue().equals(REDMINE_REALM)) {
webHelper.refreshRepostitoryCredentials(message, monitor);
} else {
if (webHelper.useApiKey()) {
webHelper.refreshHttpAuthCredentials(message + ": " + headerElem.getValue(), monitor); //$NON-NLS-1$
} else {
throw new RedmineApiErrorException(Messages.ERRMSG_ADDITIONAL_HTTPAUTH_NOT_SUPPORTED);
}
}
break;
}
}
}
break;
case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
webHelper.refreshProxyCredentials(message, monitor);
break;
}
} catch (OperationCanceledException e) {
monitor.setCanceled(true);
throw new RedmineApiAuthenticationException(Messages.AUTHENTICATION_CANCELED);
}
}