import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
*
* @param conn
* the connection that failed.
+ * @param ignoreTypes
+ * authentication types to be ignored.
* @return new authentication method to try.
*/
- static HttpAuthMethod scanResponse(final HttpConnection conn) {
+ static HttpAuthMethod scanResponse(final HttpConnection conn,
+ Collection<Type> ignoreTypes) {
final Map<String, List<String>> headers = conn.getHeaderFields();
HttpAuthMethod authentication = Type.NONE.method(EMPTY_STRING);
try {
Type methodType = Type.valueOf(valuePart[0].toUpperCase());
+
+ if ((ignoreTypes != null)
+ && (ignoreTypes.contains(methodType))) {
+ continue;
+ }
+
if (authentication.getType().compareTo(methodType) >= 0) {
continue;
}
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.SymbolicRef;
+import org.eclipse.jgit.transport.HttpAuthMethod.Type;
import org.eclipse.jgit.transport.http.HttpConnection;
import org.eclipse.jgit.util.HttpSupport;
import org.eclipse.jgit.util.IO;
throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e);
}
- try {
- int authAttempts = 1;
- for (;;) {
+
+ int authAttempts = 1;
+ Collection<Type> ignoreTypes = null;
+ for (;;) {
+ try {
final HttpConnection conn = httpOpen(u);
if (useSmartHttp) {
String exp = "application/x-" + service + "-advertisement"; //$NON-NLS-1$ //$NON-NLS-2$
// explicit authentication would be required
if (authMethod.getType() == HttpAuthMethod.Type.NONE
&& conn.getHeaderField(HDR_WWW_AUTHENTICATE) != null)
- authMethod = HttpAuthMethod.scanResponse(conn);
+ authMethod = HttpAuthMethod.scanResponse(conn, ignoreTypes);
return conn;
case HttpConnection.HTTP_NOT_FOUND:
MessageFormat.format(JGitText.get().uriNotFound, u));
case HttpConnection.HTTP_UNAUTHORIZED:
- authMethod = HttpAuthMethod.scanResponse(conn);
+ authMethod = HttpAuthMethod.scanResponse(conn, ignoreTypes);
if (authMethod.getType() == HttpAuthMethod.Type.NONE)
throw new TransportException(uri, MessageFormat.format(
JGitText.get().authenticationNotSupported, uri));
String err = status + " " + conn.getResponseMessage(); //$NON-NLS-1$
throw new TransportException(uri, err);
}
+ } catch (NotSupportedException e) {
+ throw e;
+ } catch (TransportException e) {
+ throw e;
+ } catch (IOException e) {
+ if (authMethod.getType() != HttpAuthMethod.Type.NONE) {
+ if (ignoreTypes == null) {
+ ignoreTypes = new HashSet<Type>();
+ }
+
+ ignoreTypes.add(authMethod.getType());
+
+ // reset auth method & attempts for next authentication type
+ authMethod = HttpAuthMethod.Type.NONE.method(null);
+ authAttempts = 1;
+
+ continue;
+ }
+
+ throw new TransportException(uri, MessageFormat.format(JGitText.get().cannotOpenService, service), e);
}
- } catch (NotSupportedException e) {
- throw e;
- } catch (TransportException e) {
- throw e;
- } catch (IOException e) {
- throw new TransportException(uri, MessageFormat.format(JGitText.get().cannotOpenService, service), e);
}
}