Bug 368882 - No more authentication window when using URLConnection in Eclipse Plugin
Summary: No more authentication window when using URLConnection in Eclipse Plugin
Status: REOPENED
Alias: None
Product: EGit
Classification: Technology
Component: UI (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 377347 432008 (view as bug list)
Depends on:
Blocks: 501000
  Show dependency tree
 
Reported: 2012-01-17 16:06 EST by Ralph Soika CLA
Modified: 2016-10-09 02:50 EDT (History)
14 users (show)

See Also:


Attachments
Default Eclipse Password Prompt (23.67 KB, image/png)
2014-06-11 14:33 EDT, Daniel Johnson CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph Soika CLA 2012-01-17 16:06:36 EST
Build Identifier: Version: Indigo Release Build id: 20110615-0604

I have a strange behavior in Eclipse with differnt plugins like BIRT. 
When a plugin is using a URLConnection to a server with a secured URL, in the past Eclipse automatically shows up a login dialog to perform Basic Authentication with the server.
This seems to be a feature from Eclipse platform implemented through the extension point org.eclipse.equinox.security.loginModule. 
I know about this behavior, because I have implemented my own plugin with a custom login dialog. And if the user give me wrong user/password then the eclipse login dialog pops up automatically. 
So from the view of a plugin it is sufficient to provide a code like this:

Code: 
....
urlConnection = (HttpURLConnection) new URL(myURL)
					.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setAllowUserInteraction(false);
urlConnection.connect();
.....


No special handling was necessary. If the URL returns an 401, then the eclipse login dialog appears automatically.
You can test this behavior also in the BIRT Plugin when creating a DataSet based on a XML URL. BIRT has no implementation for username/password for XML URLs.

But for some strange reasons this dialog did not longer appear in some clients after the EGit Plugin was installed. 

After I have reverted a Eclipse IDE into a setup without the Egit Plugin the internal login dialog appears again.

Can anybody check if EGit makes use of the extension point "org.eclipse.equinox.security.loginModule"?


Tested with     Eclipse EGit	1.1.0.201109151100-r

Reproducible: Always

Steps to Reproduce:
1.start Eclipse without EGit Plugin
2.create BIRT Report with a XML DataSet based on a URL from a secured server resource 
3.Log into the server by giving userid/password into the standard login dialog
4.Install EGit Plugin
5.create BIRT Report with a XML DataSet based on a URL from a secured server resource - No Login dialog will apear.

ok - mybe this is a little bit cumbersome.
So you can test it with a debug code where you setup an URL Connection to a secured resource:

urlConnection = (HttpURLConnection) new URL("http://....some_url_with_basic_authentication...")
					.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setAllowUserInteraction(false);
urlConnection.connect();
Comment 1 Matthias Sohn CLA 2012-01-19 15:17:06 EST
> Can anybody check if EGit makes use of the extension point
> "org.eclipse.equinox.security.loginModule"?

I couldn't find "org.eclipse.equinox.security.loginModule" in EGit or JGit sources.
Also plugin search didn't find any references to this extension point in the workspace 
I use for JGit and EGit development.
Comment 2 Ralph Soika CLA 2012-02-08 06:14:30 EST
Is there anyone how can confirm this behavior?
Comment 3 Denis Yuen CLA 2012-04-20 09:25:18 EDT
I can confirm this bug on BIRT using Indigo Service Release 2 Build is: 20120216-1857

I had the same issue when using a XML data source, deleted the egit plugin to test, and the authentication dialog then was able to show up.
Comment 4 Daniel Johnson CLA 2013-12-10 17:20:58 EST
I also can confirm this issue, I was using Eclipse 3.8, not sure what version of egit, but I believe it was the latest (3.1).
Comment 5 Matthias Sohn CLA 2013-12-11 08:05:44 EST
(In reply to Daniel Johnson from comment #4)
> I also can confirm this issue, I was using Eclipse 3.8, not sure what
> version of egit, but I believe it was the latest (3.1).

can you provide steps to reproduce ?
Comment 6 Ralph Soika CLA 2013-12-11 09:26:51 EST
The problem is that BIRT did not provide any way to enter a user name and password for a XML Data URL.

There is no need to reproduce this - You can see it if you try to add a XML Data URL.
Comment 7 Matthias Sohn CLA 2013-12-11 10:30:44 EST
(In reply to Ralph Soika from comment #6)
> The problem is that BIRT did not provide any way to enter a user name and
> password for a XML Data URL.
> 
> There is no need to reproduce this - You can see it if you try to add a XML
> Data URL.

but I have no clue how to do that and what I need to install first
Comment 8 Daniel Johnson CLA 2013-12-11 12:36:45 EST
In my case I have a plugin for Eclipse that calls for a config file stored in secure SVN (https url). Without eGit installed when I execute the code to get the input stream from the URL it automatically prompts for user authentication. With eGit installed it throws a '401 Unauthorized Access' IOException and never asks for authentication.

This API works with many types of URLs (http://, https://, file://, etc.). Note in the case of https that I am setting a blank Certifificate manager and accepting connections to all hosts.

Matthias, you should be able to use this code on any URL requiring authentication to reproduce the issue. 

public static InputStream getRemoteInputStream(URL url) throws Exception {

  URLConnection conn = url.openConnection();
  if (conn instanceof HttpsURLConnection) {

    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
        return null;
      }

      public void checkClientTrusted(X509Certificate[] certs, String authType) {
      }

      public void checkServerTrusted(X509Certificate[] certs, String authType) {
      }
    } };

    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new java.security.SecureRandom());
    HostnameVerifier allHostsValid = new HostnameVerifier() {
      public boolean verify(String hostname, SSLSession session) {
        return true;
      }
    };
    ((HttpsURLConnection) conn).setHostnameVerifier(allHostsValid);
    ((HttpsURLConnection) conn).setSSLSocketFactory(sc.getSocketFactory());
  }
  conn.setAllowUserInteraction(true);
  conn.connect();
  return conn.getInputStream();
}
Comment 9 Daniel Johnson CLA 2014-06-11 14:33:03 EDT
Created attachment 244166 [details]
Default Eclipse Password Prompt
Comment 10 Daniel Johnson CLA 2014-06-11 14:34:07 EDT
I checked out the source and found that eGit is overriding the default Eclipse Authenticator implementation with a new Authenticator. At startup  org.eclipse.egit.ui.Activator.setupProxy(final BundleContext context); calls java.net.Authenticator.setDefault(new EclipseAuthenticator()) . The java.net.Authenticator only allows one default, and Eclipse already had set a default in org.eclipse.core.internal.net.ProxyManager.registerAuthenticator() of type org.eclipse.ui.internal.net.auth.NetAuthenticator. So when eGit loads it is overriding this default, no longer allowing applications to make use of the default authentication service.

