Skip to main content

Can Java use IE's internet connection?

8 replies [Last post]
cknight19
Offline
Joined: 2005-04-04
Points: 0

Hi,

I'm wondering if its possible for Java apps to use IE's internet connection to access the internet as apposed to writing its own connection code.

The reason I ask is I've just finished writing an NTLM connection code ( used HttpClient) which was reasonably easy to do. However the app now requires my users to put in their proxy details, username, password, domain and proxy url and port. You'd be amazed how many users don't know this information or how to get it.....most of them have pre-built PC's and would need to phone the helpdesk for this (believe me they are a devolved breed).

I was thinking that if I could share IE's connection then I could remove that hassle. I've thought of one way I could do it using JDIC library and its Browser component, I can get HTML page content from the embedded browser but I'm not sure if it will allow me access a file download.......I'll try but in the mean-time if anyone knows of a better way to do this any info would be great.

I did google but no joy, so most likely its not possible and JDIC might be my only option......I'm not looking for any code, just guidance and perhaps a URL or two,

Thanks in advance.
Chris.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
skyewire
Offline
Joined: 2003-11-17
Points: 0

Hi,

Using system proxy settings should be supported in Java 5 and later. Check out the following article for details:

http://java.sun.com/j2se/1.5.0/docs/guide/net/proxies.html

Note the piece in section 4 that talks about ProxySelector, the default implementation, and the java.net.useSystemProxies system property.

However, if you are using HttpClient (the Apache thing?), it may do it's own thing when it comes to using proxies. Is there any reason you can't just use java.net.URLConnection to download stuff? People love to complain about its deficiencies, but I've never had any problems with it for simple downloads.

I'd be interested to know if this works for you. I haven't tried it out yet, but I'll need to support proxies for an upcoming project, and I had planned on just using a standard URLConnection, and possibly tweaking some ProxySelector stuff if users want to specify custom proxy settings.

Daniel

cknight19
Offline
Joined: 2005-04-04
Points: 0

Thanks for the post's. Checked out the ProxySelector stuff but its not quite got what I need.

> Using system proxy settings should be supported in
> Java 5 and later. Check out the following article for
> details:
>
> http://java.sun.com/j2se/1.5.0/docs/guide/net/proxies.
> html

[b]Sure system proxy settings are supported however NTLM proxies are not, you have to implement that yourself. Thats what HttpClient does really well (authenticating proxies ).....You can basically do NTLM in only two extra lines. Authenticating with my proxy is not the problem here.[/b]

> Is there any reason you can't just use
> java.net.URLConnection to download stuff? People love
> to complain about its deficiencies, but I've never
> had any problems with it for simple downloads.

[b]Sure its good for simple downloads. But if your behind a proxy and in particular an NTLM proxy then you need to use HttpClient or write an authenticator yourself. Its not that hard to write an authenticator if you understand your proxies byte output however its all be done and wrapped in HttpClient so I'd recommend every one uses that.[/b]

I don't want to have proxy information in my client application. I want my application to use Internet Explorers connection to access the internet. The reason is simple. The clients IE will already be setup to authenticate with the proxy.

In C/C++ it can be done simply by calling "URLDownloadToCacheFile()". This tells IE to download a URL to the users internet cache......it returns you a link to this information.

[b]I'm wondering if Java has the ability to do this from within the JDK API or wether I'd need to write a JNI DLL to use this C/C++ function?[/b]

skyewire
Offline
Joined: 2003-11-17
Points: 0

> Thanks for the post's. Checked out the ProxySelector
> stuff but its not quite got what I need.
>
> > Using system proxy settings should be supported in
> > Java 5 and later. Check out the following article
> for
> > details:
> >
> >
> http://java.sun.com/j2se/1.5.0/docs/guide/net/proxies.
>
> > html
>
> [b]Sure system proxy settings are supported however
> NTLM proxies are not, you have to implement that
> yourself. Thats what HttpClient does really well
> (authenticating proxies ).....You can basically do
> NTLM in only two extra lines. Authenticating with my
> proxy is not the problem here.[/b]

Why do you say that NTLM proxies are not supported? I have not tried it myself, but the following information seems to indicate that NTLM proxy authentication has been supported since Sun JRE 1.4.2, with improved (cross-platform) support in Java 6:

http://www.oaklandsoftware.com/papers/ntlm.html
http://www.oaklandsoftware.com/product_http/compare.html

> > Is there any reason you can't just use
> > java.net.URLConnection to download stuff? People
> love
> > to complain about its deficiencies, but I've never
> > had any problems with it for simple downloads.
>
> [b]Sure its good for simple downloads. But if your
> behind a proxy and in particular an NTLM proxy then
> you need to use HttpClient or write an authenticator
> yourself. Its not that hard to write an
> authenticator if you understand your proxies byte
> output however its all be done and wrapped in
> HttpClient so I'd recommend every one uses that.[/b]
>
> don't want to have proxy information in my client
> application. I want my application to use Internet
> Explorers connection to access the internet. The
> reason is simple. The clients IE will already be
> setup to authenticate with the proxy.

Since the Sun JRE supports NTLM proxy authentication, it should hopefully use it's NTLM proxy authenticator if you tell it to use the system proxy settings and those settings point to an NTLM proxy server. Have you tried using the "java.net.useSystemProxies" property (in Java 5 or 6) when your system proxy settings point to an NTLM proxy server? Again, I have not tried this myself, but my understanding is that it should "just work"... maybe a bit too optimistic!

Cheers,
Daniel

cknight19
Offline
Joined: 2005-04-04
Points: 0

