Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311640 - 401 authorization required error when importing smart HTTP repository
Summary: 401 authorization required error when importing smart HTTP repository
Status: RESOLVED FIXED
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major with 1 vote (vote)
Target Milestone: 0.10.0-M3   Edit
Assignee: Matthias Sohn CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
: 329532 (view as bug list)
Depends on: 296201
Blocks: 329893
  Show dependency tree
 
Reported: 2010-05-04 18:29 EDT by Bob Feldbauer CLA
Modified: 2012-01-19 12:05 EST (History)
6 users (show)

See Also:


Attachments
Password collection dialog in EclipseAuthenticator (7.56 KB, application/octet-stream)
2010-05-31 06:31 EDT, Ian Carr CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Feldbauer CLA 2010-05-04 18:29:30 EDT
Build Identifier: M20100211-1343

We cannot import a smart HTTP (Apache2+git-http-backend) repository using EGit.  Various colleagues and I are seeing this error in Eclipse 3.4.2 and 3.5.2 with both EGit 0.7.1 and current bleeding edge nightly builds as of May 4, 2010.  Using the same repository from other servers, with the native Linux command-line git client, works as expected.

Reproducible: Always

Steps to Reproduce:
1. File->Import, select Git Repository.
2. Setup a smart HTTP repository, using http://git.hostname.com/repos/project.git and a valid username and password
3. Get a "Transport Error: Cannot list the available branches. Reason: http://username@git.hostname.com/repos/project.git: 401 Authorization Required"
Comment 1 Bob Feldbauer CLA 2010-05-04 19:13:03 EDT
Also, I tested using msysgit's git implementation on Windows, and it also works properly.
Comment 2 Ian Carr CLA 2010-05-31 06:31:38 EDT
Created attachment 170508 [details]
Password collection dialog in EclipseAuthenticator
Comment 3 Ian Carr CLA 2010-05-31 06:32:47 EDT
I am also seeing this problem when accessing a similar environment. It would appear that the current code does not supply identity information when prompted by the server.

Looking at the code it would appear that an org.eclipse.egit.ui.EclipseAuthenticator is created and set as the default authenticator for HTTP communications, but this currently only responds in the case of proxy server configuration.

In the attached patch I have augmented this Authenticator to throw up a username/password prompt and to respond with these credentials in the case that the current proxy check yields no result.

With this patch in place I am able to use the remote functionality without the authentication failure.

Not being 100% familiar with the existing code, I am not sure whether the EclipseAuthenticator should be wrapped in an if thus:

if (getRequestorType() == Authenticator.RequestorType.PROXY) {
   ...
   current code
   ...
} else {
   ...
   server code prompt user
   ...
}

Note: I am not able to test the original proxy functionality!

Note: With the current UI, I can't see a simple way to capture or store the auth information for the remote repository. Presumably there needs to be an additional configuration to capture remote URL's and auth information?

Hope this helps

Ian
Comment 4 Stefan Lay CLA 2010-08-09 06:51:47 EDT
This is a missing feature in JGit. 

We should at least disable the credential input fields in eGit until JGit bug 296201 is fixed.
Comment 5 Stefan Lay CLA 2010-08-09 06:55:53 EDT
There is already an open bug. The feature is simply not implemented yet. As a first solution we should disable the credential input fields in EGit.

*** This bug has been marked as a duplicate of bug 296201 ***
Comment 6 Stefan Lay CLA 2010-08-09 07:02:31 EDT
I closed the bug by mistake. I wanted to track the EGit part of the bug here.
Comment 7 Stefan Lay CLA 2010-08-09 07:04:54 EDT
http(s) is a missing feature in JGit. 

It is however a bug that EGit allows the user to provide credentials and only later on reports an error.
Comment 8 Matthias Sohn CLA 2010-10-21 07:09:40 EDT
we will work on this in M2
Comment 9 Jens Baumgart CLA 2010-11-26 10:49:34 EST
I proposed basic authentification for EGit:

http://egit.eclipse.org/r/1961
Comment 10 Matthias Sohn CLA 2010-11-30 16:59:26 EST
merged as cfb8c6e0d57e09fa6013c2c27bb679df12455bc8
Comment 11 Matthias Sohn CLA 2010-11-30 17:13:19 EST
*** Bug 329532 has been marked as a duplicate of this bug. ***
Comment 12 Matthias Sohn CLA 2010-12-01 16:45:43 EST
this was finished in 0.10.0-M3 and HTTP authentication support should be
covered in 0.10 noteworthy
Comment 13 Jörn Gersdorf CLA 2012-01-19 03:39:59 EST
Sorry, this bug is not resolved. Still happens to me in 1.2.0.20112221803-r.

