[jcifs] Java applet and NTLM proxy authentication

André Warnier aw at ice-sa.com
Fri Feb 27 17:44:09 GMT 2009


I posted this before on the Tomcat list without too much success.
I hope this is a better place.

As a preamble, I am by now fairly versed in Tomcat Java server-side NTLM 
authentication (à la jCIFS/Jespa), but this is another animal : it's on 
the browser side.

In our application, we have a html form allowing users to upload several 
files together, as a "collection", to a webserver.  The html form itself 
contains some descriptive text input fields; the multiple file-upload is 
provided by a Java applet embedded in the page, which allows users to 
select local workstation files which should be uploaded to the server as 
a set, together with the static form input fields values.  It is this 
applet (not the html form) which actually does the HTTP POST-ing to the 
server of the files, one file/one POST at a time, each POST containing 
one file plus a copy of the html input field values.

To make the POST, the applet picks up from the browser the proxy 
settings if any, and uses them when it creates its own HTTP connection 
to the server, via the org.apache.commons.httpclient.* packages 
(HttpClient, method.* etc..).

It all works fine using IE and Firefox, whether the browser/customer is 
behind a corporate proxy or not.
Only in one recent case, it does not.

In that particular case, the browser is IE, and the users are behind a 
corporate outgoing proxy server which requires NTLM authentication on 
the part of the client.
The browser is of course NTLM-authenticated with this proxy, since 
otherwise it could never go through the proxy and fetch our html form in 
the first place.
However, when the applet later tries to do a POST to the same server 
whence the form came from, it receives a 401 response back from the 
proxy.  This 401 response tells the client (in this case the applet), 
that it must authenticate via the NTLM method.

Unfortunately, the Java applet and its HttpClient do not seem to 
magically pick up the containing browser's credentials and to 
automatically add them to the POST request they are doing to the same 
webserver, which I would have considered nifty. Sigh.

So now the question is : what do I have to do to my applet, that it 
would authenticate properly to that proxy, using the NTLM credentials of 
the browser it is living inside of, or using the credentials of the 
workstation in which the containing browser lives ?
Secondary question : is this even possible ?

If anyone is sufficiently interested, there is a web demo site where 
this can all be seen, and if you happen to be behind one such proxy 
requiring NTLM authentication, you can also see (in the browser's Java 
console) in detail what happens.

Thankful in advance for any hints about where to start looking,


As complementary information to my own questions above, I have already 
read the document located here :

However, that does not seem to fit the bill, in the sense that the 
method outlined there (using the jCIFS library) requires finally a call 
like this :

         new AuthScope("myserver", -1),
         new NTCredentials("username", "password", "MYSERVER", "MYDOMAIN"));

which implies seemingly that I would have to present an authentication 
dialog to the user and ask them to enter their user-id and password, 
then submit these to the NTCredentials constructor.

This is marketing-wise impossible, since the user (via his IE browser) 
is already authenticated in his own Windows/NTLM domain (and to the 
proxy), and furthermore he is so transparently.  It would thus be 
impossible for me to "sell" the idea that they need to re-enter their 
credentials just to use this facet of the application.
(I am also not quite sure how I would get the "DOMAIN" information from 
within my applet.)
(It is also quite impossible to sell to the security people, that I 
would, in my applet, be able to get hold of the user's password for 
their domain account).

What I would like is some method by which the Java applet can pick up 
this information from the browser it is running inside of, since that 
browser /is/ already authenticated.
(For example, the XMLHttpRequest javascript object does that).

If that is impossible, I am afraid that instead of using the Java applet 
to do both the local file selection and the POST submission to the 
server, I'll have to merely do the file selection, pass the list back to 
some javascript function back in the html page, and do the POST 
submission via an XMLHttpRequest at that level (supposing of course that 
this object, at least under IE, allows for NTLM authentication; but I 
think it does, or should).

Also maybe to dampen some ideas, I don't think I can sell to my customer 
a 3-digit $ license for each of their workstations..

More information about the jcifs mailing list