Hi Daniel, thanks again,

I see the line you are taking about and it look's like you're right:-

"If your Java implementation is 1.4.2 or greater and you are running Java on Windows, use the built in JRE support and you are done. Use the java.net.Authenticator class optionally in conjunction with setting some networking properties "

It's very possible that it will work, although "java.net.Authenticator" is abstract so chances are you'll have to implement all the hard parts like building up the byte request for each round during the authentication request.

However we are deviating from the problem. I'm not interested in NTLM as I already have the code for this up and running. I'm wondering whether Java can use IE's internet connection, just like C++. This removes the need for any connection or password details being held in code and asked for from the user.

[b]Regardless whether you use ProxySelector or not you are still going to need to get and maintain these details :-

domain
username
password

You either get them from the user ( which I currently do ) or you hard code them. But if Java can use IE's connection then you don't need to get any of this information.[/b]
Anyone know if this is possible from within the JDK?

skyewire
Offline
Joined: 2003-11-17
Points: 0

> It's very possible that it will work, although
> "java.net.Authenticator" is abstract so chances are
> you'll have to implement all the hard parts like
> building up the byte request for each round during
> the authentication request.

Nope, actually Sun already implemented all the bits and bytes of NTLM, so there is no extra work required.

> However we are deviating from the problem. I'm not
> interested in NTLM as I already have the code for
> this up and running.

My point here is that you [b]do[/b] need to be concerned about your NTLM code, because you are using Apache's HttpClient NTLM, which (as far as I know) does [b]not[/b] support transparently getting the user credentials from Windows like IE does. If you really must use HttpClient, then you'll need some extra native libraries to do this for you:

http://www.mail-archive.com/httpclient-dev@jakarta.apache.org/msg01671.html

> I'm wondering whether Java can
> use IE's internet connection, just like C++. This
> removes the need for any connection or password
> details being held in code and asked for from the
> user.
>
> [b]Regardless whether you use ProxySelector or not
> you are still going to need to get and maintain these
> details :-
>
> domain
> username
> password
>
> You either get them from the user ( which I currently
> do ) or you hard code them. But if Java can use IE's
> connection then you don't need to get any of this
> information.[/b]

I think I understand exactly what you want. You are assuming that if you use Sun's NTLM proxy authentication, you will have to provide the domain, username, and password. This is not the case. A major benefit of using Sun's implementation is that it can [b]transparently[/b] authenticate the user using the credentials of the currently logged on Windows user. As I see it, the only time you'll ever need to provide domain, username, and password is if you want to use NTLM authentication from a non-Windows OS. Details on Sun's NTLM authentication:

http://java.sun.com/javase/6/docs/technotes/guides/net/http-auth.html

Of note: "On Microsoft Windows platforms, NTLM authentication attempts to acquire the user credentials from the system without prompting the user's authenticator object. If these credentials are not accepted by the server then the user's authenticator will be called."

cknight19
Offline
Joined: 2005-04-04
Points: 0

> My point here is that you [b]do[/b] need to be
> concerned about your NTLM code, because you are using
> Apache's HttpClient NTLM, which (as far as I know)
> does [b]not[/b] support transparently getting the
> user credentials from Windows like IE does. If you
> really must use HttpClient, then you'll need some
> extra native libraries to do this for you:

[b]The idea I had in mind was to completely bin HttpClient and NTLM altogether and leech IE's connection to download files.[/b]

However I had no idea that Sun supported transparent user credentials, thats exactly what I'm after and I'll start re-coding to use this implementation, only prompting, if the cache user credentials fail. Thank you for bearing with me.

The only problem I have now is the following quote from http://java.sun.com/javase/6/docs/technotes/guides/net/http-auth.html

[i]"In fact, if you are running on a Windows machine as a [b]domain user[/b], or, you are running on a Linux or Solaris machine that has already issued the kinit command and got the credential cache. The class MyAuthenticator will be completely ignored"[/i]

Unfortunetly for me not all my users will be on the domain. Still I can always fallback to a JNI DLL for non domain users.

Thanks again for all your help.

skyewire
Offline
Joined: 2003-11-17
Points: 0

> The only problem I have now is the following quote
> from
> http://java.sun.com/javase/6/docs/technotes/guides/net
> /http-auth.html
>
> [i]"In fact, if you are running on a Windows machine
> as a [b]domain user[/b], or, you are running on a
> Linux or Solaris machine that has already issued the
> kinit command and got the credential cache. The class
> MyAuthenticator will be completely ignored"[/i]
>
> Unfortunetly for me not all my users will be on the
> domain. Still I can always fallback to a JNI DLL for
> non domain users.

Sounds like an unfortunate restriction that it will not work for non-domain users - maybe give it a try and hopefully it will work anyway. It's always easier to have a pure Java solution and not mess with JNI.

If you do end up needing JNI, you may want to check out the cool NLink library, which lets you call Win32 APIs without having to write any native code. It'll hopefully be fairly quick and easy to call URLDownloadToCacheFile() using this:

https://nlink.dev.java.net/

Cheers,
Daniel

ghackmann
Offline
Joined: 2005-06-08
Points: 0

Take a look at the ProxySelector section of http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html. Of note:

"On recent Windows systems and on Gnome 2.x platforms it is possible to tell the default ProxySelector to use the system proxy settings (both recent versions of Windows and Gnome 2.x let you set proxies globally through their user interface). If the system property java.net.useSystemProxies is set to true (by default it is set to false for compatibility sake), then the default ProxySelector will try to use these settings."