See also bug 338048, bug 339220 and bug 342592.
Comment 14 Jörn Gersdorf CLA 2012-01-19 04:57:06 EST
(In reply to comment #13)
> Sorry, this bug is not resolved. Still happens to me in 1.2.0.20112221803-r.
> 
> See also bug 338048, bug 339220 and bug 342592.

It's neither working via HTTP nor via HTTPS.
Comment 15 Lars Vogel CLA 2012-01-19 05:14:30 EST
@Jörn: Are you behind a proxy? If yes, maintain the proxy in Eclipse and restart Eclipse.
Comment 16 Jörn Gersdorf CLA 2012-01-19 11:35:10 EST
(In reply to comment #15)
> @Jörn: Are you behind a proxy? If yes, maintain the proxy in Eclipse and
> restart Eclipse.

@Lars:
No, i'm not behind a proxy.

I resolved my problem. Reason is that eGIT performs Http Basic authentication on the first GET only which is not so nice. I had apache configured to request authentication only on "^/git/.*/(git-receive-pack|git-upload-pack)" but not on "^/git/.*/info/refs.*$".

In that situation the first GET (performed in TransportHttp.connect(...)) succeeds without Authorization request (401) by the server, however, the next POST to git/<repo>/git-upload-pack is answered by the server by a 401 which leads to an exception in eGit (even though it is a perfectly valid answer by the server).

There are also two other things which I think could be better from a user perspective:
- If the server (or client) closes the tcp connection - for whatever reason - the server will request a new Authorization for the next HTTP request. Should be handled as well because that bit me several times.
- The loop in TransportHttp.connect(...) should be configurable. It hit me that I
  entered the wrong password which is authenticated against the active directory
  on the server - and due to the loop my windows user was locked several times.
  It would be nice if we could configure the max number of trials.
- In eGit, if I don't want to store the password in the secure store eGit
  is asking me always for user/password. It would be really nice if eGit would
  remember the user/password in that case for the eclipse session.

Anyway, thank you for your great work!
Comment 17 Jörn Gersdorf CLA 2012-01-19 11:53:49 EST
Okay, but now I've got a new problem: GIT PUSH is not working in eGIT. In that case the client/server communication is as follows:

>eGit> GET /git/git_server.git/info/refs?service=git-receive-pack

<Git-Server< 401 Unauthorized, Authentication: Basic

and at that point eGit quits with the message "Repository http://server:444/git/git_server.git failed to write".

Stack Trace:

!ENTRY org.eclipse.egit.core 4 0 2012-01-19 17:49:19.006
!MESSAGE An exception occurred during push on URI https://mucsd47r.server.westlb.net:444/git/git_server.git: An internal Exception occurred during push: https://mucsd47r.server.westlb.net:444/git/git_server.git: cannot open git-receive-pack
!STACK 0
org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of push command
	at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:156)
	at org.eclipse.egit.core.op.PushOperation.run(PushOperation.java:227)
	at org.eclipse.egit.ui.internal.push.PushOperationUI.execute(PushOperationUI.java:145)
	at org.eclipse.egit.ui.internal.push.PushOperationUI$1.run(PushOperationUI.java:202)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.eclipse.jgit.errors.TransportException: https://mucsd47r.server.westlb.net:444/git/git_server.git: cannot open git-receive-pack
	at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:466)
	at org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:365)
	at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:130)
	at org.eclipse.jgit.transport.Transport.push(Transport.java:1120)
	at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:152)
	... 4 more
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
	at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
	at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
	at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
	at org.eclipse.jgit.util.HttpSupport.response(HttpSupport.java:167)
	at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:429)
	... 8 more
Comment 18 Jörn Gersdorf CLA 2012-01-19 12:05:23 EST
(In reply to comment #17)
> Okay, but now I've got a new problem: GIT PUSH is not working in eGIT. In that
> case the client/server communication is as follows:
> 
> >eGit> GET /git/git_server.git/info/refs?service=git-receive-pack
> 
> <Git-Server< 401 Unauthorized, Authentication: Basic
> 
> and at that point eGit quits with the message "Repository
> http://server:444/git/git_server.git failed to write".
> 
> Stack Trace:
> 
> !ENTRY org.eclipse.egit.core 4 0 2012-01-19 17:49:19.006
> !MESSAGE An exception occurred during push on URI
> https://mucsd47r.server.westlb.net:444/git/git_server.git: An internal
> Exception occurred during push:
> https://mucsd47r.server.westlb.net:444/git/git_server.git: cannot open
> git-receive-pack
> !STACK 0
> org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during
> execution of push command
>     at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:156)
>     at org.eclipse.egit.core.op.PushOperation.run(PushOperation.java:227)
>     at
> org.eclipse.egit.ui.internal.push.PushOperationUI.execute(PushOperationUI.java:145)
>     at
> org.eclipse.egit.ui.internal.push.PushOperationUI$1.run(PushOperationUI.java:202)
>     at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
> Caused by: org.eclipse.jgit.errors.TransportException:
> https://mucsd47r.server.westlb.net:444/git/git_server.git: cannot open
> git-receive-pack
>     at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:466)
>     at
> org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:365)
>     at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:130)
>     at org.eclipse.jgit.transport.Transport.push(Transport.java:1120)
>     at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:152)
>     ... 4 more
> Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext
> connection?
>     at
> com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
>     at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
>     at
> com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
>     at
> sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
>     at
> sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
>     at
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
>     at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
>     at
> sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
>     at org.eclipse.jgit.util.HttpSupport.response(HttpSupport.java:167)
>     at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:429)
>     ... 8 more

Sorry, forget about that one, this is a non-issue!