Without egit installed any application code that tries to connect to a secure address will receive a dialog prompt from NetAuthenticator (attached password_prompt.png), however the egit EclipseAuthenticator implementation simply returns null authentication for any request, unless a proxy is configured in Eclipse, than it will return that authentication information instead.

Can someone explain why egit needs a new default Authenticator.
Comment 11 Daniel Johnson CLA 2014-06-11 16:37:30 EDT
*** Bug 377347 has been marked as a duplicate of this bug. ***
Comment 12 Ralph Soika CLA 2014-06-12 02:52:14 EDT
In my expirance this bug did not longer exits since 'Juno' version.
Comment 13 Matthias Sohn CLA 2014-06-12 06:33:40 EDT
(In reply to Daniel Johnson from comment #10)
> I checked out the source and found that eGit is overriding the default
> Eclipse Authenticator implementation with a new Authenticator. At startup 
> org.eclipse.egit.ui.Activator.setupProxy(final BundleContext context); calls
> java.net.Authenticator.setDefault(new EclipseAuthenticator()) . The
> java.net.Authenticator only allows one default, and Eclipse already had set
> a default in
> org.eclipse.core.internal.net.ProxyManager.registerAuthenticator() of type
> org.eclipse.ui.internal.net.auth.NetAuthenticator. So when eGit loads it is
> overriding this default, no longer allowing applications to make use of the
> default authentication service.
> 
> Without egit installed any application code that tries to connect to a
> secure address will receive a dialog prompt from NetAuthenticator (attached
> password_prompt.png), however the egit EclipseAuthenticator implementation
> simply returns null authentication for any request, unless a proxy is
> configured in Eclipse, than it will return that authentication information
> instead.
> 
> Can someone explain why egit needs a new default Authenticator.

thanks for the detailed analysis, I think we can simply remove this code
I pushed a fix for review
https://git.eclipse.org/r/#/c/28411/
Comment 14 Daniel Johnson CLA 2014-06-18 16:59:33 EDT
Thanks Matthias. Any chance this will make it in time for Luna release? I don't think there is anything I can do to help it progress, but let me know if there is.
Comment 15 Matthias Sohn CLA 2014-06-19 20:11:47 EDT
no chance for Luna since the final build was done last week on Wednesday and this bug for sure doesn't qualify as a showstopper for the release train
Comment 16 Carsten Reckord CLA 2014-11-25 17:09:21 EST
*** Bug 432008 has been marked as a duplicate of this bug. ***
Comment 17 Mykola Nikishov CLA 2015-06-30 15:55:15 EDT
[Batch change] Remove pre-3.7 Target Milestones

If anyone on CC list is going to fix/implement this, please assign a new 3.7+ target milestone.
Comment 18 Szymon Ptaszkiewicz CLA 2015-08-21 11:35:52 EDT
(In reply to Matthias Sohn from comment #13)
> thanks for the detailed analysis, I think we can simply remove this code
> I pushed a fix for review
> https://git.eclipse.org/r/#/c/28411/

Matthias, is there any chance this can be merged? It would be great if we could have this bug fixed for Mars.1 (a.k.a. Mars SR1).
Comment 19 Andrey Loskutov CLA 2015-08-23 17:48:58 EDT
(In reply to Daniel Johnson from comment #10)
> So when eGit loads it is
> overriding this default, no longer allowing applications to make use of the
> default authentication service.

That is bad. However, applications can always override default authentication service (like egit). Not that it is nice thing, but at least there is a workaround.

> Without egit installed any application code that tries to connect to a
> secure address will receive a dialog prompt from NetAuthenticator (attached
> password_prompt.png), however the egit EclipseAuthenticator implementation
> simply returns null authentication for any request, unless a proxy is
> configured in Eclipse, than it will return that authentication information
> instead.
> 
> Can someone explain why egit needs a new default Authenticator.

Looking on the code of NetAuthenticator vs EclipseAuthenticator the reason was to *reuse* proxy authentication settings from Eclipse (all big companies are sitting behind proxies), however this makes users who are NOT behind proxy with zero chances to get authentication :-(

@Shawn: since the code was initially contributed by you: do you have any idea why the code was originally added?

I think better solution would be not simply remove that EclipseAuthenticator thing but enhance it: get (via reflection) the previous Authenticator (if any) and redirect the getPasswordAuthentication() calls to it if there is no proxy for given host configured in Eclipse. Additionally the original NetAuthenticator implementation should be improved by the code from EclipseAuthenticator, so that egit could later completely remove that piece of code.
Comment 20 Eclipse Genie CLA 2015-08-24 03:38:02 EDT
New Gerrit change created: https://git.eclipse.org/r/54374
Comment 21 Matthias Sohn CLA 2015-08-24 03:40:26 EDT
pushed a new change for stable-4.0 following Andrey's suggestion which delegates to NetAuthenticator if proxy has no configuration
Comment 22 Andrey Loskutov CLA 2015-08-24 04:10:59 EDT
(In reply to Matthias Sohn from comment #21)
> pushed a new change for stable-4.0 following Andrey's suggestion which
> delegates to NetAuthenticator if proxy has no configuration

Matthias, will you create a follow up task for NetAuthenticator?
Comment 23 Matthias Sohn CLA 2015-08-24 04:42:38 EDT
(In reply to Andrey Loskutov from comment #22)
> (In reply to Matthias Sohn from comment #21)
> > pushed a new change for stable-4.0 following Andrey's suggestion which
> > delegates to NetAuthenticator if proxy has no configuration
> 
> Matthias, will you create a follow up task for NetAuthenticator?

do you know which is the platform component and git repository owning the source for NetAuthenticator ? Then I could contribute the enhancement right away.
Comment 24 Andrey Loskutov CLA 2015-08-24 04:49:37 EDT
(In reply to Matthias Sohn from comment #23)
> (In reply to Andrey Loskutov from comment #22)
> > (In reply to Matthias Sohn from comment #21)
> > > pushed a new change for stable-4.0 following Andrey's suggestion which
> > > delegates to NetAuthenticator if proxy has no configuration
> > 
> > Matthias, will you create a follow up task for NetAuthenticator?
> 
> do you know which is the platform component and git repository owning the
> source for NetAuthenticator ? Then I could contribute the enhancement right
> away.

https://git.eclipse.org/c/platform/eclipse.platform.team.git/

See also bug 196780, bug 312228 and bug 318173.